1- name : Generate Docs
1+ name : Generate and Compare Docs
22
33on :
44 push :
@@ -15,8 +15,62 @@ 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+ ID=$(gh run list --repo $GITHUB_REPOSITORY -c $BASE_SHA -w 174604400 -L 1 --json databaseId --jq ".[].databaseId")
55+ echo "run_id=$ID" >> $GITHUB_OUTPUT
56+
57+ - name : Download metadata artifact
58+ if : ${{ github.event_name == 'pull_request' }}
59+ uses : actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
60+ with :
61+ name : commit
62+ run-id : ${{ steps.main.outputs.run_id }}
63+ github-token : ${{ secrets.GITHUB_TOKEN }}
64+
65+ - id : pr
66+ if : ${{ github.event_name == 'pull_request' }}
67+ run : |
68+ SHA=$(cat commit)
69+ echo "sha=$SHA" >> "$GITHUB_OUTPUT"
70+
1871 generate :
1972 runs-on : ubuntu-latest
73+ needs : prepare
2074 strategy :
2175 matrix :
2276 include :
@@ -32,10 +86,12 @@ jobs:
3286 input : ' ./node/doc/api/*.md'
3387 - target : legacy-json
3488 input : ' ./node/doc/api/*.md'
89+ compare : true
3590 - target : legacy-html
3691 input : ' ./node/doc/api/*.md'
3792 - target : web
3893 input : ' ./node/doc/api/*.md'
94+ compare : true
3995 - target : llms-txt
4096 input : ' ./node/doc/api/*.md'
4197 fail-fast : false
56112 with :
57113 persist-credentials : false
58114 repository : nodejs/node
115+ ref : ${{ needs.prepare.outputs.sha }}
59116 sparse-checkout : |
60117 doc/api
61118 lib
@@ -79,13 +136,27 @@ jobs:
79136 node bin/cli.mjs generate \
80137 -t ${{ matrix.target }} \
81138 -i "${{ matrix.input }}" \
82- -o " out/${{ matrix.target }}" \
139+ -o out \
83140 -c ./node/CHANGELOG.md \
84141 --index ./node/doc/api/index.md \
85142 --log-level debug
86143
144+ - name : Download base branch artifact
145+ if : ${{ matrix.compare && needs.prepare.outputs.base-run }}
146+ uses : actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
147+ with :
148+ name : ${{ matrix.target }}
149+ path : base
150+ run-id : ${{ needs.prepare.outputs.base-run }}
151+ github-token : ${{ secrets.GITHUB_TOKEN }}
152+
153+ - name : Compare to base branch
154+ if : ${{ matrix.compare && needs.prepare.outputs.base-run }}
155+ run : |
156+ node scripts/compare-builds/${{ matrix.target }}.mjs > out/comparison.txt
157+
87158 - name : Upload ${{ matrix.target }} artifacts
88159 uses : actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
89160 with :
90161 name : ${{ matrix.target }}
91- path : out/${{ matrix.target }}
162+ path : out
0 commit comments