|
| 1 | +name: update-schema-docs |
| 2 | + |
| 3 | +# Regenerate bundle/schema/jsonschema_for_docs.json after every release. |
| 4 | +# |
| 5 | +# bundle/internal/schema/since_version.go computes `x-since-version` annotations |
| 6 | +# from the list of `v*` git tags that exist when the schema is generated. The |
| 7 | +# committed file is therefore stale by one release as soon as the next tag is |
| 8 | +# pushed: fields shipped in that tag don't get stamped until the file is |
| 9 | +# regenerated against a tag list that includes it. |
| 10 | +# |
| 11 | +# This workflow runs on every `v*` tag push, regenerates the file from `main`, |
| 12 | +# and pushes the updated file directly to `main`. |
| 13 | + |
| 14 | +on: |
| 15 | + push: |
| 16 | + tags: |
| 17 | + - "v*" |
| 18 | + |
| 19 | + workflow_dispatch: |
| 20 | + inputs: |
| 21 | + tag: |
| 22 | + description: "Release tag this run is updating annotations for (e.g. v0.299.0). Used in the commit message only." |
| 23 | + required: false |
| 24 | + |
| 25 | +permissions: |
| 26 | + contents: write |
| 27 | + |
| 28 | +jobs: |
| 29 | + update-schema-docs: |
| 30 | + runs-on: |
| 31 | + group: databricks-protected-runner-group-large |
| 32 | + labels: linux-ubuntu-latest-large |
| 33 | + |
| 34 | + steps: |
| 35 | + - name: Checkout main |
| 36 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 37 | + with: |
| 38 | + # The commit lands on main, not the tagged commit, so check main out |
| 39 | + # directly. fetch-depth: 0 + fetch-tags: true ensure since_version.go |
| 40 | + # can resolve `git show <tag>:bundle/schema/jsonschema.json` for every |
| 41 | + # historical release. |
| 42 | + ref: main |
| 43 | + fetch-depth: 0 |
| 44 | + fetch-tags: true |
| 45 | + |
| 46 | + - name: Setup Go |
| 47 | + uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 |
| 48 | + with: |
| 49 | + go-version-file: go.mod |
| 50 | + cache-dependency-path: | |
| 51 | + go.sum |
| 52 | + bundle/internal/schema/*.* |
| 53 | +
|
| 54 | + - name: Determine release tag |
| 55 | + id: tag |
| 56 | + env: |
| 57 | + GITHUB_REF: ${{ github.ref }} |
| 58 | + INPUT_TAG: ${{ inputs.tag }} |
| 59 | + run: | |
| 60 | + if [ "${{ github.event_name }}" = "push" ]; then |
| 61 | + tag="${GITHUB_REF#refs/tags/}" |
| 62 | + else |
| 63 | + tag="${INPUT_TAG:-manual}" |
| 64 | + fi |
| 65 | + echo "tag=$tag" >> "$GITHUB_OUTPUT" |
| 66 | +
|
| 67 | + - name: Regenerate jsonschema_for_docs.json |
| 68 | + run: go tool -modfile=tools/task/go.mod task --force generate-schema-docs |
| 69 | + |
| 70 | + - name: Show diff |
| 71 | + run: git diff -- bundle/schema/jsonschema_for_docs.json |
| 72 | + |
| 73 | + # Fail loudly if regeneration touches anything other than the docs schema. |
| 74 | + # Anything else (annotations.yml, untracked files, ...) is a bug in the |
| 75 | + # generator, not something we want to silently push to main. |
| 76 | + - name: Assert only jsonschema_for_docs.json changed |
| 77 | + id: check |
| 78 | + run: | |
| 79 | + changed=$(git status --porcelain) |
| 80 | + if [ -z "$changed" ]; then |
| 81 | + echo "No changes; skipping commit." |
| 82 | + echo "skip=true" >> "$GITHUB_OUTPUT" |
| 83 | + exit 0 |
| 84 | + fi |
| 85 | + expected=" M bundle/schema/jsonschema_for_docs.json" |
| 86 | + if [ "$changed" != "$expected" ]; then |
| 87 | + echo "Expected only bundle/schema/jsonschema_for_docs.json to be modified." |
| 88 | + echo "Actual git status --porcelain:" |
| 89 | + echo "$changed" |
| 90 | + exit 1 |
| 91 | + fi |
| 92 | + echo "skip=false" >> "$GITHUB_OUTPUT" |
| 93 | +
|
| 94 | + - name: Commit and push to main |
| 95 | + if: steps.check.outputs.skip != 'true' |
| 96 | + env: |
| 97 | + TAG: ${{ steps.tag.outputs.tag }} |
| 98 | + run: | |
| 99 | + git config user.name "github-actions[bot]" |
| 100 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 101 | + git add bundle/schema/jsonschema_for_docs.json |
| 102 | + git commit -m "Update jsonschema_for_docs.json since-versions for ${TAG}" |
| 103 | + git push origin HEAD:main |
0 commit comments