Skip to content

Commit 4ac6d43

Browse files
dahliaclaude
andcommitted
Parallelize npm publishing with docs publishing
Previously, npm publishing only started after the entire main.yaml workflow completed (including docs publishing) due to using workflow_run trigger. Now, publish-npm job triggers build.yaml via workflow_dispatch immediately after publish-jsr completes, allowing npm and docs publishing to run in parallel. Changes: - Rename publish job to publish-jsr for clarity - Add publish-npm job that triggers build.yaml via workflow_dispatch - Remove workflow_run trigger from build.yaml (now solely workflow_dispatch) - Update publish-docs dependency to publish-jsr Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 13db168 commit 4ac6d43

2 files changed

Lines changed: 49 additions & 40 deletions

File tree

.github/workflows/build.yaml

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@
99
# that is directly triggered, not reusable workflows called via workflow_call.
1010
# See: https://docs.npmjs.com/trusted-publishers/
1111
#
12-
# The workflow is triggered in two ways:
13-
# 1. workflow_run: Automatically after main.yaml completes (for regular releases)
14-
# 2. workflow_dispatch: Manually triggered (for PR pre-releases)
12+
# This workflow is triggered via workflow_dispatch from:
13+
# 1. main.yaml's publish-npm job (for regular releases)
14+
# 2. publish-pr.yaml (for PR pre-releases)
1515
name: build
1616

1717
on:
18-
workflow_run:
19-
workflows: [main]
20-
types: [completed]
2118
workflow_dispatch:
2219
inputs:
2320
run_id:
@@ -31,37 +28,15 @@ on:
3128

3229
jobs:
3330
npm-publish:
34-
# For workflow_run: only run if the triggering workflow succeeded and was a push event
35-
# For workflow_dispatch: always run
36-
if: >-
37-
github.event_name == 'workflow_dispatch' ||
38-
(github.event.workflow_run.conclusion == 'success' &&
39-
github.event.workflow_run.event == 'push')
4031
runs-on: ubuntu-latest
4132
permissions:
4233
id-token: write
4334
contents: read
4435
steps:
45-
- name: Determine run ID and tag
46-
id: config
47-
run: |
48-
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
49-
echo "run_id=${{ inputs.run_id }}" >> $GITHUB_OUTPUT
50-
echo "tag=${{ inputs.tag }}" >> $GITHUB_OUTPUT
51-
else
52-
echo "run_id=${{ github.event.workflow_run.id }}" >> $GITHUB_OUTPUT
53-
# Determine tag based on ref type from the triggering workflow
54-
if [[ "${{ github.event.workflow_run.head_branch }}" == refs/tags/* ]] || \
55-
[[ -n "$(echo '${{ github.event.workflow_run.head_branch }}' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+')" ]]; then
56-
echo "tag=latest" >> $GITHUB_OUTPUT
57-
else
58-
echo "tag=dev" >> $GITHUB_OUTPUT
59-
fi
60-
fi
6136
- uses: actions/download-artifact@v4
6237
with:
6338
name: npm-packages
64-
run-id: ${{ steps.config.outputs.run_id }}
39+
run-id: ${{ inputs.run_id }}
6540
github-token: ${{ secrets.GITHUB_TOKEN }}
6641
- run: ls -la
6742
- name: Setup Node.js
@@ -73,7 +48,7 @@ jobs:
7348
- name: Publish packages
7449
run: |
7550
set -ex
76-
TAG="${{ steps.config.outputs.tag }}"
51+
TAG="${{ inputs.tag }}"
7752
for pkg in fedify-*.tgz; do
7853
if [[ "$TAG" = "latest" ]]; then
7954
npm publish --logs-dir=. --provenance --access public "$pkg" \

.github/workflows/main.yaml

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
22
#
3-
# Main CI workflow for testing, linting, and publishing to JSR.
4-
# npm publishing is handled separately by build.yaml, which is triggered
5-
# automatically via workflow_run after this workflow completes successfully.
6-
# This separation is required for npm's trusted publishing (OIDC) to work
7-
# correctly. See build.yaml for more details.
3+
# Main CI workflow for testing, linting, and publishing to JSR/npm.
4+
# npm publishing is handled by build.yaml, which is triggered via workflow_dispatch
5+
# from the publish-npm job. This allows npm publishing to run in parallel with
6+
# docs publishing, rather than waiting for the entire workflow to complete.
7+
# See build.yaml for details on why this separation is required for npm's
8+
# trusted publishing (OIDC).
89
name: main
910
on: [push, pull_request]
1011

@@ -203,7 +204,7 @@ jobs:
203204
- run: pnpm install
204205
- run: pnpm publish --recursive --dry-run --no-git-checks
205206

206-
publish:
207+
publish-jsr:
207208
if: github.event_name == 'push'
208209
needs: [test, test-node, test-bun, test-cfworkers, lint, release-test]
209210
runs-on: ubuntu-latest
@@ -302,8 +303,41 @@ jobs:
302303
((attempt++))
303304
done
304305
305-
# NOTE: npm publishing is handled by build.yaml via workflow_run trigger.
306-
# Do not add npm publish steps here - it will break trusted publishing.
306+
# Trigger build.yaml via workflow_dispatch to publish to npm.
307+
# This is required because npm's trusted publishing (OIDC) validates
308+
# the directly triggered workflow, not reusable workflows called via
309+
# workflow_call. By triggering build.yaml directly, npm sees build.yaml
310+
# as the entry point and validates against it.
311+
publish-npm:
312+
if: github.event_name == 'push'
313+
needs: [publish-jsr]
314+
runs-on: ubuntu-latest
315+
permissions:
316+
actions: write
317+
steps:
318+
- name: Trigger build.yaml workflow
319+
uses: actions/github-script@v7
320+
with:
321+
script: |
322+
// Determine tag based on ref type
323+
let tag;
324+
if (context.payload.ref && context.payload.ref.startsWith('refs/tags/')) {
325+
tag = 'latest';
326+
} else {
327+
tag = 'dev';
328+
}
329+
330+
await github.rest.actions.createWorkflowDispatch({
331+
owner: context.repo.owner,
332+
repo: context.repo.repo,
333+
workflow_id: 'build.yaml',
334+
ref: context.ref,
335+
inputs: {
336+
run_id: '${{ github.run_id }}',
337+
tag: tag
338+
}
339+
});
340+
console.log(`Triggered build.yaml workflow with run_id=${{ github.run_id }}, tag=${tag}`);
307341
308342
publish-examples-blog:
309343
if: github.event_name == 'push'
@@ -324,7 +358,7 @@ jobs:
324358
root: .
325359

326360
publish-docs:
327-
needs: [publish]
361+
needs: [publish-jsr]
328362
runs-on: ubuntu-latest
329363
permissions:
330364
id-token: write
@@ -355,7 +389,7 @@ jobs:
355389
pnpm run build
356390
fi
357391
env:
358-
SHORT_VERSION: ${{ needs.publish.outputs.short_version }}
392+
SHORT_VERSION: ${{ needs.publish-jsr.outputs.short_version }}
359393
PLAUSIBLE_DOMAIN: ${{ secrets.PLAUSIBLE_DOMAIN }}
360394
STABLE_DOCS_URL: ${{ vars.STABLE_DOCS_URL }}
361395
UNSTABLE_DOCS_URL: ${{ vars.UNSTABLE_DOCS_URL }}

0 commit comments

Comments
 (0)