From c6ca020281423816fe7257c3aaa5a3bc06590413 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 24 Oct 2026 17:04:51 +0000 Subject: [PATCH] ci: implement gitea's cache-seeder (#1350) Like Gitea's CI, only a `cache-seeder` workflow on main saves the go caches, all other jobs only restore them. Caches are scoped per repository, so until now any pull request, forks included, could write a cache that other runs restore. The seeder compiles the tests without running them, so no test result is ever cached. Reviewed-on: https://gitea.com/gitea/runner/pulls/1350 Reviewed-by: Lunny Xiao Co-authored-by: silverwind --- .gitea/actions/go-setup/action.yml | 29 +++++++++++++++++++++++++++++ .gitea/workflows/cache-seeder.yml | 26 ++++++++++++++++++++++++++ .gitea/workflows/test.yml | 10 ++-------- 3 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 .gitea/actions/go-setup/action.yml create mode 100644 .gitea/workflows/cache-seeder.yml diff --git a/.gitea/actions/go-setup/action.yml b/.gitea/actions/go-setup/action.yml new file mode 100644 index 00000000..78fc503e --- /dev/null +++ b/.gitea/actions/go-setup/action.yml @@ -0,0 +1,29 @@ +name: go-setup +description: Set up go and restore its caches, which only the cache-seeder workflow saves + +runs: + using: composite + steps: + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7 + id: setup-go + with: + go-version-file: go.mod + check-latest: true + cache: false + - if: ${{ github.workflow == 'cache-seeder' }} + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + ~/.cache/golangci-lint + key: go-${{ runner.os }}-${{ runner.arch }}-${{ steps.setup-go.outputs.go-version }}-${{ hashFiles('go.mod', 'go.sum', '.golangci.yml', 'Makefile', '.gitea/actions/go-setup/action.yml', '.gitea/workflows/cache-seeder.yml') }} + - if: ${{ github.workflow != 'cache-seeder' }} + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + ~/.cache/golangci-lint + key: go-${{ runner.os }}-${{ runner.arch }}-${{ steps.setup-go.outputs.go-version }}-${{ hashFiles('go.mod', 'go.sum', '.golangci.yml', 'Makefile', '.gitea/actions/go-setup/action.yml', '.gitea/workflows/cache-seeder.yml') }} + restore-keys: go-${{ runner.os }}-${{ runner.arch }}-${{ steps.setup-go.outputs.go-version }}- diff --git a/.gitea/workflows/cache-seeder.yml b/.gitea/workflows/cache-seeder.yml new file mode 100644 index 00000000..0d47a444 --- /dev/null +++ b/.gitea/workflows/cache-seeder.yml @@ -0,0 +1,26 @@ +name: cache-seeder + +on: + workflow_dispatch: + push: + branches: + - main + paths: + - go.mod + - go.sum + - .golangci.yml + - Makefile + - .gitea/actions/go-setup/action.yml + - .gitea/workflows/cache-seeder.yml + +jobs: + seed: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + - uses: ./.gitea/actions/go-setup + - run: make deps-tools lint build + - name: compile the test binaries without running them + run: | + make test GOTEST_FLAGS='-race -exec true' + go test -tags e2e -exec true ./e2e/... diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index 7d833e0c..61184e93 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -17,10 +17,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7 - with: - go-version-file: 'go.mod' - check-latest: true + - uses: ./.gitea/actions/go-setup - name: prepare anonymous docker config run: mkdir -p "$DOCKER_CONFIG" && echo '{}' > "$DOCKER_CONFIG/config.json" # Pre-pull act/runner's two largest base images so a slow pull can't dominate `make test`; @@ -68,10 +65,7 @@ jobs: - gitea/gitea:main-nightly steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7 - with: - go-version-file: 'go.mod' - check-latest: true + - uses: ./.gitea/actions/go-setup - name: prepare anonymous docker config run: mkdir -p "$DOCKER_CONFIG" && echo '{}' > "$DOCKER_CONFIG/config.json" - name: e2e compatibility