Skip to content

Commit 6a8a5ed

Browse files
Publish jsonschema_for_docs.json to docgen branch instead of main
main remains untouched. The workflow regenerates the schema in a main checkout (full history + tags so since_version.go can stamp), copies the result into a worktree on the docgen branch, and pushes there. workflow_dispatch no longer takes a tag input; it picks up the most recent v* tag automatically. Co-authored-by: Isaac
1 parent d45dc9a commit 6a8a5ed

1 file changed

Lines changed: 43 additions & 33 deletions

File tree

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
name: update-schema-docs
22

3-
# Regenerate bundle/schema/jsonschema_for_docs.json after every release.
3+
# Regenerate bundle/schema/jsonschema_for_docs.json after every release and
4+
# publish it to the `docgen` branch.
45
#
5-
# bundle/internal/schema/since_version.go computes `x-since-version` annotations
6+
# bundle/internal/schema/since_version.go derives `x-since-version` annotations
67
# 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`.
8+
# `docgen` branch is therefore stale by one release as soon as the next tag is
9+
# pushed; this workflow keeps it current.
1310

1411
on:
1512
push:
1613
tags:
1714
- "v*"
1815

1916
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
2417

2518
permissions:
2619
contents: write
@@ -35,10 +28,9 @@ jobs:
3528
- name: Checkout main
3629
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
3730
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.
31+
# Regen runs against `main`. fetch-depth: 0 + fetch-tags: true ensure
32+
# since_version.go can resolve `git show <tag>:bundle/schema/jsonschema.json`
33+
# for every historical release.
4234
ref: main
4335
fetch-depth: 0
4436
fetch-tags: true
@@ -55,49 +47,67 @@ jobs:
5547
id: tag
5648
env:
5749
GITHUB_REF: ${{ github.ref }}
58-
INPUT_TAG: ${{ inputs.tag }}
5950
run: |
6051
if [ "${{ github.event_name }}" = "push" ]; then
6152
tag="${GITHUB_REF#refs/tags/}"
6253
else
63-
tag="${INPUT_TAG:-manual}"
54+
tag=$(git tag --list 'v*' --sort=-version:refname | head -n 1)
55+
fi
56+
if [ -z "$tag" ]; then
57+
echo "Could not determine a v* tag to publish for." >&2
58+
exit 1
6459
fi
6560
echo "tag=$tag" >> "$GITHUB_OUTPUT"
61+
echo "Publishing for tag $tag"
6662
6763
- name: Regenerate jsonschema_for_docs.json
6864
run: go tool -modfile=tools/task/go.mod task --force generate-schema-docs
6965

70-
- name: Show diff
71-
run: git diff -- bundle/schema/jsonschema_for_docs.json
72-
7366
# Fail loudly if regeneration touches anything other than the docs schema.
7467
# 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
68+
# generator, not something we want to silently publish.
69+
- name: Assert only jsonschema_for_docs.json changed on main
7870
run: |
7971
changed=$(git status --porcelain)
72+
expected=" M bundle/schema/jsonschema_for_docs.json"
8073
if [ -z "$changed" ]; then
81-
echo "No changes; skipping commit."
82-
echo "skip=true" >> "$GITHUB_OUTPUT"
74+
echo "Regeneration produced no diff against main."
8375
exit 0
8476
fi
85-
expected=" M bundle/schema/jsonschema_for_docs.json"
8677
if [ "$changed" != "$expected" ]; then
8778
echo "Expected only bundle/schema/jsonschema_for_docs.json to be modified."
8879
echo "Actual git status --porcelain:"
8980
echo "$changed"
9081
exit 1
9182
fi
92-
echo "skip=false" >> "$GITHUB_OUTPUT"
9383
94-
- name: Commit and push to main
95-
if: steps.check.outputs.skip != 'true'
84+
- name: Capture regenerated file
85+
run: |
86+
mkdir -p "$RUNNER_TEMP/regen"
87+
cp bundle/schema/jsonschema_for_docs.json "$RUNNER_TEMP/regen/jsonschema_for_docs.json"
88+
89+
- name: Check out docgen worktree
90+
run: |
91+
git fetch origin docgen
92+
git worktree add "$RUNNER_TEMP/docgen" origin/docgen
93+
94+
- name: Stage regenerated file on docgen
95+
working-directory: ${{ runner.temp }}/docgen
96+
run: |
97+
mkdir -p bundle/schema
98+
cp "$RUNNER_TEMP/regen/jsonschema_for_docs.json" bundle/schema/jsonschema_for_docs.json
99+
git add bundle/schema/jsonschema_for_docs.json
100+
101+
- name: Commit and push to docgen
102+
working-directory: ${{ runner.temp }}/docgen
96103
env:
97104
TAG: ${{ steps.tag.outputs.tag }}
98105
run: |
106+
if git diff --cached --quiet; then
107+
echo "docgen already up to date for ${TAG}; nothing to commit."
108+
exit 0
109+
fi
99110
git config user.name "github-actions[bot]"
100111
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
112+
git commit -m "Update jsonschema_for_docs.json for ${TAG}"
113+
git push origin HEAD:docgen

0 commit comments

Comments
 (0)