forked from vegaprotocol/frontend-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 1
243 lines (210 loc) · 7.25 KB
/
ci-cd-trigger.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
name: CI/CD
on:
push:
branches:
- release/*
pull_request:
types:
- opened
- ready_for_review
- reopened
- synchronize
jobs:
node-modules:
if: github.event.pull_request.draft == false
runs-on: ubuntu-22.04
name: 'Cache yarn modules'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- name: Setup node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: yarn
- name: Cache node modules
id: cache
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-cache-node-modules-${{ hashFiles('yarn.lock') }}
- name: yarn install
if: steps.cache.outputs.cache-hit != 'true'
run: yarn install --pure-lockfile
lint-format:
timeout-minutes: 10
needs: node-modules
runs-on: ubuntu-22.04
name: '(CI) lint + format check'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- name: Setup node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: yarn
- name: Cache node modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-cache-node-modules-${{ hashFiles('yarn.lock') }}
- name: Derive appropriate SHAs for base and head for `nx affected` commands
uses: nrwl/nx-set-shas@v4
with:
main-branch-name: develop
- name: Check formatting
run: yarn nx format:check
- name: Lint affected
run: yarn nx affected:lint --max-warnings=0
- name: Build affected spec
run: yarn nx affected --target=build-spec
test-affected:
timeout-minutes: 30
needs: build-sources
runs-on: ubuntu-22.04
name: 'run unit test of affected apps'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- name: Setup node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: yarn
- name: Cache node modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-cache-node-modules-${{ hashFiles('yarn.lock') }}
- name: Derive appropriate SHAs for base and head for `nx affected` commands
uses: nrwl/nx-set-shas@v4
with:
main-branch-name: develop
- name: Setup nx
run: yarn global add nx@latest
- name: Test affected
run: yarn nx affected:test
build-sources:
timeout-minutes: 30
needs: lint-format
runs-on: ubuntu-22.04
name: 'Build sources of affected apps'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- name: Setup node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: yarn
- name: Cache node modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-cache-node-modules-${{ hashFiles('yarn.lock') }}
- name: Derive appropriate SHAs for base and head for `nx affected` commands
uses: nrwl/nx-set-shas@v4
with:
main-branch-name: develop
# See affected apps
- name: See affected apps
run: |
branch_slug="$(echo '${{ github.head_ref || github.ref_name }}' | sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g | cut -c 1-50 )"
python3 tools/ci/check-affected.py --github-ref="${{ github.ref }}" --branch-slug="$branch_slug" --event-name="${{ github.event_name }}"
- name: Verify script result
run: |
echo "Check outputs from script"
echo "projects: ${{ env.PROJECTS }}"
echo "projects-e2e: ${{ env.PROJECTS_E2E }}"
- name: Build affected
run: yarn nx affected:build || (yarn install && yarn nx affected:build)
outputs:
projects: ${{ env.PROJECTS }}
projects-e2e: ${{ env.PROJECTS_E2E }}
# check-e2e-needed:
# runs-on: ubuntu-latest
# needs: build-sources
# name: '(CI) check if e2e needed'
# outputs:
# run-tests: ${{ steps.check-test.outputs.e2e-needed }}
# steps:
# - name: Check branch
# id: check-test
# run: |
# if [[ "${{ github.event_name }}" == "pull_request" ]]; then
# echo "e2e-needed=true" >> $GITHUB_OUTPUT
# else
# echo "e2e-needed=false" >> $GITHUB_OUTPUT
# fi
# - name: Print result
# run: |
# echo "e2e-needed: ${{ steps.check-test.outputs.e2e-needed }}"
# cypress:
# needs: [build-sources, check-e2e-needed]
# name: '(CI) cypress'
# uses: ./.github/workflows/cypress-run.yml
# secrets: inherit
# if: needs.check-e2e-needed.outputs.run-tests == 'true' && (contains(github.event.pull_request.title, 'explorer'))
# with:
# projects: ${{ needs.build-sources.outputs.projects-e2e }}
# tags: '@smoke'
publish-dist:
needs: build-sources
name: '(CD) publish dist'
if: github.event_name != 'pull_request' && ((contains(github.ref, 'release/mainnet') && !contains(github.ref, 'mirror')) || contains(github.ref, 'release/testnet') || contains(github.ref, 'release/validators-testnet') || contains(github.ref, 'release/mainnet-mirror'))
uses: ./.github/workflows/publish-dist.yml
secrets: inherit
with:
projects: ${{ needs.build-sources.outputs.projects }}
previews:
needs: build-sources
name: '(CD) previews'
if: github.event_name == 'pull_request'
uses: ./.github/workflows/previews.yml
secrets: inherit
with:
projects: ${{ needs.build-sources.outputs.projects }}
# trading-e2e:
# needs: [build-sources, check-e2e-needed]
# name: '(CI) trading e2e python'
# uses: ./.github/workflows/trading-e2e-test-run.yml
# secrets: inherit
# if: needs.check-e2e-needed.outputs.run-tests == 'true' && contains(needs.build-sources.outputs.projects, 'trading')
# with:
# github-sha: ${{ github.event.pull_request.head.sha || github.sha }}
# test-check:
# name: '(CI) Final Tests check'
# if: ${{ always() }}
# needs: [cypress, trading-e2e]
# runs-on: ubuntu-22.04
# steps:
# - name: Check Cypress Tests Result
# run: |
# result="${{ needs.cypress.result }}"
# echo "Cypress Tests Result: $result"
# if [[ $result != "success" && $result != "skipped" ]]; then
# echo "Failing due to Cypress tests."
# exit 1
# fi
# - name: Check Trading E2E Tests Result
# run: |
# result="${{ needs.trading-e2e.result }}"
# echo "Trading E2E Tests Result: $result"
# if [[ $result != "success" && $result != "skipped" ]]; then
# echo "Failing due to Trading E2E tests."
# exit 1
# fi
# - name: All Tests Passed
# run: echo "All specified tests have passed successfully."