summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Kriese <michael.kriese@gmx.de>2024-12-05 09:36:03 +0100
committerMichael Kriese <michael.kriese@gmx.de>2024-12-05 09:36:03 +0100
commit70892c4813c19a8c9a465122bae737a743bd7dec (patch)
tree819a9d817eddacc6c19908f569cfaa33879ea15e
parentMerge pull request 'chore(i18): cleanup locales' (#6090) from earl-warren/for... (diff)
parentci: include and fix `setup-cache-go` action (diff)
downloadforgejo-70892c4813c19a8c9a465122bae737a743bd7dec.tar.xz
forgejo-70892c4813c19a8c9a465122bae737a743bd7dec.zip
Merge pull request 'build: only require go minor' (#6151) from viceice/forgejo:build/pin-go-to-minor-only into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6151 Reviewed-by: Gusted <gusted@noreply.codeberg.org>
-rw-r--r--.forgejo/workflows-composite/setup-cache-go/action.yaml59
-rw-r--r--.forgejo/workflows-composite/setup-env/action.yaml2
-rw-r--r--go.mod2
3 files changed, 61 insertions, 2 deletions
diff --git a/.forgejo/workflows-composite/setup-cache-go/action.yaml b/.forgejo/workflows-composite/setup-cache-go/action.yaml
new file mode 100644
index 0000000000..adec8c7c4c
--- /dev/null
+++ b/.forgejo/workflows-composite/setup-cache-go/action.yaml
@@ -0,0 +1,59 @@
+# SPDX-License-Identifier: MIT
+name: 'Forgejo Actions to setup Go and cache dependencies'
+author: 'Forgejo authors'
+description: |
+ Wrap the setup-go with improved dependency caching.
+inputs:
+ username:
+ description: 'User for which to manage the dependency cache'
+ default: root
+
+runs:
+ using: "composite"
+ steps:
+ - name: "Install zstd for faster caching"
+ 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@v5
+ id: go-version
+ with:
+ go-version-file: "go.mod"
+ # do not cache dependencies, we do this manually
+ cache: false
+
+ - name: "Get go environment information"
+ id: go-environment
+ run: |
+ echo "modcache=$(su ${RUN_AS_USER} -c '/opt/hostedtoolcache/go/${GO_VERSION}/x64/bin/go env GOMODCACHE')" >> "$GITHUB_OUTPUT"
+ echo "cache=$(su ${RUN_AS_USER} -c '/opt/hostedtoolcache/go/${GO_VERSION}/x64/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)"
+ 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: actions/cache@v4
+ 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 }}
diff --git a/.forgejo/workflows-composite/setup-env/action.yaml b/.forgejo/workflows-composite/setup-env/action.yaml
index 83cce157bd..28216e9b8d 100644
--- a/.forgejo/workflows-composite/setup-env/action.yaml
+++ b/.forgejo/workflows-composite/setup-env/action.yaml
@@ -10,7 +10,7 @@ runs:
adduser --quiet --comment forgejo --disabled-password forgejo || true
chown -R forgejo:forgejo .
- - uses: https://codeberg.org/fnetx/setup-cache-go@4b50dd28b1068fa06d433c5fabed3f6f4d4ccddf
+ - uses: ./.forgejo/workflows-composite/setup-cache-go
with:
username: forgejo
diff --git a/go.mod b/go.mod
index 03a61c481b..53d3e1ef3e 100644
--- a/go.mod
+++ b/go.mod
@@ -1,6 +1,6 @@
module code.gitea.io/gitea
-go 1.23.1
+go 1.23
toolchain go1.23.4