|
| 1 | +name: Accept Goldens |
| 2 | + |
| 3 | +# Triggered manually from the Actions tab. Checks out the specified branch, |
| 4 | +# runs the full test suite with PULUMI_ACCEPT=1 (and autogold `-update`), and |
| 5 | +# commits any refreshed golden files back to the branch. Used when local |
| 6 | +# golden regeneration cannot reproduce CI (e.g. plugins missing on |
| 7 | +# darwin-arm64). |
| 8 | + |
| 9 | +on: |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + ref: |
| 13 | + description: 'Branch (or ref) to regenerate goldens on' |
| 14 | + required: true |
| 15 | + default: 'main' |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: write |
| 19 | + |
| 20 | +env: |
| 21 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 22 | + PULUMI_SKIP_UPDATE_CHECK: 'true' |
| 23 | + |
| 24 | +jobs: |
| 25 | + accept: |
| 26 | + runs-on: ubuntu-latest |
| 27 | + timeout-minutes: 180 |
| 28 | + steps: |
| 29 | + - name: Check out source code |
| 30 | + uses: actions/checkout@v4 |
| 31 | + with: |
| 32 | + ref: ${{ github.event.inputs.ref }} |
| 33 | + persist-credentials: true |
| 34 | + - name: Install terraform |
| 35 | + uses: hashicorp/setup-terraform@v3 |
| 36 | + with: |
| 37 | + terraform_wrapper: false |
| 38 | + - name: Install Go |
| 39 | + uses: actions/setup-go@v5 |
| 40 | + with: |
| 41 | + go-version: 1.25.x |
| 42 | + cache-dependency-path: | |
| 43 | + **/go.sum |
| 44 | + - name: Find pulumi version |
| 45 | + id: pulumi_version |
| 46 | + shell: bash |
| 47 | + run: | |
| 48 | + GO_MODULE_VERSION=$(go list -m -f '{{.Version}}' github.com/pulumi/pulumi/pkg/v3) |
| 49 | + echo "pulumi_version=${GO_MODULE_VERSION#v}" >> "$GITHUB_OUTPUT" |
| 50 | + - name: Install pulumi |
| 51 | + uses: pulumi/actions@8e5e406f4007fca908480587cb9893c07090f58d # v7 |
| 52 | + with: |
| 53 | + pulumi-version: ${{ steps.pulumi_version.outputs.pulumi_version }} |
| 54 | + - name: Build |
| 55 | + run: make build |
| 56 | + - name: Build PF |
| 57 | + run: cd pkg/pf && make build |
| 58 | + - name: Restore plugins |
| 59 | + uses: actions/cache/restore@v4 |
| 60 | + with: |
| 61 | + path: ~/.pulumi/plugins |
| 62 | + key: ubuntu-latest-plugins |
| 63 | + restore-keys: | |
| 64 | + ubuntu-latest-plugins |
| 65 | + # Discover Go packages that import hexops/autogold so we can pass |
| 66 | + # `-args -update` only to those. `-update` is registered by autogold's |
| 67 | + # init(), so packages that don't import it fail with "flag provided |
| 68 | + # but not defined". |
| 69 | + - name: Compute autogold packages |
| 70 | + id: autogold_pkgs |
| 71 | + run: | |
| 72 | + set -euo pipefail |
| 73 | + # List of package dirs (relative) that import autogold. |
| 74 | + pkgs=$(git grep -l 'hexops/autogold' -- '*.go' \ |
| 75 | + | xargs -n1 dirname | sort -u | sed 's|^|./|') |
| 76 | + echo "packages<<EOF" >> "$GITHUB_OUTPUT" |
| 77 | + echo "$pkgs" >> "$GITHUB_OUTPUT" |
| 78 | + echo "EOF" >> "$GITHUB_OUTPUT" |
| 79 | + echo "found $(echo "$pkgs" | wc -l) autogold packages" |
| 80 | + # Two passes: |
| 81 | + # 1. Full suite with PULUMI_ACCEPT=1 (regenerates all non-autogold goldens). |
| 82 | + # 2. Autogold-importing packages with `-args -update` to refresh their |
| 83 | + # autogold values. |
| 84 | + # `make test_accept` handles PULUMI_HOME + plugin install and sets |
| 85 | + # PULUMI_ACCEPT=1 for us. |
| 86 | + - name: Regenerate PULUMI_ACCEPT goldens |
| 87 | + run: | |
| 88 | + make test_accept RUN_TEST_CMD='./...' |
| 89 | + - name: Regenerate autogold goldens |
| 90 | + run: | |
| 91 | + pkgs=$(echo '${{ steps.autogold_pkgs.outputs.packages }}' | tr '\n' ' ') |
| 92 | + make test_accept RUN_TEST_CMD="$pkgs -args -update" |
| 93 | + - name: Commit and push |
| 94 | + run: | |
| 95 | + git config user.name 'github-actions[bot]' |
| 96 | + git config user.email 'github-actions[bot]@users.noreply.github.com' |
| 97 | + if git diff --quiet; then |
| 98 | + echo 'No golden changes.' |
| 99 | + exit 0 |
| 100 | + fi |
| 101 | + git add -A |
| 102 | + git commit -m 'Regenerate goldens via CI' |
| 103 | + git push origin HEAD:${{ github.event.inputs.ref }} |
0 commit comments