-
Notifications
You must be signed in to change notification settings - Fork 1
188 lines (160 loc) · 6.55 KB
/
test-deploy-environment.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
name: Test and deploy environment
on:
workflow_dispatch:
push:
branches-ignore:
- main
- production
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
env_name: ${{ steps.env_name.outputs.env_name }}
build_matrix: ${{ steps.config.outputs.build }}
deploy_matrix: ${{ steps.config.outputs.deploy }}
test_matrix: ${{ steps.config.outputs.test }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
fetch-depth: 0
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20.17"
- name: Get environment name
id: env_name
working-directory: devops/scripts
run: |
env_name=$(node get-environment-name.js ${{ github.ref_name }})
echo "env_name: $env_name"
echo "env_name=$env_name" >> $GITHUB_OUTPUT
- name: Get matrices configuration
id: config
run: |
# BUILD MATRIX
echo "[]" \
| jq '. + [{name:"api", tag:$tag}]' --arg tag "$(git log --max-count=1 --oneline -- api packages/lib package-lock.json | cut -d " " -f 1)" \
| jq '. + [{name:"apiv2", tag:$tag}]' --arg tag "$(git log --max-count=1 --oneline -- apiv2 packages/lib package-lock.json | cut -d " " -f 1)" \
| jq '. + [{name:"app", tag:$tag}]' --arg tag "$(git log --max-count=1 --oneline -- app packages package-lock.json | cut -d " " -f 1)" \
| jq '. + [{name:"admin", tag:$tag}]' --arg tag "$(git log --max-count=1 --oneline -- admin packages package-lock.json | cut -d " " -f 1)" > build.json
echo "Build matrix"
cat build.json
echo "build=$(jq -c < build.json)" >> $GITHUB_OUTPUT
# DEPLOY MATRIX
cat build.json > deploy.json
echo "Deploy matrix"
cat deploy.json
echo "deploy=$(jq -c < deploy.json)" >> $GITHUB_OUTPUT
# TEST MATRIX
git switch main
echo "[]" \
| jq '. + [{name:"api", run_test:$tag}]' --arg tag "$(git log --max-count=1 --oneline main..${{ github.ref_name }} -- api packages/lib package-lock.json | cut -d " " -f 1)" \
| jq '. + [{name:"apiv2", run_test:$tag}]' --arg tag "$(git log --max-count=1 --oneline main..${{ github.ref_name }} -- apiv2 packages/lib package-lock.json | cut -d " " -f 1)" \
| jq '. + [{name:"app", run_test:$tag}]' --arg tag "$(git log --max-count=1 --oneline main..${{ github.ref_name }} -- app packages package-lock.json | cut -d " " -f 1)" \
| jq '. + [{name:"admin", run_test:$tag}]' --arg tag "$(git log --max-count=1 --oneline main..${{ github.ref_name }} -- admin packages package-lock.json | cut -d " " -f 1)" \
| jq '. + [{name:"lib", run_test:$tag}]' --arg tag "$(git log --max-count=1 --oneline main..${{ github.ref_name }} -- packages package-lock.json | cut -d " " -f 1)" > test.json
echo "Test matrix"
cat test.json
echo "test=$(jq -c < test.json)" >> $GITHUB_OUTPUT
test:
needs: prepare
runs-on: ubuntu-latest
strategy:
matrix:
app: ${{ fromJSON(needs.prepare.outputs.test_matrix) }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
- name: Run tests
uses: jenseng/dynamic-uses@v1
if: ${{matrix.app.run_test}}
with:
uses: ./.github/actions/run-tests-${{matrix.app.name}}
with: '{"branch_name": "${{ github.ref_name }}", "CC_TEST_REPORTER_ID": "${{ secrets.CC_TEST_REPORTER_ID }}" }'
create_environment:
if: |
!(contains(github.ref_name, '-no-ci-') ||
startsWith(github.ref_name, 'no-ci-') ||
endsWith(github.ref_name, 'no-ci') ||
contains(github.ref_name, '_no_ci_') ||
startsWith(github.ref_name, 'no_ci_') ||
endsWith(github.ref_name, '_no_ci') ||
startsWith(github.ref_name, 'renovate') ||
startsWith(github.ref_name, 'gh-readonly-')
)
needs: prepare
runs-on: ubuntu-latest
outputs:
registry: ${{ steps.registry.outputs.registry }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20.17"
- name: Create environment
id: registry
working-directory: devops/scripts
env:
SCW_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }}
SCW_SECRET_KEY: ${{ secrets.SCW_CI_DEPLOY_SECRET_KEY }}
run: |
node create-environment.js ${{ needs.prepare.outputs.env_name }}
registry=$(node get-environment-registry.js ${{ needs.prepare.outputs.env_name }})
echo "registry: $registry"
echo "registry=$registry" >> $GITHUB_OUTPUT
build:
needs: [prepare, create_environment]
runs-on: ubuntu-latest
strategy:
matrix:
app: ${{ fromJSON(needs.prepare.outputs.build_matrix) }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
- name: Login to Docker Container Registry
uses: docker/login-action@v2
with:
username: nologin
password: ${{ secrets.SCW_CI_DEPLOY_SECRET_KEY }}
registry: ${{ needs.create_environment.outputs.registry }}
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20.17"
- name: Build image
working-directory: devops/scripts
env:
SCW_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }}
SCW_SECRET_KEY: ${{ secrets.SCW_CI_DEPLOY_SECRET_KEY }}
run: |
node build-application-docker.js --push ${{ needs.prepare.outputs.env_name }} ${{matrix.app.name}} ${{matrix.app.tag}}
deploy:
needs: [prepare, build]
runs-on: ubuntu-latest
strategy:
matrix:
app: ${{ fromJSON(needs.prepare.outputs.deploy_matrix) }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20.17"
- name: Deploy image on Scaleway
working-directory: devops/scripts
env:
SCW_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID }}
SCW_SECRET_KEY: ${{ secrets.SCW_CI_DEPLOY_SECRET_KEY }}
run: |
node deploy-scaleway.js ${{ needs.prepare.outputs.env_name }} ${{matrix.app.name}} ${{matrix.app.tag}}