From 16845123086ab6c1191da3c4c17c131ae5ea67bd Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Thu, 4 Sep 2025 16:29:39 +0800 Subject: [PATCH] ci(release test):cache key to env --- .github/actions/setup-goreleaser/action.yml | 11 +++++-- .github/workflows/release-build.yml | 36 +++++++++++++++++---- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/.github/actions/setup-goreleaser/action.yml b/.github/actions/setup-goreleaser/action.yml index 1748c12e..d4ef8665 100644 --- a/.github/actions/setup-goreleaser/action.yml +++ b/.github/actions/setup-goreleaser/action.yml @@ -1,5 +1,12 @@ name: "Setup GoReleaser" description: "Setup GoReleaser environment" +inputs: + darwin-cache-key: + description: "Darwin sysroot cache key" + required: true + linux-cache-key: + description: "Linux sysroot cache key" + required: true runs: using: "composite" steps: @@ -12,13 +19,13 @@ runs: uses: actions/cache/restore@v4 with: path: .sysroot/darwin.tar.gz - key: darwin-sysroot-${{ hashFiles('.github/workflows/populate_darwin_sysroot.sh') }}-0.0.5 + key: ${{ inputs.darwin-cache-key }} - name: Restore Linux sysroot cache id: cache-linux-sysroot uses: actions/cache/restore@v4 with: path: .sysroot/linux.tar.gz - key: linux-sysroot-${{ hashFiles('.github/workflows/populate_linux_sysroot.sh') }}-0.0.7 + key: ${{ inputs.linux-cache-key }} - name: Populate Darwin sysroot run: tar -xzvf .sysroot/darwin.tar.gz -C .sysroot shell: bash diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml index c678d7df..53deb458 100644 --- a/.github/workflows/release-build.yml +++ b/.github/workflows/release-build.yml @@ -8,8 +8,25 @@ on: branches: ["**"] jobs: + setup: + runs-on: ubuntu-latest + outputs: + darwin-cache-key: ${{ steps.cache-keys.outputs.darwin-key }} + linux-cache-key: ${{ steps.cache-keys.outputs.linux-key }} + steps: + - name: Check out code + uses: actions/checkout@v5 + - name: Calculate cache keys + id: cache-keys + run: | + DARWIN_KEY="darwin-sysroot-${{ hashFiles('.github/workflows/populate_darwin_sysroot.sh') }}-0.0.5" + LINUX_KEY="linux-sysroot-${{ hashFiles('.github/workflows/populate_linux_sysroot.sh') }}-0.0.7" + echo "darwin-key=$DARWIN_KEY" >> $GITHUB_OUTPUT + echo "linux-key=$LINUX_KEY" >> $GITHUB_OUTPUT + populate-darwin-sysroot: runs-on: macos-latest + needs: setup steps: - name: Check out code uses: actions/checkout@v5 @@ -18,7 +35,7 @@ jobs: uses: actions/cache/restore@v4 with: path: .sysroot/darwin.tar.gz - key: darwin-sysroot-${{ hashFiles('.github/workflows/populate_darwin_sysroot.sh') }}-0.0.5 + key: ${{ needs.setup.outputs.darwin-cache-key }} lookup-only: true - name: Populate Darwin sysroot if: steps.cache-darwin-sysroot.outputs.cache-hit != 'true' @@ -31,9 +48,10 @@ jobs: uses: actions/cache/save@v4 with: path: .sysroot/darwin.tar.gz - key: darwin-sysroot-${{ hashFiles('.github/workflows/populate_darwin_sysroot.sh') }}-0.0.5 + key: ${{ needs.setup.outputs.darwin-cache-key }} populate-linux-sysroot: runs-on: ubuntu-latest + needs: setup steps: - name: Check out code uses: actions/checkout@v5 @@ -42,7 +60,7 @@ jobs: uses: actions/cache/restore@v4 with: path: .sysroot/linux.tar.gz - key: linux-sysroot-${{ hashFiles('.github/workflows/populate_linux_sysroot.sh') }}-0.0.7 + key: ${{ needs.setup.outputs.linux-cache-key }} lookup-only: true - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -60,15 +78,18 @@ jobs: uses: actions/cache/save@v4 with: path: .sysroot/linux.tar.gz - key: linux-sysroot-${{ hashFiles('.github/workflows/populate_linux_sysroot.sh') }}-0.0.7 + key: ${{ needs.setup.outputs.linux-cache-key }} build: runs-on: ubuntu-latest - needs: [populate-darwin-sysroot, populate-linux-sysroot] + needs: [setup, populate-darwin-sysroot, populate-linux-sysroot] steps: - name: Check out code uses: actions/checkout@v5 - name: Set up Release uses: ./.github/actions/setup-goreleaser + with: + darwin-cache-key: ${{ needs.setup.outputs.darwin-cache-key }} + linux-cache-key: ${{ needs.setup.outputs.linux-cache-key }} - name: Run GoReleaser (Build & Test) env: GITHUB_TOKEN: ${{github.token}} @@ -178,7 +199,7 @@ jobs: mod-version: ${{ matrix.go-mod-version }} release: - needs: [build, test-artifacts] + needs: [setup, build, test-artifacts] runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/') steps: @@ -188,6 +209,9 @@ jobs: fetch-depth: 0 - name: Set up Release uses: ./.github/actions/setup-goreleaser + with: + darwin-cache-key: ${{ needs.setup.outputs.darwin-cache-key }} + linux-cache-key: ${{ needs.setup.outputs.linux-cache-key }} - name: Run GoReleaser (Release) env: GITHUB_TOKEN: ${{github.token}}