Repository navigation
93 lines (80 loc) · 2.91 KB
/
Copy pathdist-sync.yml
File metadata and controls
93 lines (80 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: Sync generated dist
on:
pull_request_target:
types: [opened, synchronize, reopened]
permissions:
contents: read
pull-requests: read
jobs:
build-dist:
name: Build dist without write credentials
runs-on: ubuntu-latest
steps:
# Checkout the PR merge ref as data only. This job has no write token,
# so scripts supplied by an untrusted PR cannot modify the repository.
- uses: actions/checkout@v4
with:
ref: refs/pull/${{ github.event.pull_request.number }}/merge
persist-credentials: false
- name: Read Node version from mise.toml
id: node
run: echo "version=$(grep -E '^node\s*=' mise.toml | sed -E 's/.*\"([^\"]+)\".*/\1/')" >> "$GITHUB_OUTPUT"
- name: Install package manager
run: |
corepack enable
corepack install
- uses: actions/setup-node@v6
with:
node-version: ${{ steps.node.outputs.version }}
- name: Install dependencies
run: yarn install --immutable
- name: Build action bundle
run: yarn build
- name: Upload generated bundle
uses: actions/upload-artifact@v4
with:
name: generated-dist
path: dist/
if-no-files-found: error
retention-days: 1
commit-dist:
name: Commit dist for same-repository PRs
needs: build-dist
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: read
steps:
# Checkout the target branch, not PR code, in the job that has write
# permission. All PR-controlled code runs only in build-dist above.
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
persist-credentials: true
- name: Download generated bundle
uses: actions/download-artifact@v4
with:
name: generated-dist
path: dist
- name: Validate generated bundle paths
run: |
test -f dist/index.js
test -f dist/index.js.map
test -f dist/licenses.txt
test -f dist/sourcemap-register.js
if find dist -mindepth 1 -maxdepth 1 ! -name 'index.js' ! -name 'index.js.map' ! -name 'licenses.txt' ! -name 'sourcemap-register.js' | grep -q .; then
echo 'Artifact contains unexpected files' >&2
exit 1
fi
- name: Commit generated bundle
env:
PR_BRANCH: ${{ github.event.pull_request.head.ref }}
run: |
git add -- dist/index.js dist/index.js.map dist/licenses.txt
if ! git diff --cached --quiet; then
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
git commit -m "chore: update generated dist"
git push origin "HEAD:${PR_BRANCH}"
fi