-
Notifications
You must be signed in to change notification settings - Fork 0
240 lines (211 loc) · 7.01 KB
/
ci.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
name: CI
on:
push:
paths:
- '**'
branches:
- '**'
tags:
- '*.*.*'
workflow_dispatch:
env:
ARTIFACT_NAME: live-chat
DOCKER_IMAGE_NAME: livechat
DOCKER_REGISTRY_DOMAIN: ghcr.io
jobs:
client:
name: Client
runs-on: ubuntu-22.04
permissions:
contents: read
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Validate HTML
uses: Cyb3r-Jak3/html5validator-action@v7.2.0
with:
root: Client
css: true
- name: Upload build artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}-client
path: Client
server:
name: Server
runs-on: ubuntu-22.04
permissions:
contents: read
services:
mongodb:
image: mongo:6-jammy
env:
MONGO_INITDB_ROOT_USERNAME: mongodb
MONGO_INITDB_ROOT_PASSWORD: P4ssw0rd
MONGO_INITDB_DATABASE: github-actions-workflow
ports:
- 27017:27017
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
working-directory: Server
run: npm install
- name: Build project
working-directory: Server
run: npm run build
- name: Generate Express session secret
id: express
run: echo "EXPRESS_SESSION_SECRET=$(openssl rand -hex 16)" >> $GITHUB_OUTPUT
- name: Create environment variables file
working-directory: Server
run: cp --verbose --archive production.env test.env
- name: Run tests
working-directory: Server
env:
NODE_ENV: test
HTTP_SERVER_ADDRESS: 127.0.0.1
MONGO_SCHEME: mongodb
MONGO_HOST: 127.0.0.1
MONGO_DATABASE: github-actions-workflow
MONGO_USER_NAME: mongodb
MONGO_USER_PASS: P4ssw0rd
EXPRESS_SESSION_SECRET: ${{ steps.express.outputs.EXPRESS_SESSION_SECRET }}
EXPRESS_CLIENT_DIRECTORY: ../Client
EXPRESS_COOKIE_DOMAIN: 127.0.0.1
run: npm test
- name: Remove tests
working-directory: Server
run: rm --verbose --recursive dist/tests
- name: Upload log artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}-server-log
path: Server/logs/server.log
- name: Upload build artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}-server
path: |
Server/dist/
Server/package.json
Server/package-lock.json
Server/production.env
docker:
name: Docker
runs-on: ubuntu-22.04
needs:
- client
- server
concurrency:
group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: read
packages: write
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
- name: Setup Docker
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64
- name: Login to GitHub Container Registry
if: ${{ github.event_name != 'pull_request' && !startsWith( github.ref_name, 'dependabot/' ) }}
uses: docker/login-action@v3
with:
registry: ${{ env.DOCKER_REGISTRY_DOMAIN }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Download server build artifact
uses: actions/download-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}-server
path: artifacts/server/
- name: Download client build artifact
uses: actions/download-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}-client
path: artifacts/client/
- name: Create metadata for Docker image
id: metadata
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_REGISTRY_DOMAIN }}/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}
flavor: latest=true
tags: |
type=ref,event=pr
type=ref,event=branch
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}.{{minor}}.{{patch}}
labels: |
org.opencontainers.image.title=Live Chat
org.opencontainers.image.vendor=${{ github.repository_owner }}
com.docker.extension.publisher-url=https://viral32111.com
- name: Build & push Docker image
uses: docker/build-push-action@v5
with:
push: ${{ github.event_name != 'pull_request' && !startsWith( github.ref_name, 'dependabot/' ) }}
file: Dockerfile
context: artifacts
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
platforms: linux/amd64,linux/arm64
provenance: false
no-cache: true
pull: true
- name: Delete untagged Docker images
if: ${{ github.event_name != 'pull_request' && !startsWith( github.ref_name, 'dependabot/' ) }}
uses: snok/container-retention-policy@v2
with:
image-names: ${{ env.DOCKER_IMAGE_NAME }}
cut-off: 24 hours ago UTC
keep-at-least: 1
untagged-only: true
skip-tags: latest
account-type: personal
token: ${{ secrets.PACKAGES_PERSONAL_ACCESS_TOKEN }}
deploy-github:
name: Deploy to GitHub Pages
runs-on: ubuntu-22.04
if: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
needs: client
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
concurrency:
group: github-pages
cancel-in-progress: false
permissions:
contents: read
pages: write
id-token: write
steps:
- name: Setup GitHub Pages
uses: actions/configure-pages@v4
- name: Download client build artifact
uses: actions/download-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}-client
path: artifact
- name: Upload to GitHub Pages
uses: actions/upload-pages-artifact@v3
with:
path: artifact
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
- name: Run Page Speed Insights
uses: jakepartusch/psi-action@v1.3
with:
url: ${{ steps.deployment.outputs.page_url }}
threshold: 70
strategy: desktop
key: ${{ secrets.GOOGLE_PAGE_SPEED_INSIGHTS_API_KEY }}