Repository navigation
152 lines (139 loc) · 6.34 KB
/
Copy pathbump-upstream-docs.yml
File metadata and controls
152 lines (139 loc) · 6.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: Bump upstream docs pin
# Moves the objectstack pin, `.objectstack-sha`, and opens a pull request whose
# body lists the upstream commits and changed paths since the previous pin.
# That body is the alignment review's input: the site is checked against a
# bounded diff instead of a periodic re-read of the corpus. The rules are in the
# header of `.github/scripts/bump-upstream-pin.mjs`; AGENTS.md has the short form.
#
# objectstack on a published `@objectstack/cli` release. With no `sha`, the
# run pins the commit tagged with npm's `latest` release.
#
# The cloud pin, `.cloud-sha`, is NOT moved here: it is moved by hand when the
# docs are refreshed to match production (maintainer ruling,
# docs.objectos.ai#433), and the helper refuses `upstream: cloud`. AGENTS.md
# "Upstream pins" has the steps. This workflow still checks its format.
#
# Triggers: `workflow_dispatch` by hand, or `repository_dispatch` of type
# `bump-upstream-docs` with `client_payload: { upstream: objectstack, sha }` —
# the shape a release workflow elsewhere sends. On a pull request that touches
# the pins, the helper or this file, the `pins` job runs the helper's self-test
# and checks both pin files by format alone; it reads neither upstream.
#
# ⛔ One secret, `UPSTREAM_BUMP_TOKEN`, and the bump refuses to start without
# it. It pushes the bump branch and opens the pull request (contents: write and
# pull-requests: write here), which `GITHUB_TOKEN` cannot do usefully: a pull
# request it opens starts no `pull_request` workflows — GitHub suppresses them
# to prevent recursive runs — so CI would never run on the bump, and whether
# this repository lets Actions open pull requests at all is a repository
# setting.
on:
workflow_dispatch:
inputs:
upstream:
description: Which pin to move (the cloud pin is moved by hand, see AGENTS.md)
type: choice
options: [objectstack]
required: true
sha:
description: >-
Full 40-character commit SHA to pin. Leave empty to pin npm's latest
@objectstack/cli release.
type: string
required: false
repository_dispatch:
types: [bump-upstream-docs]
pull_request:
branches: [main]
paths:
- '.objectstack-sha'
- '.cloud-sha'
- '.github/scripts/bump-upstream-pin.mjs'
- '.github/workflows/bump-upstream-docs.yml'
permissions:
contents: read
jobs:
pins:
name: Upstream pins are well-formed
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: actions/setup-node@v7
with:
node-version: 22
- name: Self-test
run: node .github/scripts/bump-upstream-pin.mjs --self-test
- name: Both pin files hold a full SHA or the placeholder
run: node .github/scripts/bump-upstream-pin.mjs --check
bump:
# A static name: a skipped job's name is never evaluated, so an expression
# here shows up verbatim as a check on every pull request that runs `pins`.
name: Bump an upstream pin
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
# Two bumps of one upstream would both diff from the same old pin.
concurrency:
group: bump-upstream-docs-${{ inputs.upstream || github.event.client_payload.upstream }}
cancel-in-progress: false
# Event values reach the scripts as environment variables only, never
# interpolated into a `run:` body; the helper validates both.
env:
UPSTREAM: ${{ inputs.upstream || github.event.client_payload.upstream }}
SHA: ${{ inputs.sha || github.event.client_payload.sha }}
steps:
- name: Require UPSTREAM_BUMP_TOKEN
env:
UPSTREAM_BUMP_TOKEN: ${{ secrets.UPSTREAM_BUMP_TOKEN }}
run: |
if [ -z "$UPSTREAM_BUMP_TOKEN" ]; then
echo "::error title=NOT CONFIGURED::The repository secret UPSTREAM_BUMP_TOKEN is not set. It needs contents: write + pull-requests: write on this repository. GITHUB_TOKEN is not a substitute: a pull request it opens runs no CI. (The cloud pin needs no token: it is moved by hand, see AGENTS.md.)"
exit 1
fi
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: actions/setup-node@v7
with:
node-version: 22
- name: Self-test
run: node .github/scripts/bump-upstream-pin.mjs --self-test
- name: Move the pin and write the pull-request body
id: bump
shell: bash
env:
UPSTREAM_TOKEN: ${{ secrets.UPSTREAM_BUMP_TOKEN }}
run: |
args=(--upstream "$UPSTREAM" --body "$RUNNER_TEMP/body.md" --git-dir "$RUNNER_TEMP/upstream.git")
if [ -n "$SHA" ]; then args+=(--sha "$SHA"); fi
node .github/scripts/bump-upstream-pin.mjs "${args[@]}"
if [ -f "$RUNNER_TEMP/body.md" ]; then cat "$RUNNER_TEMP/body.md" >> "$GITHUB_STEP_SUMMARY"; fi
- name: Open the pull request
if: steps.bump.outputs.changed == 'true'
shell: bash
env:
GH_TOKEN: ${{ secrets.UPSTREAM_BUMP_TOKEN }}
LABEL: ${{ steps.bump.outputs.label }}
SHORT: ${{ steps.bump.outputs.short }}
TITLE: ${{ steps.bump.outputs.title }}
run: |
set -euo pipefail
branch="bump-upstream-docs/${LABEL}-${SHORT}"
# The token rides in GIT_CONFIG_* (masked), never on a command line.
basic=$(printf 'x-access-token:%s' "$GH_TOKEN" | base64 -w0)
echo "::add-mask::$basic"
export GIT_CONFIG_COUNT=1
export GIT_CONFIG_KEY_0=http.https://github.com/.extraheader
export GIT_CONFIG_VALUE_0="AUTHORIZATION: basic $basic"
if git ls-remote --exit-code --heads origin "$branch" > /dev/null; then
echo "::error::Branch $branch already exists — a bump to this commit was already pushed. Review or close its pull request instead of bumping again."
exit 1
fi
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git switch -c "$branch"
git add -- ".${LABEL}-sha"
git commit -m "$TITLE"
git push origin "$branch"
gh pr create --base main --head "$branch" --title "$TITLE" --body-file "$RUNNER_TEMP/body.md"