|
| 1 | +name: Template Compatibility |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + |
| 7 | +# This job is informational — it is intentionally NOT a required status check |
| 8 | +# so that breaking SDK changes (major version bumps) can still be merged. |
| 9 | +# When templates break, a comment is posted on the PR with details. |
| 10 | +# For intentional breaking changes, create a matching branch in cre-templates |
| 11 | +# named compat/<your-sdk-branch-name> with the template fixes applied. |
| 12 | +# The job will automatically detect and test against that branch. |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + pull-requests: write |
| 17 | + |
| 18 | +jobs: |
| 19 | + template-compatibility: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + # Only run on PRs (not push to main) |
| 22 | + if: github.event_name == 'pull_request' |
| 23 | + |
| 24 | + defaults: |
| 25 | + run: |
| 26 | + shell: bash {0} |
| 27 | + |
| 28 | + env: |
| 29 | + TEMPLATES_REPO: smartcontractkit/cre-templates |
| 30 | + # Convention: a matching branch in cre-templates named compat/<sdk-branch> |
| 31 | + # allows coordinated breaking changes without blocking the SDK PR. |
| 32 | + COMPAT_BRANCH: compat/${{ github.head_ref }} |
| 33 | + |
| 34 | + steps: |
| 35 | + - name: Checkout SDK |
| 36 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 37 | + with: |
| 38 | + submodules: recursive |
| 39 | + |
| 40 | + - name: Setup Rust (1.85.0) with wasm target |
| 41 | + uses: actions-rust-lang/setup-rust-toolchain@150fca883cd4034361b621bd4e6a9d34e5143606 # v1.15.4 |
| 42 | + with: |
| 43 | + toolchain: 1.85.0 |
| 44 | + target: wasm32-wasip1 |
| 45 | + override: true |
| 46 | + |
| 47 | + - name: Setup Bun |
| 48 | + uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0 |
| 49 | + with: |
| 50 | + bun-version: 1.3.12 |
| 51 | + |
| 52 | + - name: Cache Bun dependencies |
| 53 | + uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4 |
| 54 | + with: |
| 55 | + path: ~/.bun/install/cache |
| 56 | + key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }} |
| 57 | + |
| 58 | + - name: Cache cargo + Javy |
| 59 | + uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4 |
| 60 | + with: |
| 61 | + path: | |
| 62 | + ~/.cargo/registry |
| 63 | + ~/.cargo/git |
| 64 | + ~/.cache/javy |
| 65 | + key: ${{ runner.os }}-cre-plugin-v8.1.0-${{ hashFiles('packages/cre-sdk-javy-plugin/src/javy_chainlink_sdk/Cargo.lock', 'packages/cre-sdk-javy-plugin/src/cre_generated_host.Cargo.lock') }} |
| 66 | + |
| 67 | + - name: Install SDK dependencies |
| 68 | + run: bun install --frozen-lockfile |
| 69 | + |
| 70 | + # Detect whether a matching compat branch exists in cre-templates. |
| 71 | + # If it does, we test against it (coordinated breaking change). |
| 72 | + # If not, we fall back to main. |
| 73 | + - name: Detect cre-templates ref to test against |
| 74 | + id: detect-ref |
| 75 | + env: |
| 76 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 77 | + run: | |
| 78 | + if gh api "repos/$TEMPLATES_REPO/branches/$COMPAT_BRANCH" &>/dev/null; then |
| 79 | + echo "ref=$COMPAT_BRANCH" >> "$GITHUB_OUTPUT" |
| 80 | + echo "Using compat branch: $COMPAT_BRANCH" |
| 81 | + else |
| 82 | + echo "ref=main" >> "$GITHUB_OUTPUT" |
| 83 | + echo "No compat branch found, using: main" |
| 84 | + fi |
| 85 | +
|
| 86 | + - name: Checkout cre-templates (${{ steps.detect-ref.outputs.ref }}) |
| 87 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 88 | + with: |
| 89 | + repository: ${{ env.TEMPLATES_REPO }} |
| 90 | + ref: ${{ steps.detect-ref.outputs.ref }} |
| 91 | + path: cre-templates |
| 92 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 93 | + |
| 94 | + - name: Setup Node (for npm) |
| 95 | + uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 |
| 96 | + with: |
| 97 | + node-version: '22' |
| 98 | + |
| 99 | + - name: Run template compatibility check |
| 100 | + id: template-check |
| 101 | + env: |
| 102 | + TEMPLATES_DIR: cre-templates |
| 103 | + run: | |
| 104 | + set +e |
| 105 | + OUTPUT=$(./scripts/test-templates.sh 2>&1) |
| 106 | + EXIT_CODE=$? |
| 107 | + set -e |
| 108 | +
|
| 109 | + # Save output to a file for the comment step |
| 110 | + echo "$OUTPUT" > /tmp/template-check-output.txt |
| 111 | +
|
| 112 | + # Surface it in the action log regardless |
| 113 | + echo "$OUTPUT" |
| 114 | +
|
| 115 | + echo "exit_code=$EXIT_CODE" >> "$GITHUB_OUTPUT" |
| 116 | +
|
| 117 | + # Only post a comment when templates are broken. |
| 118 | + # The comment is updated (not duplicated) on subsequent pushes. |
| 119 | + - name: Post failure comment on PR |
| 120 | + if: steps.template-check.outputs.exit_code != '0' |
| 121 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 122 | + with: |
| 123 | + script: | |
| 124 | + const fs = require('fs'); |
| 125 | + const fullOutput = fs.readFileSync('/tmp/template-check-output.txt', 'utf8'); |
| 126 | +
|
| 127 | + // Extract just the "Results" and "Failure Details" sections |
| 128 | + const resultsMatch = fullOutput.match(/={8,}\nResults:.*\n={8,}[\s\S]*/); |
| 129 | + const failureSummary = resultsMatch ? resultsMatch[0].trim() : fullOutput.trim(); |
| 130 | +
|
| 131 | + const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; |
| 132 | + const templatesRef = '${{ steps.detect-ref.outputs.ref }}'; |
| 133 | + const refNote = templatesRef === 'main' |
| 134 | + ? 'tested against `cre-templates:main`' |
| 135 | + : `tested against \`cre-templates:${templatesRef}\` (compat branch)`; |
| 136 | +
|
| 137 | + const body = [ |
| 138 | + '## ⚠️ Template Compatibility Failures', |
| 139 | + '', |
| 140 | + `This PR breaks one or more templates in [cre-templates](https://github.com/${{ env.TEMPLATES_REPO }}) (${refNote}).`, |
| 141 | + '', |
| 142 | + '```', |
| 143 | + failureSummary, |
| 144 | + '```', |
| 145 | + '', |
| 146 | + `[View full output →](${runUrl})`, |
| 147 | + '', |
| 148 | + '<details>', |
| 149 | + '<summary>What should I do?</summary>', |
| 150 | + '', |
| 151 | + '- **Accidental break:** Fix the SDK change so existing templates continue to compile.', |
| 152 | + '- **Intentional breaking change:** Create a branch in `cre-templates` named `compat/${{ github.head_ref }}` with the template fixes applied. This job will automatically retest against that branch.', |
| 153 | + '', |
| 154 | + '</details>', |
| 155 | + ].join('\n'); |
| 156 | +
|
| 157 | + const marker = '<!-- template-compat-comment -->'; |
| 158 | + const commentBody = `${marker}\n${body}`; |
| 159 | +
|
| 160 | + // Update existing comment if present, otherwise create a new one |
| 161 | + const { data: comments } = await github.rest.issues.listComments({ |
| 162 | + owner: context.repo.owner, |
| 163 | + repo: context.repo.repo, |
| 164 | + issue_number: context.issue.number, |
| 165 | + }); |
| 166 | +
|
| 167 | + const existing = comments.find(c => c.body.includes(marker)); |
| 168 | + if (existing) { |
| 169 | + await github.rest.issues.updateComment({ |
| 170 | + owner: context.repo.owner, |
| 171 | + repo: context.repo.repo, |
| 172 | + comment_id: existing.id, |
| 173 | + body: commentBody, |
| 174 | + }); |
| 175 | + } else { |
| 176 | + await github.rest.issues.createComment({ |
| 177 | + owner: context.repo.owner, |
| 178 | + repo: context.repo.repo, |
| 179 | + issue_number: context.issue.number, |
| 180 | + body: commentBody, |
| 181 | + }); |
| 182 | + } |
| 183 | +
|
| 184 | + # If a prior push had failures but this push fixes them, remove the stale comment |
| 185 | + - name: Remove stale failure comment (if now passing) |
| 186 | + if: steps.template-check.outputs.exit_code == '0' |
| 187 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 188 | + with: |
| 189 | + script: | |
| 190 | + const marker = '<!-- template-compat-comment -->'; |
| 191 | + const { data: comments } = await github.rest.issues.listComments({ |
| 192 | + owner: context.repo.owner, |
| 193 | + repo: context.repo.repo, |
| 194 | + issue_number: context.issue.number, |
| 195 | + }); |
| 196 | +
|
| 197 | + const existing = comments.find(c => c.body.includes(marker)); |
| 198 | + if (existing) { |
| 199 | + await github.rest.issues.deleteComment({ |
| 200 | + owner: context.repo.owner, |
| 201 | + repo: context.repo.repo, |
| 202 | + comment_id: existing.id, |
| 203 | + }); |
| 204 | + } |
| 205 | +
|
| 206 | + # Always exit 0 — this job is informational, not a merge gate |
| 207 | + - name: Report result (non-blocking) |
| 208 | + if: always() |
| 209 | + run: | |
| 210 | + EXIT_CODE="${{ steps.template-check.outputs.exit_code }}" |
| 211 | + if [ "$EXIT_CODE" = "0" ]; then |
| 212 | + echo "✅ All templates are compatible with this SDK change." |
| 213 | + else |
| 214 | + echo "⚠️ Some templates failed — see PR comment for details." |
| 215 | + echo "This check is informational and does not block merging." |
| 216 | + fi |
| 217 | + exit 0 |
0 commit comments