Skip to content

Commit beea7c6

Browse files
committed
Meta: Publish the rendered spec for PRs
1 parent d96dae0 commit beea7c6

File tree

5 files changed

+124
-38
lines changed

5 files changed

+124
-38
lines changed

.github/workflows/build.yml

-15
This file was deleted.

.github/workflows/deploy.yml

-23
This file was deleted.

.github/workflows/publish-main.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- name: '[node LTS] npm install'
13+
uses: ljharb/actions/node/install@main
14+
with:
15+
node-version: lts/*
16+
- run: npm run build
17+
- name: publish to gh-pages
18+
uses: JamesIves/[email protected]
19+
with:
20+
branch: gh-pages
21+
folder: build
22+
clean-exclude: |
23+
pr

.github/workflows/publish-pr.yml

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Publish PR
2+
3+
on:
4+
workflow_run:
5+
workflows: ['Render PR']
6+
types: [completed]
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
if: >
12+
${{
13+
!github.event.repository.fork &&
14+
github.event.workflow_run.event == 'pull_request' &&
15+
github.event.workflow_run.conclusion == 'success'
16+
}}
17+
steps:
18+
- name: print event info
19+
uses: actions/github-script@v7
20+
with:
21+
script: 'console.log(${{ toJson(github.event) }});'
22+
- name: download zipball
23+
uses: actions/github-script@v7
24+
with:
25+
script: |
26+
const { owner, repo } = context.repo;
27+
const { total_count, artifacts } = await github.actions.listWorkflowRunArtifacts({
28+
owner,
29+
repo,
30+
run_id: ${{ github.event.workflow_run.id }},
31+
name: 'result',
32+
});
33+
if (total_count !== 1) {
34+
const summary = artifacts?.map(artifact => {
35+
const { name, size_in_bytes, url } = artifact;
36+
return { name, size_in_bytes, url };
37+
});
38+
const repr = value => JSON.stringify(value);
39+
throw Error(`Expected 1 artifact, got ${total_count} ${repr(summary ?? [])}`);
40+
}
41+
const artifactData = {
42+
owner,
43+
repo,
44+
artifact_id: artifacts[0].id,
45+
archive_format: 'zip',
46+
};
47+
const download = await github.actions.downloadArtifact(artifactData);
48+
const fs = require('fs');
49+
fs.writeFileSync('${{ github.workspace }}/result.zip', Buffer.from(download.data));
50+
- name: provide result directory
51+
run: rmdir -rf result && mkdir -p result
52+
- run: unzip -o result.zip -d result
53+
- run: ls result
54+
- name: extract PR number
55+
id: extract-pr-number
56+
run: |
57+
cd result
58+
awk -vok=1 \
59+
'{ print; if(!match($0, /^[1-9][0-9]*$/)) ok=0; } END { exit !(NR==1 && ok); }' \
60+
pr-number.txt
61+
echo "number=$(cat pr-number.txt)" >> $GITHUB_OUTPUT
62+
rm pr-number.txt
63+
- name: publish to gh-pages
64+
uses: JamesIves/[email protected]
65+
with:
66+
branch: gh-pages
67+
folder: result
68+
target-folder: pr/${{ steps.extract-pr-number.outputs.number }}
69+
- name: determine gh-pages url
70+
id: get-pages-url
71+
run: |
72+
gh_pages_url="https://$(printf '%s' "$GITHUB_REPOSITORY" \
73+
| sed 's#/#.github.io/#; s#^tc39.github.io/#tc39.es/#')"
74+
echo "url=$gh_pages_url" >> $GITHUB_OUTPUT
75+
- name: provide comment
76+
uses: phulsechinmay/[email protected]
77+
with:
78+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79+
message: |
80+
The rendered spec for this PR is available at ${{ steps.get-pages-url.outputs.url }}.

.github/workflows/render-pr.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Render PR
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
render:
7+
runs-on: ubuntu-latest
8+
if: ${{ github.event.pull_request }}
9+
steps:
10+
- uses: actions/checkout@v4
11+
- name: '[node LTS] npm install'
12+
uses: ljharb/actions/node/install@main
13+
with:
14+
node-version: lts/*
15+
- run: npm run build
16+
- run: echo ${{ github.event.number }} > build/pr-number.txt
17+
- uses: actions/upload-artifact@v4
18+
if: ${{ !github.event.repository.fork }}
19+
with:
20+
name: result
21+
path: build/

0 commit comments

Comments
 (0)