-
Notifications
You must be signed in to change notification settings - Fork 174
chore(ci): disable buildvcs stamping into binaries #19095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8fdfdfe
7173d76
046ed05
07fcb33
2ec9c25
3566da5
b49ed70
8eb5eba
d705061
b8dad64
89e6230
ee29ef8
1edc031
7f1a1c0
64385e7
6526120
076db7c
2df7925
0b0a150
d0583a0
ad46e0e
ab6a92e
7586559
87fa2bf
32d4edf
aa622b6
11b555f
44d6bd7
59ba12c
ff1adfe
5ff4ce2
9e1a72f
098af8d
a77834e
b23a670
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,37 +14,38 @@ runs: | |
| echo "GOCACHE=$(go env GOCACHE)" >> "$GITHUB_OUTPUT" | ||
| echo "GOMODCACHE=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT" | ||
| echo "GOARCH=$(go env GOARCH)" >> "$GITHUB_OUTPUT" | ||
| echo "TAG=$(date +%Yw%U)" >> "$GITHUB_OUTPUT" | ||
| TAG="${{ contains(github.event.pull_request.labels.*.name, 'ci-save-cache') && github.event.pull_request.number || '' }}" | ||
| echo "TAG=${TAG:-$(date +%Yw%U)}" >> "$GITHUB_OUTPUT" | ||
| shell: bash | ||
|
|
||
| # Save caches only on pushes to the default branch. | ||
| # All other events (PRs, etc.) restore only. | ||
| # Save caches on pushes to the default branch, or on PRs with the | ||
| # ci-save-cache label (for testing cache-affecting changes on branches). | ||
| - name: Cache Go Dependencies (save) | ||
| if: inputs.save == 'true' && (github.event_name == 'push' && github.ref_name == github.event.repository.default_branch) | ||
| if: inputs.save == 'true' && (github.event_name == 'push' && github.ref_name == github.event.repository.default_branch || contains(github.event.pull_request.labels.*.name, 'ci-save-cache')) | ||
| uses: actions/cache@v5 | ||
| with: | ||
| path: ${{ steps.cache-paths.outputs.GOMODCACHE }} | ||
| key: go-mod-v1-${{ hashFiles('**/go.sum') }} | ||
| restore-keys: go-mod-v1- | ||
|
|
||
| - name: Cache Go Dependencies (restore) | ||
| if: ${{ !(inputs.save == 'true' && (github.event_name == 'push' && github.ref_name == github.event.repository.default_branch)) }} | ||
| if: ${{ !(inputs.save == 'true' && (github.event_name == 'push' && github.ref_name == github.event.repository.default_branch || contains(github.event.pull_request.labels.*.name, 'ci-save-cache'))) }} | ||
|
Comment on lines
31
to
+32
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): The restore condition has the same To avoid undefined access and keep the logic easier to validate, consider reusing the guarded save condition and inverting it for restore, e.g.: if: ${{ !(inputs.save == 'true' && (
(github.event_name == 'push' && github.ref_name == github.event.repository.default_branch) ||
(github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'ci-save-cache'))
)) }}This keeps restore as the exact inverse of the guarded save condition while only evaluating Suggested implementation: |
||
| uses: actions/cache/restore@v5 | ||
| with: | ||
| path: ${{ steps.cache-paths.outputs.GOMODCACHE }} | ||
| key: go-mod-v1-${{ hashFiles('**/go.sum') }} | ||
| restore-keys: go-mod-v1- | ||
|
|
||
| - name: Cache Go Build (save) | ||
| if: inputs.save == 'true' && (github.event_name == 'push' && github.ref_name == github.event.repository.default_branch) | ||
| if: inputs.save == 'true' && (github.event_name == 'push' && github.ref_name == github.event.repository.default_branch || contains(github.event.pull_request.labels.*.name, 'ci-save-cache')) | ||
| uses: actions/cache@v5 | ||
| with: | ||
| path: ${{ steps.cache-paths.outputs.GOCACHE }} | ||
| key: go-build-v1-${{ github.job }}-${{ steps.cache-paths.outputs.GOARCH }}-${{ steps.cache-paths.outputs.TAG }} | ||
| restore-keys: go-build-v1-${{ github.job }}-${{ steps.cache-paths.outputs.GOARCH }}- | ||
|
|
||
| - name: Cache Go Build (restore) | ||
| if: ${{ !(inputs.save == 'true' && (github.event_name == 'push' && github.ref_name == github.event.repository.default_branch)) }} | ||
| if: ${{ !(inputs.save == 'true' && (github.event_name == 'push' && github.ref_name == github.event.repository.default_branch || contains(github.event.pull_request.labels.*.name, 'ci-save-cache'))) }} | ||
| uses: actions/cache/restore@v5 | ||
| with: | ||
| path: ${{ steps.cache-paths.outputs.GOCACHE }} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,333 @@ | ||
| name: Test Go Git Index Optimization | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| push: | ||
| branches: | ||
| - 'davdhacs/gha-disable-buildvcs' | ||
|
|
||
| defaults: | ||
| run: | ||
| shell: bash | ||
|
|
||
| jobs: | ||
|
|
||
| # ================================================================== | ||
| # Build patched Go toolchain (cached by patch hash) | ||
| # ================================================================== | ||
| build-patched-go: | ||
| runs-on: ubuntu-latest | ||
| container: | ||
| image: quay.io/stackrox-io/apollo-ci:stackrox-test-0.5.2 | ||
| volumes: | ||
| - /usr:/mnt/usr | ||
| - /opt:/mnt/opt | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Cache patched Go toolchain | ||
| id: go-cache | ||
| uses: actions/cache@v5 | ||
| with: | ||
| path: /tmp/go-patched | ||
| key: patched-go-v1-${{ hashFiles('scripts/go-gitindex.patch') }} | ||
|
|
||
| - name: Build patched Go toolchain | ||
| if: steps.go-cache.outputs.cache-hit != 'true' | ||
| run: | | ||
| set -euo pipefail | ||
| echo "::group::Clone Go 1.25.7" | ||
| git clone --depth=1 --branch go1.25.7 https://go.googlesource.com/go /tmp/go-patched 2>&1 | ||
| echo "::endgroup::" | ||
|
|
||
| echo "::group::Apply patch" | ||
| cd /tmp/go-patched | ||
| git apply "$GITHUB_WORKSPACE/scripts/go-gitindex.patch" | ||
| echo "::endgroup::" | ||
|
|
||
| echo "::group::Build Go toolchain" | ||
| cd /tmp/go-patched/src | ||
| GOROOT_BOOTSTRAP="$(go env GOROOT)" ./make.bash 2>&1 | tail -5 | ||
| echo "::endgroup::" | ||
|
|
||
| - name: Verify patched Go | ||
| continue-on-error: true | ||
| run: | | ||
| echo "Patched Go: $(/tmp/go-patched/bin/go version)" | ||
| echo "Compiler SHA256:" | ||
| sha256sum "/tmp/go-patched/pkg/tool/linux_amd64/compile" 2>/dev/null || true | ||
|
|
||
| # ================================================================== | ||
| # BASELINE: patched Go binary, all optimizations DISABLED | ||
| # Same compiler binary + fresh per-run cache = fair comparison | ||
| # ================================================================== | ||
| pre-build-go-binaries: | ||
| needs: build-patched-go | ||
| runs-on: ubuntu-latest | ||
| container: | ||
| image: quay.io/stackrox-io/apollo-ci:stackrox-test-0.5.2 | ||
| volumes: | ||
| - /usr:/mnt/usr | ||
| - /opt:/mnt/opt | ||
| env: | ||
| GONOBITINDEX: "1" | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - uses: ./.github/actions/job-preamble | ||
| with: | ||
| gcp-account: ${{ secrets.GCP_SERVICE_ACCOUNT_STACKROX_CI }} | ||
|
|
||
| - name: Restore patched Go toolchain | ||
| uses: actions/cache/restore@v5 | ||
| with: | ||
| path: /tmp/go-patched | ||
| key: patched-go-v1-${{ hashFiles('scripts/go-gitindex.patch') }} | ||
|
|
||
| - name: Set patched Go as default | ||
| run: | | ||
| echo "/tmp/go-patched/bin" >> "$GITHUB_PATH" | ||
| echo "GOROOT=/tmp/go-patched" >> "$GITHUB_ENV" | ||
|
|
||
| # Restore GOCACHE with per-run key (fresh cache, not stale weekly) | ||
| - name: Restore GOCACHE | ||
| id: baseline-gocache | ||
| uses: actions/cache/restore@v5 | ||
| with: | ||
| path: /github/home/.cache/go-build | ||
| key: baseline-gocache-v1-${{ hashFiles('scripts/go-gitindex.patch') }}-${{ github.run_id }} | ||
| restore-keys: | | ||
| baseline-gocache-v1-${{ hashFiles('scripts/go-gitindex.patch') }}- | ||
|
|
||
| - name: Restore GOMODCACHE | ||
| uses: actions/cache/restore@v5 | ||
| with: | ||
| path: /github/home/go/pkg/mod | ||
| key: go-mod-v1-${{ hashFiles('**/go.sum') }} | ||
| restore-keys: go-mod-v1- | ||
|
|
||
| - name: Download Go modules | ||
| run: make deps --always-make | ||
|
|
||
| - name: Record environment | ||
| continue-on-error: true | ||
| run: | | ||
| echo "Go: $(go version)" | ||
| echo "GONOBITINDEX: ${GONOBITINDEX}" | ||
| echo "GOCACHE: $(go env GOCACHE)" | ||
| echo "GOCACHE restored: ${{ steps.baseline-gocache.outputs.cache-hit || 'prefix-match-or-miss' }}" | ||
| echo "GOCACHE matched key: ${{ steps.baseline-gocache.outputs.cache-matched-key || 'none' }}" | ||
| echo "GOCACHE size: $(du -sh "$(go env GOCACHE)" 2>/dev/null | cut -f1 || echo 'empty')" | ||
| echo "Compiler SHA256:" | ||
| sha256sum "$(go env GOROOT)/pkg/tool/$(go env GOOS)_$(go env GOARCH)/compile" 2>/dev/null || true | ||
|
|
||
| - name: "Build Go Binaries (baseline, optimizations DISABLED)" | ||
| continue-on-error: true | ||
| run: | | ||
| time GOOS=linux GOARCH=amd64 CGO_ENABLED=1 make build-prep main-build-nodeps GOFLAGS="-v" 2>&1 | tee /tmp/build1.log | ||
| echo "Packages compiled: $(grep -c '^[a-z]' /tmp/build1.log 2>/dev/null || echo 0)" | ||
|
|
||
| - name: "Rebuild (known-warm)" | ||
| continue-on-error: true | ||
| run: | | ||
| time GOOS=linux GOARCH=amd64 CGO_ENABLED=1 make build-prep main-build-nodeps 2>&1 | ||
|
|
||
| - name: "Warm build timing (baseline, 3 runs)" | ||
| continue-on-error: true | ||
| run: | | ||
| for i in 1 2 3; do | ||
| echo "--- run $i ---" | ||
| time GOOS=linux GOARCH=amd64 CGO_ENABLED=1 make build-prep main-build-nodeps 2>&1 | ||
| done | ||
|
|
||
| - name: Save GOCACHE | ||
| uses: actions/cache/save@v5 | ||
| continue-on-error: true | ||
| with: | ||
| path: /github/home/.cache/go-build | ||
| key: baseline-gocache-v1-${{ hashFiles('scripts/go-gitindex.patch') }}-${{ github.run_id }} | ||
|
|
||
| # ================================================================== | ||
| # PATCHED GO: cold build — populates GOCACHE, saves it | ||
| # ================================================================== | ||
| patched-go-cold-build: | ||
| needs: build-patched-go | ||
| runs-on: ubuntu-latest | ||
| container: | ||
| image: quay.io/stackrox-io/apollo-ci:stackrox-test-0.5.2 | ||
| volumes: | ||
| - /usr:/mnt/usr | ||
| - /opt:/mnt/opt | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - uses: ./.github/actions/job-preamble | ||
| with: | ||
| gcp-account: ${{ secrets.GCP_SERVICE_ACCOUNT_STACKROX_CI }} | ||
|
|
||
| - name: Restore patched Go toolchain | ||
| uses: actions/cache/restore@v5 | ||
| with: | ||
| path: /tmp/go-patched | ||
| key: patched-go-v1-${{ hashFiles('scripts/go-gitindex.patch') }} | ||
|
|
||
| - name: Set patched Go as default | ||
| run: | | ||
| echo "/tmp/go-patched/bin" >> "$GITHUB_PATH" | ||
| echo "GOROOT=/tmp/go-patched" >> "$GITHUB_ENV" | ||
|
|
||
| # Restore GOCACHE: exact match for this run, or prefix match from previous run | ||
| - name: Restore GOCACHE | ||
| id: gocache-restore | ||
| uses: actions/cache/restore@v5 | ||
| with: | ||
| path: /github/home/.cache/go-build | ||
| key: patched-gocache-v1-${{ hashFiles('scripts/go-gitindex.patch') }}-${{ github.run_id }} | ||
| restore-keys: | | ||
| patched-gocache-v1-${{ hashFiles('scripts/go-gitindex.patch') }}- | ||
|
|
||
| - name: Restore GOMODCACHE | ||
| uses: actions/cache/restore@v5 | ||
| with: | ||
| path: /github/home/go/pkg/mod | ||
| key: go-mod-v1-${{ hashFiles('**/go.sum') }} | ||
| restore-keys: go-mod-v1- | ||
|
|
||
| - name: Download Go modules | ||
| run: make deps --always-make | ||
|
|
||
| - name: Record environment | ||
| continue-on-error: true | ||
| run: | | ||
| echo "Go: $(go version)" | ||
| echo "GOCACHE: $(go env GOCACHE)" | ||
| echo "GOCACHE restored: ${{ steps.gocache-restore.outputs.cache-hit || 'prefix-match-or-miss' }}" | ||
| echo "GOCACHE matched key: ${{ steps.gocache-restore.outputs.cache-matched-key || 'none' }}" | ||
| echo "GOCACHE size: $(du -sh "$(go env GOCACHE)" 2>/dev/null | cut -f1 || echo 'empty')" | ||
| echo "Compiler SHA256:" | ||
| sha256sum "$(go env GOROOT)/pkg/tool/$(go env GOOS)_$(go env GOARCH)/compile" 2>/dev/null || true | ||
|
|
||
| - name: "Build Go Binaries (patched Go)" | ||
| continue-on-error: true | ||
| run: | | ||
| echo "=== Build (patched Go) ===" | ||
| time GOOS=linux GOARCH=amd64 CGO_ENABLED=1 make build-prep main-build-nodeps GOFLAGS="-v" 2>&1 | tee /tmp/build1.log | ||
| echo "Packages compiled: $(grep -c '^[a-z]' /tmp/build1.log 2>/dev/null || echo 0)" | ||
|
|
||
| - name: "Rebuild (known-warm, same job)" | ||
| continue-on-error: true | ||
| run: | | ||
| echo "=== Known-warm rebuild ===" | ||
| time GOOS=linux GOARCH=amd64 CGO_ENABLED=1 make build-prep main-build-nodeps 2>&1 | ||
|
|
||
| - name: "GOCACHE after build" | ||
| continue-on-error: true | ||
| run: | | ||
| GOCACHE="$(go env GOCACHE)" | ||
| echo "GOCACHE size: $(du -sh "$GOCACHE" 2>/dev/null | cut -f1)" | ||
| echo "Total files: $(find "$GOCACHE" -type f 2>/dev/null | wc -l)" | ||
|
|
||
| # Save with run-specific key (unique, so save always works) | ||
| - name: Save GOCACHE | ||
| uses: actions/cache/save@v5 | ||
| continue-on-error: true | ||
| with: | ||
| path: /github/home/.cache/go-build | ||
| key: patched-gocache-v1-${{ hashFiles('scripts/go-gitindex.patch') }}-${{ github.run_id }} | ||
|
|
||
| # ================================================================== | ||
| # PATCHED GO: warm build — restores GOCACHE from cold build | ||
| # Same Go binary + same GOCACHE = should be a cache hit | ||
| # ================================================================== | ||
| patched-go-warm-build: | ||
| needs: patched-go-cold-build | ||
| runs-on: ubuntu-latest | ||
| container: | ||
| image: quay.io/stackrox-io/apollo-ci:stackrox-test-0.5.2 | ||
| volumes: | ||
| - /usr:/mnt/usr | ||
| - /opt:/mnt/opt | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - uses: ./.github/actions/job-preamble | ||
| with: | ||
| gcp-account: ${{ secrets.GCP_SERVICE_ACCOUNT_STACKROX_CI }} | ||
|
|
||
| - name: Restore patched Go toolchain | ||
| uses: actions/cache/restore@v5 | ||
| with: | ||
| path: /tmp/go-patched | ||
| key: patched-go-v1-${{ hashFiles('scripts/go-gitindex.patch') }} | ||
|
|
||
| - name: Set patched Go as default | ||
| run: | | ||
| echo "/tmp/go-patched/bin" >> "$GITHUB_PATH" | ||
| echo "GOROOT=/tmp/go-patched" >> "$GITHUB_ENV" | ||
|
|
||
| # Restore this run's GOCACHE from the cold build job | ||
| - name: Restore GOCACHE from cold build | ||
| uses: actions/cache/restore@v5 | ||
| with: | ||
| path: /github/home/.cache/go-build | ||
| key: patched-gocache-v1-${{ hashFiles('scripts/go-gitindex.patch') }}-${{ github.run_id }} | ||
|
|
||
| - name: Restore GOMODCACHE | ||
| uses: actions/cache/restore@v5 | ||
| with: | ||
| path: /github/home/go/pkg/mod | ||
| key: go-mod-v1-${{ hashFiles('**/go.sum') }} | ||
| restore-keys: go-mod-v1- | ||
|
|
||
| - name: Download Go modules | ||
| run: make deps --always-make | ||
|
|
||
| - name: Record environment | ||
| continue-on-error: true | ||
| run: | | ||
| echo "Go: $(go version)" | ||
| echo "GOCACHE: $(go env GOCACHE)" | ||
| echo "GOCACHE size: $(du -sh "$(go env GOCACHE)" 2>/dev/null | cut -f1 || echo 'empty')" | ||
| echo "Compiler SHA256:" | ||
| sha256sum "$(go env GOROOT)/pkg/tool/$(go env GOOS)_$(go env GOARCH)/compile" 2>/dev/null || true | ||
|
|
||
| - name: "Build Go Binaries (patched Go, restored GOCACHE)" | ||
| continue-on-error: true | ||
| run: | | ||
| echo "=== Build with restored GOCACHE ===" | ||
| time GOOS=linux GOARCH=amd64 CGO_ENABLED=1 make build-prep main-build-nodeps GOFLAGS="-v" 2>&1 | tee /tmp/build1.log | ||
| echo "Packages compiled (cache misses): $(grep -c '^[a-z]' /tmp/build1.log 2>/dev/null || echo 0)" | ||
|
|
||
| - name: "Rebuild (known-warm)" | ||
| continue-on-error: true | ||
| run: | | ||
| echo "=== Known-warm rebuild ===" | ||
| time GOOS=linux GOARCH=amd64 CGO_ENABLED=1 make build-prep main-build-nodeps 2>&1 | ||
|
|
||
| - name: "Warm build timing (git index ENABLED, 3 runs)" | ||
| continue-on-error: true | ||
| run: | | ||
| for i in 1 2 3; do | ||
| echo "--- run $i ---" | ||
| time GOOS=linux GOARCH=amd64 CGO_ENABLED=1 make build-prep main-build-nodeps 2>&1 | ||
| done | ||
|
|
||
| - name: "Warm build timing (git index DISABLED, 3 runs)" | ||
| continue-on-error: true | ||
| env: | ||
| GONOBITINDEX: "1" | ||
| run: | | ||
| for i in 1 2 3; do | ||
| echo "--- run $i ---" | ||
| time GOOS=linux GOARCH=amd64 CGO_ENABLED=1 make build-prep main-build-nodeps 2>&1 | ||
| done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Referencing
github.event.pull_requeston non-PR events can break the workflow expression.On push events,
github.event.pull_requestis undefined, and accessing its properties can cause the workflow condition to error. To avoid failures on pushes, wrap the label check in an event guard, e.g.:This preserves the intended behavior without touching
github.event.pull_requestwhen it doesn’t exist.