Repository navigation
251 lines (221 loc) · 8.27 KB
/
Copy pathpull_request.yml
File metadata and controls
251 lines (221 loc) · 8.27 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
name: Pull Request Checks
# Run this workflow every time a new pull request is opened
# and when commits are pushed to an existing PR
# References
# Cypress Parallel test kitchen sink (https://github.com/cypress-io/cypress-example-kitchensink/blob/master/.github/workflows/parallel.yml#L28)
# Cypress GH Action Parallel test blog (https://www.cypress.io/blog/2019/11/20/drastically-simplify-your-testing-with-cypress-github-action/)
on:
pull_request:
types: [opened, synchronize]
jobs:
# Set the job key. This key is displayed as the job name
# when a job name is not provided
install:
name: Install and cache dependencies
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@master
with:
# Removes credentials
persist-credentials: false
fetch-depth: 0
# Restore the previous NPM modules and Cypress binary archives.
# Any updated archives will be saved automatically after the entire
# workflow successfully finishes.
# See https://github.com/actions/cache
# we use exact restore key to avoid NPM module snowballing
# https://glebbahmutov.com/blog/do-not-let-npm-cache-snowball/
- name: Cache central NPM modules
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
# we use the exact restore key to avoid Cypress binary snowballing
# https://glebbahmutov.com/blog/do-not-let-cypress-cache-snowball/
- name: Cache Cypress binary
uses: actions/cache@v2
with:
path: ~/.cache/Cypress
key: cypress-${{ runner.os }}-cypress-${{ hashFiles('**/package.json') }}
restore-keys: |
cypress-${{ runner.os }}-cypress-
# Cache local node_modules to pass to testing jobs
- name: Cache local node_modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-modules-
- name: Install dependencies and verify Cypress
env:
# make sure every Cypress install prints minimal information
CI: 1
run: |
npx cypress cache path
npx cypress cache list
npx cypress verify
npx cypress info
yarn install --frozen-lockfile
static-analysis:
name: Static code analysis
runs-on: ubuntu-latest
needs: install
steps:
- name: Checkout code
uses: actions/checkout@master
with:
# Removes credentials
persist-credentials: false
fetch-depth: 0
- name: Cache local node_modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-modules-
# Runs actions specific script that does not fix errors
- name: Check linting
run: yarn run lint-ci
cypress-tests:
name: Run Cypress tests
runs-on: ubuntu-latest
needs: [install, static-analysis]
strategy:
matrix:
# Multiple machines are used for load balancing
machines: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
steps:
- name: Checkout code
uses: actions/checkout@master
with:
# Removes credentials
persist-credentials: false
fetch-depth: 0
# Restore just local node_modules and the Cypress binary archives.
- name: Cache Cypress binary
uses: actions/cache@v2
with:
path: ~/.cache/Cypress
key: cypress-${{ runner.os }}-cypress-${{ hashFiles('**/package.json') }}
restore-keys: |
cypress-${{ runner.os }}-cypress-
- name: Cache local node_modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-modules-
# check the restored Cypress binary
- name: Check binary
run: |
npx cypress cache path
npx cypress cache list
- name: Run Cypress tests
uses: cypress-io/github-action@v2.11.6
with:
browser: chrome
start: yarn storybook --ci
record: true
parallel: true
# tag will be either "push" or "pull_request"
tag: ${{ github.event_name }}
env:
TERM: xterm
# pass the Dashboard record key as an environment variable
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
# pass GitHub token to allow accurately detecting a build vs a re-run build
GITHUB_TOKEN: ${{ secrets.GH_ACTION_PAT }}
deployment:
name: Canary npm deployment
runs-on: ubuntu-latest
needs: [install, static-analysis, cypress-tests]
env:
# Set an environment variable for the publishing dev
# This is used in to make a unique canary release to npm
PR_DEV: ${{ github.actor }}
UUID: ''
VERSION: ''
steps:
- name: Checkout code
uses: actions/checkout@master
with:
# Removes credentials
persist-credentials: false
fetch-depth: 0
- name: Cache local node_modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-modules-
- name: Setup .npmrc file to publish to npm
uses: actions/setup-node@v1
with:
node-version: '12.x'
registry-url: 'https://registry.npmjs.org'
# This is required for publishing from GH Actions
- name: Set GitHub Action user
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Build the component library
- name: Build new package
run: yarn run build
# This is added to the canary version so each release is unique
- name: Generate UUID for canary release
id: generate-uuid
uses: filipstefansson/uuid-action@v1
with:
name: ${{ github.sha }}
- name: Set UUID to env variable
run: echo "UUID=${{ steps.generate-uuid.outputs.uuid }}" >> $GITHUB_ENV
- name: Tag canary release
run: yarn run release-canary
# Publish a new canary release to NPM
- name: Publish @f-design/component-library canary release from PR branch
run: npm publish --tag canary --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
# Extract the canary version number to post in a comment
- name: Capture new version
run: echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV
# See if the canary comment already exists
- name: Find Comment
uses: peter-evans/find-comment@v1
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Canary release
# If not, create a new comment
- name: Create comment
if: ${{ steps.fc.outputs.comment-id == 0 }}
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
Canary release :hatched_chick:
To test your changes, run the below in a test repo:
```terminal
yarn add @f-design/component-library@${{ env.VERSION }}
```
# Otherwise, update the existing comment
- name: Update comment
if: ${{ steps.fc.outputs.comment-id != 0 }}
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: 'replace'
body: |
Canary release :hatched_chick:
To test your changes, run the below in a test repo:
```terminal
yarn add @f-design/component-library@${{ env.VERSION }}
```