Skip to content

Meta: Publish the rendered spec for PRs #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .github/workflows/build.yml

This file was deleted.

23 changes: 0 additions & 23 deletions .github/workflows/deploy.yml

This file was deleted.

23 changes: 23 additions & 0 deletions .github/workflows/publish-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Publish

on:
push:
branches: [main]

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: '[node LTS] npm install'
uses: ljharb/actions/node/install@main
with:
node-version: lts/*
- run: npm run build
- name: Publish to gh-pages
uses: JamesIves/[email protected]
with:
branch: gh-pages
folder: build
clean-exclude: |
pr
80 changes: 80 additions & 0 deletions .github/workflows/publish-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Publish PR

on:
workflow_run:
workflows: ['Render PR']
types: [completed]

jobs:
publish:
runs-on: ubuntu-latest
if: >
${{
!github.event.repository.fork &&
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
}}
steps:
- name: Print event info
uses: actions/github-script@v7
with:
script: 'console.log(${{ toJson(github.event) }});'
- name: Download zipball
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const { total_count, artifacts } = await github.actions.listWorkflowRunArtifacts({
owner,
repo,
run_id: ${{ github.event.workflow_run.id }},
name: 'result',
});
if (total_count !== 1) {
const summary = artifacts?.map(artifact => {
const { name, size_in_bytes, url } = artifact;
return { name, size_in_bytes, url };
});
const repr = value => JSON.stringify(value);
throw Error(`Expected 1 artifact, got ${total_count} ${repr(summary ?? [])}`);
}
const artifactData = {
owner,
repo,
artifact_id: artifacts[0].id,
archive_format: 'zip',
};
const download = await github.actions.downloadArtifact(artifactData);
const fs = require('fs');
fs.writeFileSync('${{ github.workspace }}/result.zip', Buffer.from(download.data));
- name: Provide result directory
run: rmdir -rf result && mkdir -p result
- run: unzip -o result.zip -d result
- run: ls result
- name: Extract PR number
id: extract-pr-number
run: |
cd result
awk -vok=1 \
'{ print; if(!match($0, /^[1-9][0-9]*$/)) ok=0; } END { exit !(NR==1 && ok); }' \
pr-number.txt
echo "number=$(cat pr-number.txt)" >> $GITHUB_OUTPUT
rm pr-number.txt
- name: Publish to gh-pages
uses: JamesIves/[email protected]
with:
branch: gh-pages
folder: result
target-folder: pr/${{ steps.extract-pr-number.outputs.number }}
- name: Determine gh-pages url
id: get-pages-url
run: |
gh_pages_url="https://$(printf '%s' "$GITHUB_REPOSITORY" \
| sed 's#/#.github.io/#; s#^tc39.github.io/#tc39.es/#')"
echo "url=$gh_pages_url" >> $GITHUB_OUTPUT
- name: Provide PR comment
uses: phulsechinmay/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
message: |
The rendered spec for this PR is available at ${{ steps.get-pages-url.outputs.url }}.
22 changes: 22 additions & 0 deletions .github/workflows/render-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Render PR

on: [pull_request]

jobs:
render:
runs-on: ubuntu-latest
if: ${{ github.event.pull_request }}
steps:
- uses: actions/checkout@v4
- name: '[node LTS] npm install'
uses: ljharb/actions/node/install@main
with:
node-version: lts/*
- run: npm run build
- name: Save PR number
run: echo ${{ github.event.number }} > build/pr-number.txt
- uses: actions/upload-artifact@v4
if: ${{ !github.event.repository.fork }}
with:
name: result
path: build/
Loading