1- name : Generate Docs
1+ name : Generate and Compare Docs
22
33on :
44 push :
@@ -15,8 +15,64 @@ permissions:
1515 contents : read
1616
1717jobs :
18+ prepare :
19+ runs-on : ubuntu-latest
20+ outputs :
21+ sha : ${{ steps.push.outputs.sha || steps.pr.outputs.sha }}
22+ base-run : ${{ steps.main.outputs.run_id }}
23+ steps :
24+ - name : Harden Runner
25+ uses : step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
26+ with :
27+ egress-policy : audit
28+
29+ # If we are running from the main branch (a non-pull_request event), we
30+ # want the latest SHA from nodejs/node
31+ - id : push
32+ if : ${{ github.event_name != 'pull_request' }}
33+ run : |
34+ SHA=$(git ls-remote https://github.com/nodejs/node.git HEAD | awk '{print $1}')
35+ echo "$SHA" > commit
36+ echo "sha=$SHA" >> "$GITHUB_OUTPUT"
37+
38+ - name : Upload metadata artifact
39+ if : ${{ github.event_name != 'pull_request' }}
40+ uses : actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
41+ with :
42+ name : commit
43+ path : commit
44+
45+ # If we are running from a PR (a pull_request event), we
46+ # want the SHA used by the most recent `push` run
47+ - name : Get latest `main` run
48+ if : ${{ github.event_name == 'pull_request' }}
49+ id : main
50+ env :
51+ BASE_SHA : ${{ github.event.pull_request.base.sha }}
52+ GH_TOKEN : ${{ github.token }}
53+ run : |
54+ # `174604400` refers to `generate.yml`'s workflow ID, available at https://api.github.com/repos/nodejs/doc-kit/actions/workflows/generate.yml
55+ # The `databaseId` is a given runs run ID (Ref: https://docs.github.com/en/enterprise-cloud@latest/graphql/reference/objects#workflowrun)
56+ ID=$(gh run list --repo $GITHUB_REPOSITORY -c $BASE_SHA -w 174604400 -L 1 --json databaseId --jq ".[].databaseId")
57+ echo "run_id=$ID" >> $GITHUB_OUTPUT
58+
59+ - name : Download metadata artifact
60+ if : ${{ github.event_name == 'pull_request' }}
61+ uses : actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
62+ with :
63+ name : commit
64+ run-id : ${{ steps.main.outputs.run_id }}
65+ github-token : ${{ secrets.GITHUB_TOKEN }}
66+
67+ - id : pr
68+ if : ${{ github.event_name == 'pull_request' }}
69+ run : |
70+ SHA=$(cat commit)
71+ echo "sha=$SHA" >> "$GITHUB_OUTPUT"
72+
1873 generate :
1974 runs-on : ubuntu-latest
75+ needs : prepare
2076 strategy :
2177 matrix :
2278 include :
@@ -32,10 +88,12 @@ jobs:
3288 input : ' ./node/doc/api/*.md'
3389 - target : legacy-json
3490 input : ' ./node/doc/api/*.md'
91+ compare : true
3592 - target : legacy-html
3693 input : ' ./node/doc/api/*.md'
3794 - target : web
3895 input : ' ./node/doc/api/*.md'
96+ compare : true
3997 - target : llms-txt
4098 input : ' ./node/doc/api/*.md'
4199 fail-fast : false
56114 with :
57115 persist-credentials : false
58116 repository : nodejs/node
117+ ref : ${{ needs.prepare.outputs.sha }}
59118 sparse-checkout : |
60119 doc/api
61120 lib
@@ -79,13 +138,27 @@ jobs:
79138 node bin/cli.mjs generate \
80139 -t ${{ matrix.target }} \
81140 -i "${{ matrix.input }}" \
82- -o " out/${{ matrix.target }}" \
141+ -o out \
83142 -c ./node/CHANGELOG.md \
84143 --index ./node/doc/api/index.md \
85144 --log-level debug
86145
146+ - name : Download base branch artifact
147+ if : ${{ matrix.compare && needs.prepare.outputs.base-run }}
148+ uses : actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
149+ with :
150+ name : ${{ matrix.target }}
151+ path : base
152+ run-id : ${{ needs.prepare.outputs.base-run }}
153+ github-token : ${{ secrets.GITHUB_TOKEN }}
154+
155+ - name : Compare to base branch
156+ if : ${{ matrix.compare && needs.prepare.outputs.base-run }}
157+ run : |
158+ node scripts/compare-builds/${{ matrix.target }}.mjs > out/comparison.txt
159+
87160 - name : Upload ${{ matrix.target }} artifacts
88161 uses : actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
89162 with :
90163 name : ${{ matrix.target }}
91- path : out/${{ matrix.target }}
164+ path : out
0 commit comments