Skip to content

Commit 49612ee

Browse files
committed
feat(ci): add ref and publish inputs to docs-build dispatch
Let maintainers publish or preview docs for any tagged/branched commit without waiting for a push to an allowlisted branch. Dispatch now takes: - `branch` (choice): Allowlisted branch to publish under. Drives the site path (`/docs/<branch>/`) and the aggregator dispatch target. - `ref` (string, optional): Branch, tag, or commit SHA to build. Empty falls back to the branch tip. Resolved to a concrete SHA up front via `gh api repos/{owner}/{repo}/commits/{ref}`, so `metadata.json` and the aggregator payload always reference the commit that was built. - `publish` (boolean, default true): When false, `html-docs` and `spec-docs` still run and upload their per-job artifacts, but `combine` and `trigger-aggregator` are skipped. Use for dry-run / artifact inspection without deploying. `html-docs` and `spec-docs` now check out the resolved SHA rather than the branch name, which lines up the build jobs with the SHA recorded in metadata and dispatched to steel-website.
1 parent 2d76409 commit 49612ee

1 file changed

Lines changed: 45 additions & 15 deletions

File tree

.github/workflows/docs-build.yaml

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,22 @@ on:
4141
workflow_dispatch:
4242
inputs:
4343
branch:
44-
description: "Branch to build (must be allowlisted)"
44+
description: "Allowlisted branch to publish under"
45+
required: true
46+
type: choice
47+
options:
48+
- forks/amsterdam
49+
default: forks/amsterdam
50+
ref:
51+
description: "Ref to build (branch, tag, or commit SHA). Empty = branch tip."
4552
required: false
4653
type: string
54+
default: ""
55+
publish:
56+
description: "Upload combined artifact and trigger the steel-website aggregator"
57+
required: true
58+
type: boolean
59+
default: true
4760

4861
concurrency:
4962
group: docs-build-${{ github.ref }}
@@ -94,17 +107,25 @@ jobs:
94107
id: check
95108
env:
96109
BRANCH_INPUT: ${{ github.event.inputs.branch || github.ref_name }}
110+
REF_INPUT: ${{ github.event.inputs.ref }}
111+
PUBLISH_INPUT: ${{ github.event.inputs.publish }}
97112
EVENT_NAME: ${{ github.event_name }}
113+
GH_TOKEN: ${{ github.token }}
98114
run: |
99115
echo "branch=$BRANCH_INPUT" >> "$GITHUB_OUTPUT"
100116
101117
# Create artifact-safe name (replace / with -)
102118
BRANCH_ARTIFACT_NAME="${BRANCH_INPUT//\//-}"
103119
echo "branch_artifact_name=$BRANCH_ARTIFACT_NAME" >> "$GITHUB_OUTPUT"
104120
105-
# Deploy on push and workflow_dispatch, not on PRs
121+
# Deploy on push, or workflow_dispatch with publish=true. PRs never
122+
# publish. A dispatch with publish=false still builds html-docs and
123+
# spec-docs (uploaded as per-job artifacts) but skips combine and
124+
# the aggregator trigger.
106125
IS_DEPLOY="false"
107-
if [ "$EVENT_NAME" = "push" ] || [ "$EVENT_NAME" = "workflow_dispatch" ]; then
126+
if [ "$EVENT_NAME" = "push" ]; then
127+
IS_DEPLOY="true"
128+
elif [ "$EVENT_NAME" = "workflow_dispatch" ] && [ "$PUBLISH_INPUT" = "true" ]; then
108129
IS_DEPLOY="true"
109130
fi
110131
echo "is_deploy=$IS_DEPLOY" >> "$GITHUB_OUTPUT"
@@ -125,17 +146,18 @@ jobs:
125146
fi
126147
echo "should_publish=$SHOULD_PUBLISH" >> "$GITHUB_OUTPUT"
127148
128-
# Resolve tip commit SHA of the target branch. For push events this
129-
# matches github.sha, but for workflow_dispatch github.sha points at
130-
# the launch ref (typically the default branch), not the branch that
131-
# html-docs/spec-docs actually check out. Resolving here ensures
132-
# metadata.json and the steel-website dispatch payload always
133-
# reference the commit that was built.
134-
if [ "$IS_DEPLOY" = "true" ] && [ "$SHOULD_PUBLISH" = "true" ]; then
135-
COMMIT_SHA=$(git ls-remote "https://github.com/${GITHUB_REPOSITORY}.git" \
136-
"refs/heads/${BRANCH_INPUT}" | awk '{print $1}')
149+
# Resolve the ref we will actually check out and build. On dispatch,
150+
# the user can specify any branch/tag/SHA; empty falls back to the
151+
# target branch tip. For push, we always build the pushed ref.
152+
# Resolving to a concrete SHA here keeps metadata.json and the
153+
# aggregator dispatch payload consistent with what the build jobs
154+
# check out, even when github.sha points at a different ref (which
155+
# happens for workflow_dispatch launched from the default branch).
156+
if [ "$EVENT_NAME" != "pull_request" ] && [ "$SHOULD_PUBLISH" = "true" ]; then
157+
RESOLVE_REF="${REF_INPUT:-$BRANCH_INPUT}"
158+
COMMIT_SHA=$(gh api "repos/${GITHUB_REPOSITORY}/commits/${RESOLVE_REF}" --jq .sha 2>/dev/null || true)
137159
if [ -z "$COMMIT_SHA" ]; then
138-
echo "ERROR: could not resolve commit SHA for branch '${BRANCH_INPUT}'"
160+
echo "ERROR: could not resolve commit SHA for ref '${RESOLVE_REF}'"
139161
exit 1
140162
fi
141163
echo "commit_sha=$COMMIT_SHA" >> "$GITHUB_OUTPUT"
@@ -148,13 +170,21 @@ jobs:
148170
echo "| Setting | Value |"
149171
echo "|---------|-------|"
150172
echo "| **Branch** | \`$BRANCH_INPUT\` |"
173+
if [ -n "$REF_INPUT" ]; then
174+
echo "| **Ref** | \`$REF_INPUT\` |"
175+
fi
176+
if [ -n "${COMMIT_SHA:-}" ]; then
177+
echo "| **Resolved SHA** | \`${COMMIT_SHA:0:7}\` |"
178+
fi
151179
echo "| **Event** | \`$EVENT_NAME\` |"
152180
echo "| **Deploy build** | $IS_DEPLOY |"
153181
echo "| **Allowlisted** | $SHOULD_PUBLISH |"
154182
echo ""
155183
156184
if [ "$EVENT_NAME" = "pull_request" ]; then
157185
echo "-> **Build only** -- pull request; artifacts are not published."
186+
elif [ "$EVENT_NAME" = "workflow_dispatch" ] && [ "$PUBLISH_INPUT" != "true" ]; then
187+
echo "-> **Build only** -- \`publish\` input is false; \`html-docs\` and \`spec-docs\` artifacts are uploaded but not combined or dispatched."
158188
elif [ "$SHOULD_PUBLISH" = "true" ]; then
159189
echo "-> **Will publish** -- branch is allowlisted; artifacts will be built, combined, and uploaded."
160190
else
@@ -177,7 +207,7 @@ jobs:
177207
steps:
178208
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
179209
with:
180-
ref: ${{ github.event_name == 'workflow_dispatch' && needs.check-should-publish.outputs.branch || '' }}
210+
ref: ${{ github.event_name == 'workflow_dispatch' && needs.check-should-publish.outputs.commit_sha || '' }}
181211
fetch-depth: 0
182212
submodules: recursive
183213

@@ -215,7 +245,7 @@ jobs:
215245
steps:
216246
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
217247
with:
218-
ref: ${{ github.event_name == 'workflow_dispatch' && needs.check-should-publish.outputs.branch || '' }}
248+
ref: ${{ github.event_name == 'workflow_dispatch' && needs.check-should-publish.outputs.commit_sha || '' }}
219249
fetch-depth: 0
220250
submodules: recursive
221251

0 commit comments

Comments
 (0)