|
| 1 | +name: "Check transpiled concepts are up to date" |
| 2 | +description: >- |
| 3 | + Compares the working tree against what is committed for the transpiled dialect |
| 4 | + folders. If they differ, the committed concepts_postgres / concepts_duckdb |
| 5 | + are stale relative to the BigQuery sources, and this action reports a NEUTRAL |
| 6 | + (yellow) check. |
| 7 | +
|
| 8 | + The calling job must grant `checks: write` (and `contents: read`) permissions. |
| 9 | +
|
| 10 | +inputs: |
| 11 | + github-token: |
| 12 | + description: "Token used to create the neutral check run." |
| 13 | + required: true |
| 14 | + check-name: |
| 15 | + description: "Name shown for the neutral check run." |
| 16 | + required: false |
| 17 | + default: "Dialects up to date with BigQuery" |
| 18 | + paths: |
| 19 | + description: "Space-separated paths to compare against the committed tree." |
| 20 | + required: false |
| 21 | + default: "mimic-iv/concepts_postgres mimic-iv/concepts_duckdb" |
| 22 | + |
| 23 | +runs: |
| 24 | + using: "composite" |
| 25 | + steps: |
| 26 | + - name: Detect drift from committed concepts |
| 27 | + id: drift |
| 28 | + shell: bash |
| 29 | + run: | |
| 30 | + changes="$(git status --porcelain -- ${{ inputs.paths }})" |
| 31 | + if [ -z "$changes" ]; then |
| 32 | + echo "Committed dialect concepts match the BigQuery sources." |
| 33 | + echo "out_of_date=false" >> "$GITHUB_OUTPUT" |
| 34 | + exit 0 |
| 35 | + fi |
| 36 | +
|
| 37 | + echo "out_of_date=true" >> "$GITHUB_OUTPUT" |
| 38 | +
|
| 39 | + # Persist the file list and diff for the check run + job summary. |
| 40 | + printf '%s\n' "$changes" > concept-drift-files.txt |
| 41 | + git --no-pager diff -- ${{ inputs.paths }} > concept-drift.diff |
| 42 | +
|
| 43 | + { |
| 44 | + echo "### :warning: Transpiled concepts are out of date" |
| 45 | + echo |
| 46 | + echo "The committed \`concepts_postgres\` / \`concepts_duckdb\` differ from" |
| 47 | + echo "what the transpiler produces from the BigQuery sources. Regenerate with:" |
| 48 | + echo |
| 49 | + echo '```sh' |
| 50 | + echo "mimic_utils convert_folder mimic-iv/concepts mimic-iv/concepts_postgres --destination_dialect postgres" |
| 51 | + echo "mimic_utils convert_folder mimic-iv/concepts mimic-iv/concepts_duckdb --destination_dialect duckdb" |
| 52 | + echo '```' |
| 53 | + echo |
| 54 | + echo "…and commit the result, or let the regeneration bot open a PR after this merges." |
| 55 | + echo |
| 56 | + echo "<details><summary>Files that differ</summary>" |
| 57 | + echo |
| 58 | + echo '```' |
| 59 | + cat concept-drift-files.txt |
| 60 | + echo '```' |
| 61 | + echo |
| 62 | + echo "</details>" |
| 63 | + } >> "$GITHUB_STEP_SUMMARY" |
| 64 | +
|
| 65 | + - name: Report neutral check run when out of date |
| 66 | + if: steps.drift.outputs.out_of_date == 'true' |
| 67 | + uses: actions/github-script@v7 |
| 68 | + with: |
| 69 | + github-token: ${{ inputs.github-token }} |
| 70 | + script: | |
| 71 | + const fs = require('fs'); |
| 72 | + const read = (p) => fs.existsSync(p) ? fs.readFileSync(p, 'utf8') : ''; |
| 73 | + const files = read('concept-drift-files.txt').trim(); |
| 74 | + let diff = read('concept-drift.diff'); |
| 75 | +
|
| 76 | + // Check run output text is capped at 65535 chars; keep well under it. |
| 77 | + const LIMIT = 60000; |
| 78 | + if (diff.length > LIMIT) { |
| 79 | + diff = diff.slice(0, LIMIT) + '\n... (diff truncated) ...\n'; |
| 80 | + } |
| 81 | +
|
| 82 | + const headSha = context.payload.pull_request |
| 83 | + ? context.payload.pull_request.head.sha |
| 84 | + : context.sha; |
| 85 | +
|
| 86 | + const summary = [ |
| 87 | + 'The committed `concepts_postgres` / `concepts_duckdb` are stale relative to', |
| 88 | + 'the BigQuery sources. Regenerate them with the two `mimic_utils convert_folder`', |
| 89 | + 'commands and commit the result, or let the regeneration bot open a PR after', |
| 90 | + 'this branch merges.', |
| 91 | + '', |
| 92 | + '### Files that differ', |
| 93 | + '```', |
| 94 | + files, |
| 95 | + '```', |
| 96 | + ].join('\n'); |
| 97 | +
|
| 98 | + try { |
| 99 | + await github.rest.checks.create({ |
| 100 | + owner: context.repo.owner, |
| 101 | + repo: context.repo.repo, |
| 102 | + name: '${{ inputs.check-name }}', |
| 103 | + head_sha: headSha, |
| 104 | + status: 'completed', |
| 105 | + conclusion: 'neutral', |
| 106 | + output: { |
| 107 | + title: 'Transpiled concepts are out of date', |
| 108 | + summary, |
| 109 | + text: diff ? ['```diff', diff, '```'].join('\n') : undefined, |
| 110 | + }, |
| 111 | + }); |
| 112 | + } catch (error) { |
| 113 | + // The default GITHUB_TOKEN is read-only for pull requests from forks, |
| 114 | + // so it cannot create a check run. Fall back to a warning annotation |
| 115 | + // rather than failing the job red. |
| 116 | + core.warning( |
| 117 | + 'Transpiled concepts are out of date with the BigQuery sources; ' + |
| 118 | + 'could not post a neutral check run (' + error.message + '). ' + |
| 119 | + 'Regenerate the concepts_postgres / concepts_duckdb folders and commit them.' |
| 120 | + ); |
| 121 | + } |
0 commit comments