|
5 | 5 | types: [opened, reopened, synchronize] |
6 | 6 |
|
7 | 7 | permissions: |
8 | | - contents: read |
| 8 | + contents: write |
9 | 9 | pull-requests: write |
10 | 10 |
|
11 | 11 | jobs: |
12 | | - buf-cre: |
| 12 | + cre-tests: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + strategy: |
| 15 | + fail-fast: false |
| 16 | + matrix: |
| 17 | + check: |
| 18 | + - name: "lint" |
| 19 | + cmd: "buf lint cre" |
| 20 | + needs_buf: true |
| 21 | + needs_go: false |
| 22 | + - name: "breaking" |
| 23 | + cmd: "buf breaking cre --against \".git#branch=main,subdir=cre\" --exclude-path node_modules" |
| 24 | + needs_buf: true |
| 25 | + needs_go: false |
| 26 | + - name: "gofmt" |
| 27 | + cmd: "gofmt -l cre" |
| 28 | + needs_buf: false |
| 29 | + needs_go: true |
| 30 | + - name: "go-test" |
| 31 | + cmd: "cd cre/go && go test ./..." |
| 32 | + needs_buf: false |
| 33 | + needs_go: true |
| 34 | + - name: "verify-run" |
| 35 | + cmd: "cd cre/verify && go run ." |
| 36 | + needs_buf: false |
| 37 | + needs_go: true |
| 38 | + - name: "verify-test" |
| 39 | + cmd: "cd cre/verify && go test ./..." |
| 40 | + needs_buf: false |
| 41 | + needs_go: true |
| 42 | + |
| 43 | + steps: |
| 44 | + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 |
| 45 | + with: |
| 46 | + persist-credentials: true |
| 47 | + ref: ${{ github.head_ref || github.ref_name }} |
| 48 | + |
| 49 | + - name: Setup CRE Environment |
| 50 | + id: setup |
| 51 | + uses: ./.github/actions/setup-cre |
| 52 | + with: |
| 53 | + install-buf: ${{ matrix.check.needs_buf }} |
| 54 | + install-go-tools: ${{ matrix.check.needs_go }} |
| 55 | + |
| 56 | + - name: Run ${{ matrix.check.name }} check |
| 57 | + if: steps.setup.outputs.cre_changed == 'true' |
| 58 | + run: ${{ matrix.check.cmd }} |
| 59 | + |
| 60 | + fix-cre: |
13 | 61 | runs-on: ubuntu-latest |
| 62 | + outputs: |
| 63 | + commit_made: ${{ steps.auto-fix-completed.outputs.commit_made || steps.no-changes.outputs.commit_made }} |
14 | 64 | steps: |
15 | | - - uses: actions/checkout@v4 # v4.1.7 |
| 65 | + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 |
| 66 | + with: |
| 67 | + persist-credentials: true |
| 68 | + ref: ${{ github.head_ref || github.ref_name }} |
| 69 | + |
| 70 | + - name: Setup Environment |
| 71 | + id: setup |
| 72 | + uses: ./.github/actions/setup-cre |
| 73 | + with: |
| 74 | + install-buf: 'true' |
| 75 | + install-go-tools: 'true' |
16 | 76 |
|
17 | | - - name: Install buf CLI (v1.45.0, SHA bee67191e0a207d52b6c7f0ac9d3d1210898d2f9) |
| 77 | + - name: Auto-fix & regenerate |
| 78 | + if: steps.setup.outputs.cre_changed == 'true' |
18 | 79 | run: | |
19 | | - if ! command -v buf >/dev/null; then |
20 | | - echo "Installing buf CLI v1.45.0..." |
21 | | - curl -sSL https://github.com/bufbuild/buf/releases/download/v1.45.0/buf-$(uname -s)-$(uname -m) -o /usr/local/bin/buf |
22 | | - chmod +x /usr/local/bin/buf |
23 | | - else |
24 | | - echo "buf CLI already available." |
25 | | - fi |
| 80 | + buf format -w cre |
| 81 | + gofmt -w cre |
| 82 | + |
| 83 | + cd cre/go |
| 84 | + go generate ./... |
| 85 | + go mod tidy |
| 86 | + cd - |
| 87 | + cd cre/verify |
| 88 | + go generate ./... |
| 89 | + go mod tidy |
| 90 | +
|
26 | 91 |
|
27 | | - - name: Check if cre/ files were modified |
28 | | - id: changes |
| 92 | + - name: Detect regen changes |
| 93 | + if: steps.setup.outputs.cre_changed == 'true' |
| 94 | + id: detect-regen |
29 | 95 | run: | |
30 | | - if git diff --name-only origin/main...HEAD | grep '^cre/'; then |
31 | | - echo "cre_changed=true" >> $GITHUB_OUTPUT |
| 96 | + if [[ -n "$(git status --porcelain)" ]]; then |
| 97 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
32 | 98 | else |
33 | | - echo "cre_changed=false" >> $GITHUB_OUTPUT |
| 99 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
34 | 100 | fi |
35 | 101 |
|
36 | | - - name: Set tool versions |
37 | | - if: steps.changes.outputs.cre_changed == 'true' |
38 | | - id: tool-versions |
39 | | - uses: smartcontractkit/tool-versions-to-env-action@v1.0.8 |
40 | | - |
41 | | - - name: Run buf lint for cre |
42 | | - if: steps.changes.outputs.cre_changed == 'true' |
43 | | - run: buf lint cre |
| 102 | + - name: Commit auto-fix changes |
| 103 | + if: steps.setup.outputs.cre_changed == 'true' && steps.detect-regen.outputs.changed == 'true' |
| 104 | + run: | |
| 105 | + git config --local user.email "action@github.com" |
| 106 | + git config --local user.name "GitHub Action" |
| 107 | + git add . |
| 108 | + git commit -m "Auto-fix: buf format, gofmt, go generate, go mod tidy [skip ci]" |
| 109 | + git push |
44 | 110 |
|
45 | | - - name: Run buf breaking for cre |
46 | | - if: steps.changes.outputs.cre_changed == 'true' |
47 | | - run: buf breaking cre --against ".git#branch=main,subdir=cre" --exclude-path node_modules |
| 111 | + - name: Auto-fix completed |
| 112 | + if: steps.setup.outputs.cre_changed == 'true' && steps.detect-regen.outputs.changed == 'true' |
| 113 | + id: auto-fix-completed |
| 114 | + run: | |
| 115 | + echo "commit_made=true" >> "$GITHUB_OUTPUT" |
| 116 | + echo "::notice::Auto-fix changes have been committed. The new commit will trigger a fresh workflow run with the fixes applied." |
| 117 | + exit 1 |
48 | 118 |
|
49 | | - - name: Skip buf checks — no cre/ changes |
50 | | - if: steps.changes.outputs.cre_changed == 'false' |
51 | | - run: echo "No changes to cre/ — skipping buf lint and breaking checks." |
| 119 | + - name: No changes needed |
| 120 | + if: steps.setup.outputs.cre_changed == 'false' || steps.detect-regen.outputs.changed == 'false' |
| 121 | + id: no-changes |
| 122 | + run: | |
| 123 | + echo "commit_made=false" >> "$GITHUB_OUTPUT" |
| 124 | + if [[ "${{ steps.setup.outputs.cre_changed }}" == "false" ]]; then |
| 125 | + echo "::notice::No CRE files were modified, skipping auto-fix." |
| 126 | + else |
| 127 | + echo "::notice::No formatting or generation changes needed." |
| 128 | + fi |
52 | 129 |
|
| 130 | + buf-cre: |
| 131 | + needs: [cre-tests, fix-cre] |
| 132 | + if: always() |
| 133 | + runs-on: ubuntu-latest |
| 134 | + steps: |
| 135 | + - name: Check results |
| 136 | + run: | |
| 137 | + echo "cre-tests result: ${{ needs.cre-tests.result }}" |
| 138 | + echo "fix-cre commit made: ${{ needs.fix-cre.outputs.commit_made }}" |
| 139 | + |
| 140 | + if [[ "${{ needs.cre-tests.result }}" == "success" ]]; then |
| 141 | + echo "::notice::✅ All CRE tests passed successfully" |
| 142 | + exit 0 |
| 143 | + elif [[ "${{ needs.fix-cre.outputs.commit_made }}" == "true" ]]; then |
| 144 | + echo "::notice::🔧 Auto-fix commit was made - workflow will re-run automatically with fixes applied" |
| 145 | + exit 1 |
| 146 | + else |
| 147 | + echo "::error::❌ CRE tests failed and no automatic fix is available" |
| 148 | + exit 1 |
| 149 | + fi |
0 commit comments