-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
285 lines (256 loc) · 9.65 KB
/
on-pull-request.yml
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
name: on pull request
on: pull_request
env:
CACHE_PATH: |
**/node_modules
~/.cache/Cypress
YARN_CACHE_PATH: |
~/.cache/yarn/v6
FILES_TO_DELETE: |
sudo rm -rf "/usr/share/dotnet"
sudo rm -rf "/usr/share/swift"
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "/usr/local/lib/android/sdk"
sudo rm -rf "/opt/hostedtoolcache/Python"
sudo rm -rf "/opt/hostedtoolcache/go"
sudo rm -rf "/opt/hostedtoolcache/CodeQL"
sudo rm -rf "/var/lib/gems"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo apt-get clean -y
sudo apt-get autoremove -y
jobs:
# Stop previous runs
stop-previous-run:
runs-on: ubuntu-22.04
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ secrets.GITHUB_TOKEN }}
# Save necessary env variables to use them in next jobs
save-env:
runs-on: ubuntu-22.04
needs: stop-previous-run
if: always()
steps:
- name: Save env variables
id: save-env-variables
run: |
mkdir -p ./workflow
echo "${{ github.event.pull_request.number }}" > ./workflow/prNum
echo "${{ github.run_id }}" > ./workflow/runId
echo "${{ github.repository }}" > ./workflow/repoFullName
echo "${{ github.repository_owner }}" > ./workflow/ownerName
- name: Upload artifact
id: upload-artifact
uses: actions/upload-artifact@v3
with:
name: env_for_comment
path: workflow/
# Check if forked master is up to date with origin master in module federation examples repo
forked_master_status:
runs-on: ubuntu-22.04
needs: stop-previous-run
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- name: Check if forked master is up to date
id: check-forked-master
if: github.repository_owner == 'module-federation'
run: |
echo "${{ github.repository_owner }}"
git remote add base https://github.com/${{github.repository}}
git remote -v
git fetch --all
export FORKED_MASTER_SHA=$(git log -n 1 --pretty=format:"%H" origin/${{ github.event.pull_request.base.ref}})
export BASE_MASTER_SHA=$(git log -n 1 --pretty=format:"%H" base/${{ github.event.pull_request.base.ref }})
echo "$FORKED_MASTER_SHA"
echo "$BASE_MASTER_SHA"
if [ "$FORKED_MASTER_SHA" == "$BASE_MASTER_SHA" ];
then
echo "The forked master is up to date with the base master branch"
exit 0
else
echo "The forked master branch is not up to date with the base master branch, Please update your fork!"
exit 1
fi
# Setup matrix from changed samples by lerna ls --since origin/master command
setup-matrix:
runs-on: ubuntu-22.04
needs: forked_master_status
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout
id: checkout-matrix
uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- name: Create matrix
id: set-matrix
run: |
npm i lerna@6 -g
all="$(npm run list:all --silent)"
diff="$(npm run list:changed --silent)"
matrix="$(node checkChangedWorkspaces.js "$all" "$diff")"
echo "matrix=$matrix" >> $GITHUB_OUTPUT
- name: Changed workspaces
id: changed-workspaces
run: |
echo '${{ steps.set-matrix.outputs.matrix }}'
# Install main dependencies (yarn install) + Create cache for Yarn and Cypress
install-main-dependencies:
needs: setup-matrix
if: ${{ needs.setup-matrix.outputs.matrix != '{"container":[]}' }}
runs-on: ubuntu-22.04
steps:
- name: Checkout code
id: checkout-code
uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- name: Free up some space
id: free-up-space
run: ${{ env.FILES_TO_DELETE }}
# Hash yarn.lock files to use it as a cache key, if yarn.lock files are changed, the cache will be invalidated
- name: Check Yarn hash
id: check-yarn-hash
run: |
yarnHash="$(npx hash-files -f '["**/yarn.lock"]' -a sha256)"
echo "yarnHash=$yarnHash" >> $GITHUB_OUTPUT
- name: Restore Yarn Global Cache
id: restore-yarn-global-cache
uses: actions/cache/restore@v3
with:
path: |
${{ env.YARN_CACHE_PATH }}
${{ env.CACHE_PATH }}
key: yarn-global-cache-${{ steps.check-yarn-hash.outputs.yarnHash }} # Can use time based key as well
restore-keys: |
yarn-global-cache-
- name: Check disk space before install
id: check-disk-space-before-install
run: |
df -h
- name: Install dependencies
id: install-dependencies
if: steps.restore-yarn-global-cache.outputs.cache-hit != 'true'
env:
NODE_OPTIONS: "--max_old_space_size=4096"
run: |
echo "Yarn has changed - installing dependencies ... "
npm install lerna@6 -g
lerna bootstrap
- name: Cache Yarn and Cypress
if: steps.restore-yarn-global-cache.outputs.cache-hit != 'true'
id: cache-yarn-cypress
uses: actions/cache/save@v3
with:
path: |
${{ env.YARN_CACHE_PATH }}
${{ env.CACHE_PATH }}
key: yarn-global-cache-${{ steps.check-yarn-hash.outputs.yarnHash }} # Can use time based key as well
- name: Check disk space after installation
id: check-disk-space-after-installation
run: |
df -h
# Run Cypress e2e tests for changed samples (additionally install deps for all changed samples if there is no any created cache in master branch) + Create artifacts for Cypress screenshots and videos
run-e2e-test:
needs: [setup-matrix, install-main-dependencies]
if: ${{ needs.setup-matrix.outputs.matrix != '{"container":[]}' }}
runs-on: ubuntu-22.04
timeout-minutes: 30
strategy:
fail-fast: false
matrix: ${{fromJson(needs.setup-matrix.outputs.matrix)}}
steps:
- name: Checkout
id: checkout-e2e
uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- name: Free up some space
id: free-up-space-e2e
run: ${{ env.FILES_TO_DELETE }}
- name: Check disk space before install
id: check-disk-space-before-install-e2e
run: |
df -h
# Hash yarn.lock files to use it as a cache key, if yarn.lock files are changed, the cache will be invalidated
- name: Check Yarn hash
id: check-yarn-hash
run: |
yarnHash="$(npx hash-files -f '["**/yarn.lock"]' -a sha256)"
echo "yarnHash=$yarnHash" >> $GITHUB_OUTPUT
- name: Restore Yarn Global Cache
id: restore-yarn-global-cache-e2e
uses: actions/cache/restore@v3
with:
path: |
${{ env.YARN_CACHE_PATH }}
${{ env.CACHE_PATH }}
key: yarn-global-cache-${{ steps.check-yarn-hash.outputs.yarnHash }} # Can use time based key as well
restore-keys: |
yarn-global-cache
yarn-global-cache-
- name: Install deps
id: install-deps-e2e
if: steps.restore-yarn-global-cache-e2e.outputs.cache-hit != 'true'
env:
NODE_OPTIONS: "--max_old_space_size=4096"
run: |
echo "Yarn changed - install deps ... "
npm i lerna@6 -g
lerna bootstrap
- name: Install sample deps
id: install-sample-deps
# TODO Uncomment when yarn will work properly from the root and install all nessessary deps. Also please, add yarn install to the run section below instead of npx lerna exec
# if: steps.yarn-cache.outputs.cache-hit != 'true'
run: |
# npx lerna exec --stream --scope="${{ matrix.container }}*" --concurrency=1 "yarn install"
echo 'test'
- name: Cache Yarn and Cypress
if: steps.restore-yarn-global-cache-e2e.outputs.cache-hit != 'true'
id: cache-yarn-cypress
uses: actions/cache/save@v3
with:
path: |
${{ env.YARN_CACHE_PATH }}
${{ env.CACHE_PATH }}
key: yarn-global-cache-${{ steps.check-yarn-hash.outputs.yarnHash }} # Can use time based key as well
- name: Check disk space after install
id: check-disk-space-after-install-e2e
run: |
df -h
- name: Set up node
id: setup-node
uses: actions/setup-node@v3
with:
node-version: 16
- name: Run sample e2e tests
id: run-sample-e2e-tests
run: |
node -v
npx lerna run --scope=${{ matrix.container }} e2e:ci
- name: Create artifacts for Allure report
id: create-artifacts-allure-report
uses: actions/upload-artifact@v3
if: always()
with:
name: allure-results
path: 'cypress/results/allure-results'
retention-days: 7