-
Notifications
You must be signed in to change notification settings - Fork 2
308 lines (308 loc) · 12.8 KB
/
releases.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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
name: CI at Devel Branch
run-name: ${{ github.actor }} is deploying at devel branch 🚀
on:
push:
branches:
- develop
env:
RELEASE_ID: rc-${{ github.ref_name }}-${{ github.run_id }}
NODE_VERSION: 16.x
jobs:
configure:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout to repository
uses: actions/checkout@v3
with:
repository: 'grnet/rciam-deploy-inv'
ref: 'master'
ssh-key: ${{ secrets.DEPLOY_READ_SECRET }}
path: 'inventory'
- name: Set matrix data
id: set-matrix
working-directory: inventory/rciam-metrics-dev/files/all/tenants
# https://www.jitsejan.com/use-github-actions-with-json-file-as-matrix
run: |
ls
cat ./config.json
echo "matrix=$(jq -c . < ./config.json)" >> $GITHUB_OUTPUT
checkout:
runs-on: ubuntu-latest
needs: configure
strategy:
matrix: ${{ fromJson(needs.configure.outputs.matrix) }}
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref_name }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v3
with:
path: 'metrics-app-${{matrix.tenant}}'
ref: 'develop'
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "💡 The ${{ github.sha }} commit processing started."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- name: Download playbook
uses: actions/checkout@v3
with:
# Repository name with owner. For example, actions/checkout
# Default: ${{ github.repository }}
repository: 'rciam/rciam-deploy'
ref: 'devel'
path: 'roles'
- name: Download inventory
uses: actions/checkout@v3
with:
repository: 'grnet/rciam-deploy-inv'
ref: 'master'
ssh-key: ${{ secrets.DEPLOY_READ_SECRET }}
path: 'inventory'
- name: Run playbook (create react_config file)
uses: dawidd6/action-ansible-playbook@v2
with:
# Required, playbook filepath
playbook: metricsservers.yml
# Optional, directory where playbooks live
directory: ./roles
key: ${{ secrets.DEPLOY_READ_SECRET }}
# Optional, encrypted vault password
vault_password: ${{secrets.VAULT_PASSWORD_DEVEL}}
options: |
--inventory ${{ github.workspace }}/inventory/rciam-metrics-dev/hosts.ini
--tags rciam-metrics:config-local
-u debian
- name: List files in the repository
# The tenant specific config file, i.e. config.tenant.environment.json, becomes plain config.json
# because the frontend lives under its own directory/path
run: |
ls -la ${{ github.workspace }}/inventory/rciam-metrics-dev/files
- name: Move tenant config file to config.json
# The tenant specific config file, i.e. config.tenant.environment.json, becomes plain config.json
run: |
mv ${{ github.workspace }}/inventory/rciam-metrics-dev/files/config.${{ matrix.tenant }}.json ${{ github.workspace }}/metrics-app-${{matrix.tenant}}/javascript/src/config.json
- name: List files in metrics-app-${{matrix.tenant}} javascript
# The tenant specific config file, i.e. config.tenant.environment.json, becomes plain config.json
run: |
ls -la ${{ github.workspace }}/metrics-app-${{matrix.tenant}}/javascript/src
- name: Cat config.json contents
# The tenant specific config file, i.e. config.tenant.environment.json, becomes plain config.json
run: |
cat ${{ github.workspace }}/metrics-app-${{matrix.tenant}}/javascript/src/config.json
- name: Share artifact inside workflow (frontend)
uses: actions/upload-artifact@v3
with:
name: react-application
path: |
${{ github.workspace }}/metrics-app-${{matrix.tenant}}
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install dependencies
run: |
cd ${{ github.workspace }}/metrics-app-${{matrix.tenant}}/javascript; npm install
- name: Build React application
run: |
cd ${{ github.workspace }}/metrics-app-${{matrix.tenant}}/javascript; CI=false npm run build
# Share artifact inside workflow
- name: List files in the repository
run: |
ls ${{ github.workspace }}/metrics-app-${{matrix.tenant}}
- name: Create release branch
run: cd ${{ github.workspace }}/metrics-app-${{matrix.tenant}}/; git checkout -b ${{ env.RELEASE_ID }}
- name: Initialize mandatory git config
working-directory: ./metrics-app-${{matrix.tenant}}
run: |
git config user.name "GitHub Actions"
git config user.email [email protected]
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ env.RELEASE_ID }}
directory: ./metrics-app-${{matrix.tenant}}
- name: Share artifact inside workflow - ${{matrix.tenant}}
uses: actions/upload-artifact@v3
with:
name: react-github-actions-build-${{matrix.tenant}}
path: |
${{ github.workspace }}/metrics-app-${{matrix.tenant}}/javascript/build
${{ github.workspace }}/metrics-app-${{matrix.tenant}}/javascript/CHANGELOG.md
${{ github.workspace }}/metrics-app-${{matrix.tenant}}/CHANGELOG.md
- name: Share artifact inside workflow - backend
uses: actions/upload-artifact@v3
with:
name: react-github-actions-build-backend
path: |
${{ github.workspace }}/metrics-app-${{matrix.tenant}}/app
${{ github.workspace }}/metrics-app-${{matrix.tenant}}/requirements.txt
${{ github.workspace }}/metrics-app-${{matrix.tenant}}/CHANGELOG.md
- run: echo "🍏 This job's status is ${{ job.status }}."
frontend_release:
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.configure.outputs.matrix) }}
# We specify that deploys needs to
# finish before we create a release
# Job outputs are available to all downstream jobs that depend on this job.
needs: [checkout, configure]
steps:
# Download previously shared build
- name: Get artifact
uses: actions/download-artifact@v3
with:
path: ./metrics-app-${{matrix.tenant}}
name: react-github-actions-build-${{matrix.tenant}}
- name: List files
run: |
pwd
ls -la ./
ls -la ./metrics-app-${{matrix.tenant}}/
ls -la ./metrics-app-${{matrix.tenant}}/javascript
ls -la ./metrics-app-${{matrix.tenant}}/javascript/build
- name: Compress action step
uses: a7ul/[email protected]
id: compress
# The frontend release is only the javascript/build
# We need to include all the files and directories since
# the action is not smart enough to under asterisk (*)
with:
command: c
cwd: ./metrics-app-${{matrix.tenant}}/javascript/build
files: |
asset-manifest.json
index.html
static
outPath: frontend-${{matrix.tenant}}-release-build.tar.gz
# Upload as an artifact of the current workflow
- name: Upload frontend build zip artifact
uses: actions/upload-artifact@v1
with:
name: frontend-${{matrix.tenant}}-release-build.tar.gz
path: frontend-${{matrix.tenant}}-release-build.tar.gz
- name: Create Release
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: "frontend-${{matrix.tenant}}-release-build.tar.gz"
bodyFile: "./metrics-app-${{matrix.tenant}}/javascript/CHANGELOG.md"
tag: "frontend-${{matrix.tenant}}-${{ github.ref_name }}-${{ env.RELEASE_ID }}"
makeLatest: true
generateReleaseNotes: true
backend_release:
runs-on: ubuntu-latest
# We specify that deploys needs to
# finish before we create a release
# Job outputs are available to all downstream jobs that depend on this job.
needs: [checkout, configure]
steps:
# Download previously shared build
- name: Get artifact
uses: actions/download-artifact@v3
with:
name: react-github-actions-build-backend
- name: Compress action step
uses: a7ul/[email protected]
id: compress
with:
command: c
cwd: ./
files: |
app/
requirements.txt
outPath: backend-release-build.tar.gz
- name: Upload backend build zip artifact
uses: actions/upload-artifact@v1
with:
name: backend-release-build.tar.gz
path: backend-release-build.tar.gz
- name: Create Release
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: "backend-release-build.tar.gz"
bodyFile: "CHANGELOG.md"
tag: "metrics-api-${{ github.ref_name }}-${{ env.RELEASE_ID }}"
makeLatest: true
generateReleaseNotes: true
deploy_backend:
runs-on: ubuntu-latest
# We specify that deploys needs to
# finish before we create a release
needs: backend_release
steps:
- name: Download playbook
uses: actions/checkout@v3
with:
# Repository name with owner. For example, actions/checkout
# Default: ${{ github.repository }}
repository: 'rciam/rciam-deploy'
ref: 'devel'
path: 'roles'
- name: Download inventory
uses: actions/checkout@v3
with:
repository: 'grnet/rciam-deploy-inv'
ref: 'master'
ssh-key: ${{ secrets.DEPLOY_READ_SECRET }}
path: 'inventory'
- name: Run playbook (deploy rciam-metrics) with release metrics-api-${{ github.ref_name }}-${{ env.RELEASE_ID }}
uses: dawidd6/action-ansible-playbook@v2
with:
# Required, playbook filepath
playbook: metricsservers.yml
# Optional, directory where playbooks live
directory: ./roles
key: ${{ secrets.DEPLOY_READ_SECRET }}
# Optional, encrypted vault password
vault_password: ${{secrets.VAULT_PASSWORD_DEVEL}}
options: |
--inventory ${{ github.workspace }}/inventory/rciam-metrics-dev/hosts.ini
--tags rciam-metrics:deploy-backend
-u debian
--extra-vars "metrics_release=metrics-api-${{ github.ref_name }}-${{ env.RELEASE_ID }}"
deploy_frontend:
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.configure.outputs.matrix) }}
# We specify that deploys needs to
# finish before we create a release
# Job outputs are available to all downstream jobs that depend on this job.
needs: [frontend_release, configure]
steps:
- name: Download playbook
uses: actions/checkout@v3
with:
# Repository name with owner. For example, actions/checkout
# Default: ${{ github.repository }}
repository: 'rciam/rciam-deploy'
ref: 'devel'
path: 'roles'
- name: Download inventory
uses: actions/checkout@v3
with:
repository: 'grnet/rciam-deploy-inv'
ref: 'master'
ssh-key: ${{ secrets.DEPLOY_READ_SECRET }}
path: 'inventory'
- name: Run playbook (deploy rciam-metrics) with release frontend-${{matrix.tenant}}-${{ github.ref_name }}-${{ env.RELEASE_ID }}
uses: dawidd6/action-ansible-playbook@v2
with:
# Required, playbook filepath
playbook: metricsservers.yml
# Optional, directory where playbooks live
directory: ./roles
key: ${{ secrets.DEPLOY_READ_SECRET }}
# Optional, encrypted vault password
vault_password: ${{secrets.VAULT_PASSWORD_DEVEL}}
options: |
--inventory ${{ github.workspace }}/inventory/rciam-metrics-dev/hosts.ini
--tags rciam-metrics:deploy-frontend
-u debian
--extra-vars "metrics_release=frontend-${{matrix.tenant}}-${{ github.ref_name }}-${{ env.RELEASE_ID }} tenant_environment=${{matrix.tenant}}"