Repository navigation
201 lines (192 loc) · 7.13 KB
/
Copy pathangular-release.yml
File metadata and controls
201 lines (192 loc) · 7.13 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
name: Release TEDI Angular library
on:
push:
branches:
- rc
- main
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
- name: Lint
run: |
npm ci --cache .npm --prefer-offline
npm run lint
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
- name: Test
run: |
npm ci --cache .npm --prefer-offline
npm run test
# The post-merge build. This is the one that always runs, and its result is
# what the next pull request's build is compared against, so `rc` must never
# be skipped. The optional pre-merge build lives in `angular-chromatic.yml`
# and fires once per pull request, on approval.
#
# `needs: [lint, test]` is deliberate: a build that cannot pass its own tests
# is not worth 600 snapshots against a shared monthly quota.
chromatic:
needs: [lint, test]
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write # the result is posted back to the merged PR
# The `chore(release)` guard is belt and braces. semantic-release pushes
# its version commit with GITHUB_TOKEN, and a GITHUB_TOKEN push does not
# trigger workflows at all, so no such run has ever started. It would start
# mattering the day the release is moved onto a PAT or an app token.
if: |
github.event_name == 'push' &&
(github.ref == 'refs/heads/rc' || github.ref == 'refs/heads/main') &&
!startsWith(github.event.head_commit.message, 'chore(release)')
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
- name: Install dependencies
run: |
npm ci --cache .npm --prefer-offline
- name: Build Storybook
run: npm run build:sb:chromatic
# chromaui/action rather than the raw CLI: it surfaces the build result
# as step outputs (change count, build URL, capture counts), which the
# two steps below need. exitZeroOnChanges keeps the release green: a
# visual change is something to review, not a broken build.
- name: Publish to Chromatic
id: chromatic
uses: chromaui/action@v18
with:
projectToken: ${{ secrets.CHROMATIC_TOKEN }}
exitZeroOnChanges: true
# The rc build runs after the pull request merged, so its result has no
# PR to land on by default. Map the commit back to its pull request
# (this resolves correctly for squash merges) and leave a sticky comment
# there, which is the page the author was last looking at.
- name: Comment the result on the merged pull request
if: steps.chromatic.outputs.changeCount != '0' && steps.chromatic.outputs.changeCount != ''
continue-on-error: true
uses: actions/github-script@v7
env:
CHANGE_COUNT: ${{ steps.chromatic.outputs.changeCount }}
BUILD_URL: ${{ steps.chromatic.outputs.buildUrl }}
with:
script: |
const { owner, repo } = context.repo;
const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner, repo, commit_sha: context.sha,
});
const pr = prs.find((p) => p.merged_at) ?? prs[0];
if (!pr) {
core.info('No pull request is associated with this commit; nothing to comment on.');
return;
}
const marker = '<!-- chromatic-rc -->';
const branch = context.ref.replace('refs/heads/', '');
const body = [
marker,
'## 🎨 Chromatic',
'',
`${process.env.CHANGE_COUNT} visual change(s) were detected on \`${branch}\` after this pull request merged.`,
'',
`[Review and accept them](${process.env.BUILD_URL})`,
].join('\n');
const { data: comments } = await github.rest.issues.listComments({
owner, repo, issue_number: pr.number,
});
const existing = comments.find((c) => c.body?.includes(marker));
if (existing) {
await github.rest.issues.updateComment({ owner, repo, comment_id: existing.id, body });
} else {
await github.rest.issues.createComment({ owner, repo, issue_number: pr.number, body });
}
# actualCaptureCount is what is billed at 1x and inheritedCaptureCount is
# what TurboSnap copied at 0.2x, so this is the real per-build cost
# against the monthly quota rather than an estimate.
- name: Record the snapshot usage
if: always()
env:
CAPTURED: ${{ steps.chromatic.outputs.actualCaptureCount }}
INHERITED: ${{ steps.chromatic.outputs.inheritedCaptureCount }}
CHANGES: ${{ steps.chromatic.outputs.changeCount }}
ERRORS: ${{ steps.chromatic.outputs.errorCount }}
SPECS: ${{ steps.chromatic.outputs.specCount }}
BUILD_URL: ${{ steps.chromatic.outputs.buildUrl }}
run: |
{
echo "### Chromatic"
echo ""
echo "| metric | value |"
echo "| --- | --- |"
echo "| Stories | ${SPECS:-n/a} |"
echo "| Captured (billed 1x) | ${CAPTURED:-n/a} |"
echo "| Inherited via TurboSnap (billed 0.2x) | ${INHERITED:-n/a} |"
echo "| Visual changes | ${CHANGES:-n/a} |"
echo "| Errored stories | ${ERRORS:-n/a} |"
echo "| Build | ${BUILD_URL:-n/a} |"
} >> "$GITHUB_STEP_SUMMARY"
build-and-deploy:
needs: [lint, test]
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
- name: Build and publish npm package
run: |
HUSKY=0
npm ci
npm run build
git pull
npm run release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
merge-to-rc:
needs: build-and-deploy
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Merge main into rc
run: |
git fetch origin rc
git checkout rc
git merge origin/main --no-edit || true
git push origin rc