Skip to content

Commit 699c9cc

Browse files
committed
[wip] more comparisons
1 parent 9ddf8f9 commit 699c9cc

File tree

5 files changed

+169
-257
lines changed

5 files changed

+169
-257
lines changed

.github/workflows/compare-builds.yml

Lines changed: 0 additions & 130 deletions
This file was deleted.

.github/workflows/generate.yml

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Generate Docs
1+
name: Generate and Compare Docs
22

33
on:
44
push:
@@ -15,8 +15,62 @@ permissions:
1515
contents: read
1616

1717
jobs:
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
@@ -56,6 +112,7 @@ jobs:
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
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Compare Build Outputs
2+
3+
on:
4+
workflow_run:
5+
workflows: ['Generate Docs']
6+
types: [completed]
7+
8+
permissions:
9+
contents: read
10+
actions: read
11+
pull-requests: write
12+
13+
jobs:
14+
aggregate:
15+
name: Aggregate Comparison Results
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Harden Runner
19+
uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
20+
with:
21+
egress-policy: audit
22+
23+
- name: Download all comparison artifacts
24+
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
25+
with:
26+
run-id: ${{ github.event.workflow_run.id }}
27+
github-token: ${{ secrets.GITHUB_TOKEN }}
28+
path: results
29+
30+
- name: Combine results
31+
id: combine
32+
run: |
33+
shopt -s nullglob
34+
result_files=(results/*/comparison.txt)
35+
36+
if ((${#result_files[@]})); then
37+
{
38+
echo "combined<<EOF"
39+
cat "${result_files[@]}"
40+
echo "EOF"
41+
} >> "$GITHUB_OUTPUT"
42+
fi
43+
44+
- name: Add Comment to PR
45+
if: steps.combine.outputs.combined
46+
uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3.0.1
47+
with:
48+
comment-tag: compared
49+
message: ${{ steps.combine.outputs.combined }}
50+
pr-number: ${{ github.event.workflow_run.pull_requests[0].number }}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('todo');

0 commit comments

Comments
 (0)