Repository navigation
165 lines (143 loc) · 6.06 KB
/
Copy pathbuild.yml
File metadata and controls
165 lines (143 loc) · 6.06 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
name: Build
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]
push:
branches: [main]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
# A newer push to a pull request supersedes its run; a push to main always finishes, so the
# badges never show a cancelled run as failing.
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: read
jobs:
build:
name: Build
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Setup
uses: ./.github/actions/setup
- name: Run build
run: vp run build
- name: Upload build artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: dist
path: dist
tree-shaking:
name: Tree-shaking report
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout head
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Setup
uses: ./.github/actions/setup
- name: Checkout base
if: ${{ github.event_name == 'pull_request' }}
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
path: base
ref: ${{ github.event.pull_request.base.sha }}
persist-credentials: false
- name: Build head
run: npm ci && npm run build
- name: Measure base
if: ${{ github.event_name == 'pull_request' }}
id: base
run: |
if [ ! -f base/scripts/tree-shaking.ts ]; then
echo "measured=false" >> "$GITHUB_OUTPUT"
exit 0
fi
node scripts/tree-shaking.ts --json head.json
(cd base && npm ci && npm run build && node scripts/tree-shaking.ts --json ../base.json --surviving ../head.json)
echo "measured=true" >> "$GITHUB_OUTPUT"
- name: Compare against base
if: ${{ github.event_name == 'pull_request' }}
id: compare
continue-on-error: true
run: |
if [ "${{ steps.base.outputs.measured }}" = "true" ]; then
code=2
echo "code=$code" >> "$GITHUB_OUTPUT"
set +e
node scripts/tree-shaking.ts --compare base.json --markdown tree-shaking.md
code=$?
set -e
case "$code" in 0 | 1) ;; *) code=2 ;; esac
echo "code=$code" >> "$GITHUB_OUTPUT"
exit "$code"
else
{
echo "## Tree-shaking report"
echo
echo "No base measurement available (the base branch has no \`scripts/tree-shaking.ts\`, or an incompatible version). Showing head sizes only."
echo
printf '%s\n' "\`\`\`"
node scripts/tree-shaking.ts
printf '%s\n' "\`\`\`"
} > tree-shaking.md
fi
- name: Add report marker
if: ${{ github.event_name == 'pull_request' }}
run: |
if [ ! -f tree-shaking.md ]; then
printf '## Tree-shaking report\n\nThe measurement step failed before producing a report. See the job log.\n' > tree-shaking.md
fi
sed -i '1i<!-- tree-shaking-report -->' tree-shaking.md
if [ "${{ steps.compare.outputs.code }}" = "2" ]; then
printf '\n> The comparison itself failed (see the job log); the "tree-shaking: accepted" label does not cover this.\n' >> tree-shaking.md
elif [ "${{ steps.compare.outcome }}" = "failure" ]; then
if [ "${{ contains(github.event.pull_request.labels.*.name, 'tree-shaking: accepted') }}" = "true" ]; then
printf '\n> Regression accepted through the "tree-shaking: accepted" label.\n' >> tree-shaking.md
else
printf '\n> To accept an intentional size increase, add the "tree-shaking: accepted" label to this pull request.\n' >> tree-shaking.md
fi
fi
- name: Find existing comment
if: ${{ github.event_name == 'pull_request' && !github.event.pull_request.head.repo.fork }}
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: "<!-- tree-shaking-report -->"
- name: Post or update comment
if: ${{ github.event_name == 'pull_request' && !github.event.pull_request.head.repo.fork }}
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
edit-mode: replace
body-path: tree-shaking.md
- name: Summarize tree-shaking for fork pull requests
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork }}
run: cat tree-shaking.md >> "$GITHUB_STEP_SUMMARY"
- name: Fail on regression
if: "${{ github.event_name == 'pull_request' && steps.compare.outcome == 'failure' && steps.compare.outputs.code != '2' && !contains(github.event.pull_request.labels.*.name, 'tree-shaking: accepted') }}"
run: exit 1
- name: Fail when the comparison itself failed
if: "${{ github.event_name == 'pull_request' && steps.compare.outputs.code == '2' }}"
run: exit 1
- name: Summarize tree-shaking
if: ${{ github.event_name == 'push' }}
run: |
{
echo "## Tree-shaking report"
echo
printf '%s\n' "\`\`\`"
node scripts/tree-shaking.ts
printf '%s\n' "\`\`\`"
} >> "$GITHUB_STEP_SUMMARY"