-
-
Notifications
You must be signed in to change notification settings - Fork 0
160 lines (159 loc) · 5.6 KB
/
node.js.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
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
name: Node.js CI/CD
on:
push:
branches: [ "main", "develop" ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
prepare-tag:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Prepare release timestamp
id: step1
run: |
echo "CI_TAG=$(date +'%0Y.%0m.%0d')-${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
outputs:
ci_tag: ${{ steps.step1.outputs.CI_TAG }}
run-tests-frontend:
defaults:
run:
working-directory: web-app-vue
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: web-app-vue/package-lock.json
- name: Run tests frontend
run: |
npm ci
npm run build --if-present
npm run test:web --if-present
run-tests-backend:
defaults:
run:
working-directory: service-node-koa
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: service-node-koa/package-lock.json
- name: Run tests
run: |
npm ci
npm run build --if-present
npm run test:service:coverage --if-present
publish-docker-image-frontend:
if: github.ref == 'refs/heads/main'
permissions: write-all
runs-on: ubuntu-latest
needs: [ run-tests-frontend, prepare-tag ]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v5
env:
VITE_API_URL: ${{vars.VITE_API_URL}}
with:
push: true
context: "{{defaultContext}}:web-app-vue"
file: infrastructure/Dockerfile
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/sombriks/redline/redline-app:latest
ghcr.io/sombriks/redline/redline-app:${{needs.prepare-tag.outputs.ci_tag}}
publish-docker-image-backend:
if: github.ref == 'refs/heads/main'
permissions: write-all
runs-on: ubuntu-latest
needs: [run-tests-backend, prepare-tag]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v5
with:
push: true
context: "{{defaultContext}}:service-node-koa"
file: infrastructure/Dockerfile
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/sombriks/redline/redline-api:latest
ghcr.io/sombriks/redline/redline-api:${{needs.prepare-tag.outputs.ci_tag}}
update-iac-manifests:
if: github.ref == 'refs/heads/main'
permissions: write-all
runs-on: ubuntu-latest
needs: [prepare-tag, publish-docker-image-frontend, publish-docker-image-backend]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Update api image
uses: fjogeleit/yaml-update-action@main
with:
valueFile: service-node-koa/infrastructure/k8s/deployment.yml
propertyPath: spec.template.spec.containers[0].image
value: ghcr.io/sombriks/redline/redline-api:${{needs.prepare-tag.outputs.ci_tag}}
commitChange: false
- name: Update app image
uses: fjogeleit/yaml-update-action@main
with:
valueFile: web-app-vue/infrastructure/k8s/deployment.yml
propertyPath: spec.template.spec.containers[0].image
value: ghcr.io/sombriks/redline/redline-app:${{needs.prepare-tag.outputs.ci_tag}}
commitChange: false
- name: Update and tag modified manifests
run: |
git config user.name "Mr. Bob Tags"
git config user.email sombriks@gmail.com
git status
git pull
git add .
git commit -m "IaC updated ${{needs.prepare-tag.outputs.ci_tag}}"
git push origin main
git tag ${{needs.prepare-tag.outputs.ci_tag}}
git push origin ${{needs.prepare-tag.outputs.ci_tag}}