Skip to content

Commit 4261116

Browse files
authored
Publish specification 0.3.0 and keep spec and contract pins current (#116)
Move the specification pin to mdbase-spec main (13531d8), which carries the 0.3.0 release, the type packs and concurrent edits companion profiles, and runtime pack 0.2.1. - import-spec: send remaining repository-relative .md links (release record, rc.5 notes) to GitHub; the v0.2 archive's copied guides stay local. - sync-sources: publish runtime schemas from pack 0.2.1, a superset of 0.2.0 that adds the 1.1.0 record schemas. - runtime page: link the workflow 1.1.0 schema and pack 0.2.1. - Add update-pinned-sources.yml (hourly, dispatch, manual) and merge-pinned-sources.yml so the spec and contracts pins move to main through Site checks without manual bumps.
1 parent 04400d8 commit 4261116

7 files changed

Lines changed: 246 additions & 6 deletions

File tree

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Merge pinned source update
2+
3+
# Merges only the automated pinned-source pull request, after Site checks pass
4+
# on its exact head. Every other pull request keeps its normal merge path.
5+
on:
6+
workflow_run:
7+
workflows: [Site checks]
8+
types: [completed]
9+
10+
permissions:
11+
contents: read
12+
13+
concurrency:
14+
group: pinned-sources-merge
15+
cancel-in-progress: false
16+
17+
jobs:
18+
merge:
19+
name: Merge verified pinned source update
20+
if: >-
21+
github.event.workflow_run.event == 'pull_request' &&
22+
github.event.workflow_run.conclusion == 'success' &&
23+
github.event.workflow_run.head_repository.full_name == github.repository &&
24+
startsWith(github.event.workflow_run.head_branch, 'automation/sources-')
25+
runs-on: ubuntu-24.04
26+
steps:
27+
- name: Create website automation token
28+
id: app-token
29+
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
30+
with:
31+
client-id: ${{ vars.RELEASE_AUTOMATION_CLIENT_ID }}
32+
private-key: ${{ secrets.RELEASE_AUTOMATION_APP_PRIVATE_KEY }}
33+
owner: mdbase-dev
34+
repositories: mdbase.dev
35+
permission-contents: write
36+
permission-pull-requests: write
37+
38+
- name: Merge the exact checked head
39+
env:
40+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
41+
BRANCH: ${{ github.event.workflow_run.head_branch }}
42+
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
43+
run: |
44+
fields=number,author,baseRefName,files,headRefOid,isCrossRepository,mergeStateStatus,state,title
45+
pr="$(gh pr list --repo "$GITHUB_REPOSITORY" --state open --head "$BRANCH" --json "$fields" --jq '.[0] // empty')"
46+
if [ -z "$pr" ]; then
47+
echo "No open pinned source update for $BRANCH."
48+
exit 0
49+
fi
50+
if [ "$(jq -r .headRefOid <<<"$pr")" != "$HEAD_SHA" ]; then
51+
echo "$BRANCH moved after these checks; its own Site checks run decides."
52+
exit 0
53+
fi
54+
if [[ ! "$BRANCH" =~ ^automation/sources-([0-9a-f]{12})-([0-9a-f]{12})$ ]]; then
55+
echo "Unexpected branch name $BRANCH." >&2
56+
exit 1
57+
fi
58+
spec="${BASH_REMATCH[1]}"
59+
contracts="${BASH_REMATCH[2]}"
60+
jq -e --arg title "Update pinned sources to specification $spec and contracts $contracts" '
61+
.author.login == "app/mdbase-dev-release-automation" and
62+
.baseRefName == "main" and
63+
.isCrossRepository == false and
64+
.title == $title and
65+
([.files[].path] | sort) == ["site-sources.json"]
66+
' <<<"$pr" >/dev/null || {
67+
echo "This pull request is not an automated pinned-source update." >&2
68+
exit 1
69+
}
70+
71+
# Only the specification and contracts pins may differ from the
72+
# branch point, and they must be the revisions the branch names.
73+
base="$(gh api "repos/$GITHUB_REPOSITORY/compare/main...$HEAD_SHA" --jq .merge_base_commit.sha)"
74+
gh api "repos/$GITHUB_REPOSITORY/contents/site-sources.json?ref=$base" --jq .content | base64 -d > "$RUNNER_TEMP/base.json"
75+
gh api "repos/$GITHUB_REPOSITORY/contents/site-sources.json?ref=$HEAD_SHA" --jq .content | base64 -d > "$RUNNER_TEMP/head.json"
76+
jq -e -n --slurpfile base "$RUNNER_TEMP/base.json" --slurpfile head "$RUNNER_TEMP/head.json" \
77+
--arg spec "$spec" --arg contracts "$contracts" '
78+
($base[0] | del(.specification.ref, .contracts.ref)) == ($head[0] | del(.specification.ref, .contracts.ref)) and
79+
($head[0].specification.ref | test("^[0-9a-f]{40}$") and startswith($spec)) and
80+
($head[0].contracts.ref | test("^[0-9a-f]{40}$") and startswith($contracts))
81+
' >/dev/null || {
82+
echo "site-sources.json changes more than the named specification and contracts pins." >&2
83+
exit 1
84+
}
85+
86+
number="$(jq -r .number <<<"$pr")"
87+
# main is strict, so a behind branch needs fresh checks on its new head.
88+
if [ "$(jq -r .mergeStateStatus <<<"$pr")" = "BEHIND" ]; then
89+
gh pr update-branch "$number" --repo "$GITHUB_REPOSITORY"
90+
exit 0
91+
fi
92+
gh pr merge "$number" --repo "$GITHUB_REPOSITORY" --squash --match-head-commit "$HEAD_SHA" --delete-branch
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
name: Update pinned sources
2+
3+
# Moves the specification and contract-catalog pins in site-sources.json to
4+
# the head of their main branches. The pull request it opens is built and
5+
# tested by Site checks like any other change, and merge-pinned-sources.yml
6+
# merges it once those checks pass on its exact head.
7+
on:
8+
schedule:
9+
- cron: "17 * * * *"
10+
repository_dispatch:
11+
types: [pinned-source-updated]
12+
workflow_dispatch:
13+
14+
permissions:
15+
contents: read
16+
17+
concurrency:
18+
group: pinned-sources-update
19+
cancel-in-progress: false
20+
21+
jobs:
22+
update:
23+
name: Open pinned source update
24+
runs-on: ubuntu-24.04
25+
steps:
26+
- name: Check out website
27+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
28+
with:
29+
ref: main
30+
persist-credentials: false
31+
32+
- name: Select upstream revisions
33+
id: select
34+
env:
35+
GH_TOKEN: ${{ github.token }}
36+
run: |
37+
changed=false
38+
for source in specification contracts; do
39+
repository="$(jq -r ".$source.repository" site-sources.json)"
40+
current="$(jq -r ".$source.ref" site-sources.json)"
41+
head="$(git ls-remote "https://github.com/$repository.git" refs/heads/main | cut -f1)"
42+
if [[ ! "$head" =~ ^[0-9a-f]{40}$ ]]; then
43+
echo "Could not read the main branch of $repository." >&2
44+
exit 1
45+
fi
46+
if [ "$head" != "$current" ]; then
47+
# A pin only moves forward along main.
48+
status="$(gh api "repos/$repository/compare/$current...$head" --jq .status)"
49+
if [ "$status" != "ahead" ]; then
50+
echo "$repository main is $status relative to the pinned $current; not moving the pin." >&2
51+
exit 1
52+
fi
53+
jq --arg source "$source" --arg head "$head" '.[$source].ref = $head' site-sources.json > "$RUNNER_TEMP/site-sources.json"
54+
mv "$RUNNER_TEMP/site-sources.json" site-sources.json
55+
changed=true
56+
fi
57+
echo "${source}_ref=$head" >> "$GITHUB_OUTPUT"
58+
done
59+
echo "changed=$changed" >> "$GITHUB_OUTPUT"
60+
61+
- name: Create website automation token
62+
if: steps.select.outputs.changed == 'true'
63+
id: app-token
64+
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
65+
with:
66+
client-id: ${{ vars.RELEASE_AUTOMATION_CLIENT_ID }}
67+
private-key: ${{ secrets.RELEASE_AUTOMATION_APP_PRIVATE_KEY }}
68+
owner: mdbase-dev
69+
repositories: mdbase.dev
70+
permission-contents: write
71+
permission-pull-requests: write
72+
73+
- name: Open pull request
74+
if: steps.select.outputs.changed == 'true'
75+
env:
76+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
77+
SPEC_REF: ${{ steps.select.outputs.specification_ref }}
78+
CONTRACTS_REF: ${{ steps.select.outputs.contracts_ref }}
79+
run: |
80+
spec="${SPEC_REF:0:12}"
81+
contracts="${CONTRACTS_REF:0:12}"
82+
branch="automation/sources-$spec-$contracts"
83+
title="Update pinned sources to specification $spec and contracts $contracts"
84+
existing="$(gh pr list --repo "$GITHUB_REPOSITORY" --state all --head "$branch" --json url,state --jq '.[0] // empty')"
85+
if [ -n "$existing" ]; then
86+
# Open, merged, or deliberately closed: either way this revision
87+
# pair has been handled, and the next upstream commit opens anew.
88+
echo "These revisions are already represented by $(jq -r .url <<<"$existing") ($(jq -r .state <<<"$existing"))."
89+
exit 0
90+
fi
91+
if git ls-remote --exit-code --heads "https://github.com/$GITHUB_REPOSITORY.git" "$branch" >/dev/null 2>&1; then
92+
echo "Remote branch $branch exists without a pull request; refusing to overwrite it." >&2
93+
exit 1
94+
fi
95+
git switch -c "$branch"
96+
git config user.name "mdbase release automation[bot]"
97+
git config user.email "mdbase-release-automation[bot]@users.noreply.github.com"
98+
git add site-sources.json
99+
git commit -m "$title"
100+
git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
101+
git push --set-upstream origin "$branch"
102+
body="$(printf '%s\n' \
103+
"Moves the published sources to the head of their main branches:" \
104+
"" \
105+
"- specification: [mdbase-dev/mdbase-spec@$spec](https://github.com/mdbase-dev/mdbase-spec/commit/$SPEC_REF)" \
106+
"- contracts: [mdbase-dev/mdbase-contracts@$contracts](https://github.com/mdbase-dev/mdbase-contracts/commit/$CONTRACTS_REF)" \
107+
"" \
108+
"Site checks build and test the site at these revisions. The pull request merges itself when they pass.")"
109+
url="$(gh pr create --repo "$GITHUB_REPOSITORY" --base main --head "$branch" --title "$title" --body "$body")"
110+
echo "Opened $url"
111+
112+
# Runs are serialized and always take the newest heads, so any other
113+
# open update is older and would only move the pins back.
114+
gh pr list --repo "$GITHUB_REPOSITORY" --state open --json number,headRefName \
115+
--jq ".[] | select(.headRefName | startswith(\"automation/sources-\")) | select(.headRefName != \"$branch\") | .number" |
116+
while read -r number; do
117+
gh pr close "$number" --repo "$GITHUB_REPOSITORY" --delete-branch --comment "Superseded by $url."
118+
done

‎README.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,25 @@ The workflow uses a GitHub App configured as `RELEASE_AUTOMATION_CLIENT_ID` and
100100
only `contents: write` and `pull requests: write`. The App token ensures the
101101
resulting pull request triggers the ordinary protected `Site checks` workflow.
102102

103+
## Specification and contract updates
104+
105+
The specification and contract-catalog pins follow their repositories' `main`
106+
branches. Every hour (and on a `pinned-source-updated` repository dispatch or a
107+
manual run), `.github/workflows/update-pinned-sources.yml` compares both pins
108+
with the upstream heads. When either has moved forward, it opens one pull
109+
request on an `automation/sources-<spec>-<contracts>` branch that changes only
110+
those refs. `Site checks` builds and tests the site at the new revisions, and
111+
`.github/workflows/merge-pinned-sources.yml` merges the pull request when they
112+
pass on its exact head. The merge then deploys through the normal `main` path.
113+
A newer update closes an older open one. If the checks fail, the pull request
114+
stays open for a person to look at, and the next upstream commit opens a fresh
115+
one.
116+
117+
The merge workflow acts only on a pull request opened by the release App,
118+
titled for the two revisions its branch names, and changing nothing in
119+
`site-sources.json` except those two refs. It uses the same App credentials
120+
as the Connect release update.
121+
103122
## Development deployment
104123

105124
```sh

‎scripts/import-spec.mjs‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
1313
const specDir = resolve(process.env.MDBASE_SPEC_DIR ?? join(root, "..", "mdbase-spec"));
1414
const source = resolve(process.env.MDBASE_SPEC_SITE_DIST ?? join(specDir, "site", "dist"));
1515
const destination = join(root, "dist", "spec");
16+
const SUPPORT_FILES = ["IMPLEMENTING.md", "REFERENCE-RUNNER.md", "QUICK-REFERENCE.md"];
1617
const siteOrigin = new URL(process.env.MDBASE_SITE_ORIGIN ?? "https://mdbase.dev").origin;
1718

1819
required(join(root, "dist", "index.html"), "Build mdbase.dev before importing the specification");
@@ -29,7 +30,7 @@ writeFileSync(
2930
rewrite(readFileSync(join(source, "spec-v0.2.html"), "utf8"), true)
3031
);
3132

32-
for (const support of ["IMPLEMENTING.md", "REFERENCE-RUNNER.md", "QUICK-REFERENCE.md"]) {
33+
for (const support of SUPPORT_FILES) {
3334
const path = join(specDir, "v0.2", support);
3435
if (existsSync(path)) copyFileSync(path, join(destination, "v0.2", support));
3536
}
@@ -64,7 +65,17 @@ function rewrite(html, archive) {
6465
)
6566
.replace(/<a href="\.\/person\.md">([^<]+)<\/a>/g, "<code>$1</code>")
6667
.replace(/<a href="\.\/project\.md">([^<]+)<\/a>/g, "<code>$1</code>")
67-
.replace(/href="\.\/\d{2}-[^"#]+\.md#([^"]+)"/g, 'href="#$1"');
68+
.replace(/href="\.\/\d{2}-[^"#]+\.md#([^"]+)"/g, 'href="#$1"')
69+
// Any other repository-relative document (release records, release
70+
// notes) is not published on this site, so link to it on GitHub. The
71+
// archive's support guides are copied beside it below, so they stay.
72+
.replace(
73+
/href="\.\/([^"#]+\.md)(#[^"]*)?"/g,
74+
(link, path, fragment = "") =>
75+
archive && SUPPORT_FILES.includes(path)
76+
? link
77+
: `href="https://github.com/mdbase-dev/mdbase-spec/blob/main/${path}${fragment}"`
78+
);
6879
return renderSpecPage(readFileSync(shellPath, "utf8"), content, archive);
6980
}
7081

‎scripts/sync-sources.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const runtimeSchemaSource = join(
4444
specDir,
4545
"standard-packs",
4646
"mdbase-runtime",
47-
"0.2.0",
47+
"0.2.1",
4848
"schemas",
4949
);
5050
const runtimeSchemaDestination = join(root, "public", "runtime", "schemas", "v0.2");

‎site-sources.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"specification": {
33
"repository": "mdbase-dev/mdbase-spec",
4-
"ref": "eabae2143275a0619b02d564961fa74b8037185e"
4+
"ref": "13531d8d2ad7344d45d0eb15124e731e07ee76c4"
55
},
66
"connect": {
77
"repository": "mdbase-dev/mdbase-connect",

‎src/pages/runtime/index.astro‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ steps:
153153
</tbody>
154154
</table>
155155
<p>
156-
<a href="/runtime/schemas/v0.2/mdbase.runtime.workflow/1.0.0.schema.json">
156+
<a href="/runtime/schemas/v0.2/mdbase.runtime.workflow/1.1.0.schema.json">
157157
Open the workflow JSON Schema
158158
</a>
159159
{" · "}
160-
<a href="https://github.com/mdbase-dev/mdbase-spec/tree/main/standard-packs/mdbase-runtime/0.2.0">
160+
<a href="https://github.com/mdbase-dev/mdbase-spec/tree/main/standard-packs/mdbase-runtime/0.2.1">
161161
Inspect the complete standard pack
162162
</a>
163163
</p>

0 commit comments

Comments
 (0)