Skip to content

Commit 6a37f2b

Browse files
bakkotljharb
authored andcommitted
Meta: fix PR previews (#3679)
1 parent f92c1ae commit 6a37f2b

File tree

7 files changed

+119
-416
lines changed

7 files changed

+119
-416
lines changed

.github/workflows/pr-preview.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: 'ecma262'
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, synchronize, reopened, labeled]
6+
7+
jobs:
8+
check-membership:
9+
name: 'check membership'
10+
runs-on: ubuntu-22.04
11+
outputs:
12+
result: ${{ steps.test-membership.outputs.result }}
13+
should-run: ${{ steps.should-run.outputs.result }}
14+
steps:
15+
- uses: actions/github-script@v7
16+
id: should-run
17+
with:
18+
result-encoding: string
19+
script: |
20+
const { action, label } = context.payload;
21+
22+
// Run on opened/synchronize for members, or when 'request preview' label is added
23+
if (action === 'labeled' && label?.name === 'request preview') {
24+
return 'yes';
25+
} else if (action === 'opened' || action === 'synchronize' || action === 'reopened') {
26+
return 'check-membership';
27+
}
28+
return 'no';
29+
30+
- uses: actions/github-script@v7
31+
id: test-membership
32+
if: steps.should-run.outputs.result == 'check-membership'
33+
env:
34+
AUTHOR: ${{ github.event.pull_request.user.login }}
35+
with:
36+
result-encoding: string
37+
script: |
38+
const author = process.env.AUTHOR;
39+
if (author === 'jmdyck') return 'yes';
40+
try {
41+
const result = await github.request('GET /orgs/{org}/members/{username}', {
42+
org: 'tc39',
43+
username: author,
44+
headers: {
45+
'X-GitHub-Api-Version': '2022-11-28'
46+
}
47+
});
48+
return 'yes';
49+
} catch (e) {
50+
console.log({ author }, e);
51+
return 'no';
52+
}
53+
- run: echo "${{steps.test-membership.outputs.result}}"
54+
55+
build:
56+
name: 'publish PR preview'
57+
runs-on: ubuntu-22.04
58+
needs: check-membership
59+
if: needs.check-membership.outputs.should-run == 'yes' || (needs.check-membership.outputs.should-run == 'check-membership' && needs.check-membership.outputs.result == 'yes')
60+
61+
permissions:
62+
contents: write
63+
pull-requests: write
64+
65+
steps:
66+
- name: Remove 'request preview' label
67+
if: github.event.action == 'labeled' && github.event.label.name == 'request preview'
68+
uses: actions/github-script@v7
69+
with:
70+
script: |
71+
await github.rest.issues.removeLabel({
72+
owner: context.repo.owner,
73+
repo: context.repo.repo,
74+
issue_number: context.issue.number,
75+
name: 'request preview'
76+
});
77+
78+
- uses: actions/checkout@v4
79+
- uses: ljharb/actions/node/install@7f214d8efdbdcefc96ad9689663ef387a195deec
80+
name: 'nvm install lts/* && npm ci --no-audit'
81+
env:
82+
NPM_CONFIG_AUDIT: false
83+
with:
84+
node-version: lts/*
85+
use-npm-ci: true
86+
- run: npm run build-only
87+
- run: node scripts/insert_snapshot_warning
88+
- run: ./scripts/auto-deploy.sh --pr ${{ github.event.number }}
89+
env:
90+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
91+
- id: get-preview-url
92+
name: Get preview url
93+
run: |
94+
gh_pages_url="https://$(printf '%s' "$GITHUB_REPOSITORY" \
95+
| sed 's#/#.github.io/#; s#^tc39.github.io/#tc39.es/#')"
96+
echo "url=$gh_pages_url" >> $GITHUB_OUTPUT
97+
- name: Post preview comment
98+
uses: phulsechinmay/[email protected]
99+
with:
100+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
101+
COMMENT_IDENTIFIER: tc39_pr_preview_comment
102+
message: |
103+
The rendered spec for this PR is available at ${{ steps.get-preview-url.outputs.url }}/pr/${{ github.event.number }}.

.github/workflows/preview-build.yml

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

.github/workflows/preview.yml

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

0 commit comments

Comments
 (0)