Skip to content

Commit bf4387d

Browse files
authored
Merge pull request #60 from manicinc/fix/release-gate-docs-publisher
ci: release to tags and npm only, publish the docs from one workflow, keep master pull-request only
2 parents d8f31db + 2d8bf3b commit bf4387d

19 files changed

Lines changed: 414 additions & 239 deletions

‎.github/workflows/auto-format.yml‎

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
name: Auto Format
22

3+
# By hand only: a push made with GITHUB_TOKEN starts no workflow, so a commit from this job leaves
4+
# a head with no all-checks, which master's ruleset requires. Push once more after running it.
35
on:
4-
pull_request:
5-
types: [opened, synchronize, reopened]
66
workflow_dispatch:
77

88
permissions:
99
contents: write
10-
pull-requests: write
1110

1211
jobs:
1312
format:
1413
runs-on: ubuntu-latest
15-
# Only run on PRs from the same repo (not forks)
16-
if: github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'workflow_dispatch'
17-
14+
1815
steps:
1916
- name: Checkout code
2017
uses: actions/checkout@v4
2118
with:
2219
token: ${{ secrets.GITHUB_TOKEN }}
23-
ref: ${{ github.head_ref || github.ref }}
20+
ref: ${{ github.ref }}
2421
fetch-depth: 0
2522

2623
- name: Setup pnpm
@@ -57,16 +54,3 @@ jobs:
5754
5855
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
5956
git push
60-
61-
- name: Comment on PR
62-
if: steps.prettier.outputs.formatted == 'true' && github.event_name == 'pull_request'
63-
uses: actions/github-script@v7
64-
with:
65-
github-token: ${{ secrets.GITHUB_TOKEN }}
66-
script: |
67-
github.rest.issues.createComment({
68-
issue_number: context.issue.number,
69-
owner: context.repo.owner,
70-
repo: context.repo.repo,
71-
body: '✨ **Auto-formatted code with Prettier**\n\nI\'ve automatically formatted the code to match the project\'s style guidelines. The changes have been pushed to this PR.'
72-
})

‎.github/workflows/ci.yml‎

Lines changed: 12 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ permissions:
1414
pull-requests: write
1515
id-token: write
1616

17+
# On a pull request a newer push cancels the older run. On master the running run finishes and
18+
# only the newest waiting run is kept, so a stream of merges still reaches the end of the suite.
19+
# A re-run keys a group of its own: re-running an older commit's run never cancels the newest run
20+
# or takes its place in the queue.
1721
concurrency:
18-
group: ci-${{ github.ref }}
19-
cancel-in-progress: true
22+
group: ${{ github.run_attempt == '1' && format('ci-{0}', github.ref) || format('ci-rerun-{0}', github.run_id) }}
23+
cancel-in-progress: ${{ github.event_name == 'pull_request' && github.run_attempt == '1' }}
2024

2125
env:
2226
NODE_VERSION: '22'
@@ -72,32 +76,13 @@ jobs:
7276
- name: Install deps
7377
run: pnpm install --frozen-lockfile
7478

75-
# Auto-format and commit if needed (only for non-fork PRs and direct pushes)
76-
- name: Auto-format code
77-
id: format
78-
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)
79-
run: |
80-
pnpm run format
81-
if [[ $(git status --porcelain) ]]; then
82-
echo "formatted=true" >> $GITHUB_OUTPUT
83-
else
84-
echo "formatted=false" >> $GITHUB_OUTPUT
85-
fi
86-
87-
- name: Commit formatted code
88-
if: steps.format.outputs.formatted == 'true' && (github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository))
89-
run: |
90-
git config --global user.name "github-actions[bot]"
91-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
92-
git add -A
93-
git commit -m "style: auto-format code with prettier [skip ci]"
94-
git push
95-
96-
# For fork PRs, just check formatting without auto-fixing
97-
- name: Format check (fork PRs)
98-
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository
79+
# A check, not a commit: a push made with GITHUB_TOKEN starts no workflow, so a bot's commit
80+
# on a pull request would leave a head that never reports all-checks, which master's ruleset
81+
# requires. Fix a failure with pnpm run format.
82+
- name: Format check
83+
if: github.event_name == 'pull_request'
9984
run: pnpm run format:check
100-
85+
10186
- name: Lint
10287
run: pnpm run lint
10388

@@ -273,21 +258,6 @@ jobs:
273258
- name: Bundle size check
274259
run: pnpm run size:check
275260

276-
- name: Update bundle size (README)
277-
run: pnpm run size:update
278-
279-
- name: Commit README size update (PR only)
280-
if: github.event_name == 'pull_request'
281-
run: |
282-
if git diff --quiet --exit-code README.md; then
283-
echo "No README size changes"; exit 0
284-
fi
285-
git config user.name "github-actions[bot]"
286-
git config user.email "github-actions[bot]@users.noreply.github.com"
287-
git add README.md
288-
git commit -m "chore(ci): update bundle size table [skip ci]" || true
289-
git push || echo "Non-fatal: push failed (likely due to permissions)"
290-
291261
- name: Bundle size analyze
292262
run: node scripts/analyze-build.js || true
293263

@@ -354,56 +324,6 @@ jobs:
354324
env:
355325
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
356326

357-
# Deploy docs to gh-pages after successful build on main/master branches
358-
deploy-docs:
359-
name: Deploy Documentation to gh-pages
360-
runs-on: ubuntu-latest
361-
needs: [build]
362-
if: (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') && github.event_name == 'push'
363-
permissions:
364-
contents: write
365-
pages: write
366-
steps:
367-
- uses: actions/checkout@v4
368-
with:
369-
fetch-depth: 0
370-
371-
- name: Setup pnpm
372-
uses: pnpm/action-setup@v4
373-
374-
- name: Setup Node.js
375-
uses: actions/setup-node@v4
376-
with:
377-
node-version: ${{ env.NODE_VERSION }}
378-
cache: 'pnpm'
379-
380-
# The install, the library build, the API pages and the Docusaurus build, as docs-build.yml
381-
# runs them on pull requests, after the same setup steps. No website/node_modules cache is
382-
# restored first: the one that stood here keyed on website/package-lock.json, which does
383-
# not exist, so its key never changed and every deploy restored the folder one master run
384-
# saved, from an older dependency tree than the lockfile, before an install no
385-
# pull-request check ran from. setup-node's pnpm cache holds the store.
386-
- name: Build the site
387-
run: bash scripts/build-docs-site.sh
388-
env:
389-
GA_TRACKING_ID: ${{ secrets.GA_TRACKING_ID }}
390-
MS_CLARITY_ID: ${{ secrets.MS_CLARITY_ID }}
391-
392-
- name: Deploy to gh-pages branch
393-
uses: peaceiris/actions-gh-pages@v3
394-
with:
395-
github_token: ${{ secrets.GITHUB_TOKEN }}
396-
publish_dir: ./website/build
397-
publish_branch: gh-pages
398-
force_orphan: true
399-
user_name: 'github-actions[bot]'
400-
user_email: 'github-actions[bot]@users.noreply.github.com'
401-
commit_message: |
402-
🚀 Deploy docs from ${{ github.sha }}
403-
404-
Build: ${{ github.run_id }}
405-
Actor: ${{ github.actor }}
406-
407327
all-checks:
408328
runs-on: ubuntu-latest
409329
needs: [quality, test-linux, build, security, runtime-floor]

‎.github/workflows/deploy-docs.yml‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,21 @@ on:
55
branches:
66
- master
77
- main
8+
# The paths docs-build.yml checks on a pull request: the site's pages and the API pages it
9+
# generates from the source. This is the one workflow that publishes to gh-pages.
810
paths:
911
- 'docs/**'
1012
- 'website/**'
13+
- 'src/**'
14+
- 'README.md'
15+
- 'tsconfig.json'
16+
- 'tsup.config.ts'
17+
- 'tsconfig.build.json'
18+
- 'package.json'
19+
- 'pnpm-lock.yaml'
20+
- 'pnpm-workspace.yaml'
21+
- 'typedoc.json'
22+
- 'scripts/build-docs-site.sh'
1123
- '.github/workflows/deploy-docs.yml'
1224
workflow_dispatch:
1325

@@ -16,12 +28,35 @@ permissions:
1628
pages: write
1729
id-token: write
1830

31+
# Every run that publishes waits in one group, because all of them publish to the one gh-pages
32+
# branch: the running deploy finishes and only the newest waiting run is kept. A manual run from
33+
# another branch publishes nothing and keys a group of its own, so it never takes a waiting
34+
# deploy's place.
35+
concurrency:
36+
group: ${{ (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') && 'deploy-docs' || format('deploy-docs-{0}', github.run_id) }}
37+
cancel-in-progress: false
38+
1939
jobs:
2040
deploy:
41+
# A manual run from another branch would replace the live site with that branch's pages.
42+
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main'
2143
runs-on: ubuntu-latest
2244
steps:
45+
# The branch's tip when the job starts, not the commit that started the run: a re-run keeps
46+
# its run's commit, and an older re-run would otherwise publish older pages over newer ones.
47+
# With ref set, actions/checkout fetches the branch and checks out its head. The build runs
48+
# the dependencies' install scripts, so the token stays out of .git/config; the publish step
49+
# receives it as github_token.
2350
- name: Checkout
2451
uses: actions/checkout@v4
52+
with:
53+
ref: ${{ github.ref }}
54+
fetch-depth: 0
55+
persist-credentials: false
56+
57+
- name: Read the commit being published
58+
id: tip
59+
run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
2560

2661
- name: Setup pnpm
2762
uses: pnpm/action-setup@v4
@@ -33,7 +68,8 @@ jobs:
3368
cache: 'pnpm'
3469

3570
# The install, the library build, the API pages and the Docusaurus build, as docs-build.yml
36-
# runs them on pull requests and ci.yml's deploy-docs job runs them before its own publish.
71+
# runs them on pull requests. No website/node_modules cache is restored first: setup-node's
72+
# pnpm cache holds the store.
3773
- name: Build the site
3874
run: bash scripts/build-docs-site.sh
3975
env:
@@ -46,6 +82,7 @@ jobs:
4682
github_token: ${{ secrets.GITHUB_TOKEN }}
4783
publish_dir: ./website/build
4884
publish_branch: gh-pages
85+
force_orphan: true
4986
user_name: 'github-actions[bot]'
5087
user_email: 'github-actions[bot]@users.noreply.github.com'
51-
commit_message: 'Deploy documentation website'
88+
commit_message: 'Deploy docs from ${{ steps.tip.outputs.sha }}'

‎.github/workflows/docs-build.yml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name: Docs build
22

3-
# Builds the documentation site with scripts/build-docs-site.sh, the script ci.yml's deploy-docs
4-
# job and deploy-docs.yml run after a push to master, and deploys nothing. Without it, a pull
3+
# Builds the documentation site with scripts/build-docs-site.sh, the script deploy-docs.yml runs
4+
# after a push to master, and deploys nothing. Without it, a pull
55
# request that breaks the site (a Docusaurus or webpack release in pnpm-lock.yaml, a page in
66
# docs/, a change to the build commands) passes every check and the break first shows in the
7-
# deploy on master. The setup steps and the gh-pages publish stay in each deploy workflow.
7+
# deploy on master. The setup steps and the gh-pages publish stay in deploy-docs.yml.
88
on:
99
pull_request:
1010
branches: [master, main]
@@ -16,7 +16,7 @@ on:
1616
- 'src/**'
1717
- 'README.md'
1818
- 'tsconfig.json'
19-
# The library build that runs first, as in the deploy.
19+
# The library build that runs first, as in the deploy. deploy-docs.yml watches these paths.
2020
- 'tsup.config.ts'
2121
- 'tsconfig.build.json'
2222
- 'package.json'
@@ -52,7 +52,7 @@ jobs:
5252
node-version: '22'
5353
cache: 'pnpm'
5454

55-
# Both deploys build with the analytics ids set, so this build sets stand-ins and takes the
55+
# The deploy builds with the analytics ids set, so this build sets stand-ins and takes the
5656
# same branches of website/src/plugins/analyticsPlugin.js. Nothing here is deployed.
5757
- name: Build the site
5858
run: bash scripts/build-docs-site.sh

‎.github/workflows/releases.yml‎

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,10 @@ on:
55
branches:
66
- main
77
- master
8-
pull_request:
9-
types: [closed]
10-
branches:
11-
- main
12-
- master
13-
# Runs the release again by hand, for a release that failed after its commits landed: a
14-
# re-run reads the workflow of the failed commit, and a push releases only when its own
15-
# message starts with feat:, fix: or perf:. With dry_run, the dry-run job below runs
16-
# instead, on any branch.
8+
# Runs a release by hand: after a merged pull request, whose push is a merge commit and starts
9+
# no release, and for a release that failed after its commits landed (a re-run reads the
10+
# workflow of the failed commit). A run that failed after it pushed its tag needs the steps in
11+
# docs/deployment.md first. With dry_run, the dry-run job below runs instead, on any branch.
1712
workflow_dispatch:
1813
inputs:
1914
dry_run:
@@ -28,14 +23,10 @@ permissions:
2823
id-token: write
2924
packages: write
3025

31-
# A merged pull request starts two runs here, the push to master and the pull_request closed
32-
# event (whose ref is master), and with cancel-in-progress one cancelled the other: after #49
33-
# and #41 the closed runs 39502528638 and 17751756261 were cancelled. Were the push run
34-
# cancelled instead, the release would not run: semantic-release publishes nothing from a
35-
# pull_request event. A publishing workflow never cancels, and every run of this one waits in
36-
# one fixed group, whatever its branch or event. queue: max keeps up to 100 runs waiting; with
37-
# the default (queue: single) a newer run, even a push whose job is skipped, replaces the one
38-
# waiting, so a waiting manual run would be dropped.
26+
# A publishing workflow never cancels, and every run of this one waits in one fixed group,
27+
# whatever its branch or event. queue: max keeps up to 100 runs waiting; with the default
28+
# (queue: single) a newer run, even a push whose job is skipped, replaces the one waiting, so a
29+
# waiting manual run would be dropped.
3930
concurrency:
4031
group: semantic-release
4132
cancel-in-progress: false
@@ -45,7 +36,10 @@ jobs:
4536
release:
4637
name: Release
4738
runs-on: ubuntu-latest
48-
# Skip for commits that don't need releases. A manual run releases master or main only, the
39+
# Skip for commits that don't need releases. Revert " is the message git revert writes, which
40+
# the commit analyzer releases as a patch. contains() ignores case, so the footer is matched
41+
# with its colon: without it, any message that mentions a breaking change in its prose
42+
# started the release job. A manual run releases master or main only, the
4943
# branches .releaserc names, and only without dry_run: semantic-release refuses any other
5044
# branch, after the suite and the build have run.
5145
if: |
@@ -60,20 +54,26 @@ jobs:
6054
!startsWith(github.event.head_commit.message, 'ci:') &&
6155
!startsWith(github.event.head_commit.message, 'build:') &&
6256
(startsWith(github.event.head_commit.message, 'feat:') ||
57+
startsWith(github.event.head_commit.message, 'feat(') ||
6358
startsWith(github.event.head_commit.message, 'fix:') ||
59+
startsWith(github.event.head_commit.message, 'fix(') ||
6460
startsWith(github.event.head_commit.message, 'perf:') ||
65-
contains(github.event.head_commit.message, 'BREAKING CHANGE'))) ||
66-
(github.event_name == 'pull_request' &&
67-
github.event.pull_request.merged == true &&
68-
!contains(github.event.pull_request.labels.*.name, 'skip-release')) ||
61+
startsWith(github.event.head_commit.message, 'perf(') ||
62+
startsWith(github.event.head_commit.message, 'revert:') ||
63+
startsWith(github.event.head_commit.message, 'revert(') ||
64+
startsWith(github.event.head_commit.message, 'Revert "') ||
65+
contains(github.event.head_commit.message, 'BREAKING CHANGE:'))) ||
6966
(github.event_name == 'workflow_dispatch' && !inputs.dry_run &&
7067
(github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main'))
7168
timeout-minutes: 45
69+
# Nothing is committed to master: .releaserc has no @semantic-release/git, so a release is a
70+
# tag, an npm version and a GitHub Release, and master's ruleset (required checks, no bypass)
71+
# never meets a push from this job. package.json's version on master is not the released
72+
# version; the highest v* tag is.
73+
#
7274
# Git hooks are for commits made by hand. pnpm install installs them here (prepare: husky),
73-
# and @semantic-release/git commits and pushes with hooks on: run 39541215457 stopped when
74-
# commit-msg's commitlint rejected the release notes' long lines, and pre-push would run
75-
# the typecheck and the whole suite again. husky 9 skips its install and every hook when
76-
# HUSKY is 0.
75+
# and semantic-release pushes its tag with hooks on: pre-push would run the typecheck and the
76+
# whole suite again. husky 9 skips its install and every hook when HUSKY is 0.
7777
env:
7878
HUSKY: '0'
7979

@@ -141,7 +141,7 @@ jobs:
141141
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
142142
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
143143
# The steps above ran the lint, the suite, the build and the packed-files check on this
144-
# commit. semantic-release pushes the release commit and the tag before its publish step
144+
# commit. semantic-release pushes the tag before its publish step
145145
# (semantic-release 21.1.2 index.js lines 205 to 212), and npm publish would then run
146146
# prepublishOnly: the suite again with parallel workers (CI runs it only with
147147
# --runInBand), the lint, the build and the size script. A red second run

0 commit comments

Comments
 (0)