## Description
<!-- **Please link some issue here describing what you are trying to achieve.**
In case there is no issue present for your PR, please consider creating one.
At least please give us some description what you are trying to achieve and why your change is needed. -->
relates to #1234
## Checklist
- [ ] Issue was linked above
- [ ] Code format was applied: `make fmt`
- [ ] Examples were added / adjusted (see `examples/` directory)
- [x] Docs are up-to-date: `make generate-docs` (will be checked by CI)
- [ ] Unit tests got implemented or updated
- [ ] Acceptance tests got implemented or updated (see e.g. [here](f5f99d1709/stackit/internal/services/dns/dns_acc_test.go))
- [x] Unit tests are passing: `make test` (will be checked by CI)
- [x] No linter issues: `make lint` (will be checked by CI)
Reviewed-on: #47
Reviewed-by: Andre_Harms <andre.harms@stackit.cloud>
Co-authored-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
Co-committed-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
71 lines
2.7 KiB
YAML
71 lines
2.7 KiB
YAML
name: 'Setup Go and cache dependencies'
|
|
author: 'Forgejo authors, Marcel S. Henselin'
|
|
description: |
|
|
Wrap the setup-go with improved dependency caching.
|
|
|
|
inputs:
|
|
username:
|
|
description: 'User for which to manage the dependency cache'
|
|
default: root
|
|
|
|
go-version:
|
|
description: "go version to install"
|
|
default: '1.25'
|
|
required: true
|
|
|
|
runs:
|
|
using: "composite"
|
|
steps:
|
|
- name: "Install zstd for faster caching"
|
|
shell: bash
|
|
run: |
|
|
apt-get update -qq
|
|
apt-get -q install -qq -y zstd
|
|
|
|
- name: "Set up Go using setup-go"
|
|
uses: https://code.forgejo.org/actions/setup-go@v6
|
|
id: go-version
|
|
with:
|
|
go-version: ${{ inputs.go-version }}
|
|
check-latest: true # Always check for the latest patch release
|
|
# go-version-file: "go.mod"
|
|
# do not cache dependencies, we do this manually
|
|
cache: false
|
|
|
|
- name: "Get go environment information"
|
|
shell: bash
|
|
id: go-environment
|
|
run: |
|
|
chmod 755 $HOME # ensure ${RUN_AS_USER} has permission when go is located in $HOME
|
|
export GOROOT="$(go env GOROOT)"
|
|
echo "modcache=$(su ${RUN_AS_USER} -c '${GOROOT}/bin/go env GOMODCACHE')" >> "$GITHUB_OUTPUT"
|
|
echo "cache=$(su ${RUN_AS_USER} -c '${GOROOT}/bin/go env GOCACHE')" >> "$GITHUB_OUTPUT"
|
|
env:
|
|
RUN_AS_USER: ${{ inputs.username }}
|
|
GO_VERSION: ${{ steps.go-version.outputs.go-version }}
|
|
|
|
- name: "Create cache folders with correct permissions (for non-root users)"
|
|
shell: bash
|
|
if: inputs.username != 'root'
|
|
# when the cache is restored, only the permissions of the last part are restored
|
|
# so assuming that /home/user exists and we are restoring /home/user/go/pkg/mod,
|
|
# both folders will have the correct permissions, but
|
|
# /home/user/go and /home/user/go/pkg might be owned by root
|
|
run: |
|
|
su ${RUN_AS_USER} -c 'mkdir -p "${MODCACHE_DIR}" "${CACHE_DIR}"'
|
|
env:
|
|
RUN_AS_USER: ${{ inputs.username }}
|
|
MODCACHE_DIR: ${{ steps.go-environment.outputs.modcache }}
|
|
CACHE_DIR: ${{ steps.go-environment.outputs.cache }}
|
|
|
|
- name: "Restore Go dependencies from cache or mark for later caching"
|
|
id: cache-deps
|
|
uses: https://code.forgejo.org/actions/cache@v5
|
|
with:
|
|
key: setup-cache-go-deps-${{ runner.os }}-${{ inputs.username }}-${{ steps.go-version.outputs.go_version }}-${{ hashFiles('go.sum', 'go.mod') }}
|
|
restore-keys: |
|
|
setup-cache-go-deps-${{ runner.os }}-${{ inputs.username }}-${{ steps.go-version.outputs.go_version }}-
|
|
setup-cache-go-deps-${{ runner.os }}-${{ inputs.username }}-
|
|
path: |
|
|
${{ steps.go-environment.outputs.modcache }}
|
|
${{ steps.go-environment.outputs.cache }}
|