-
Notifications
You must be signed in to change notification settings - Fork 3
96 lines (92 loc) · 3.58 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
name: CI
on:
push:
branches:
- main
pull_request:
types:
- opened
- synchronize
jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Ensure Conventional Commits
uses: webiny/[email protected]
- name: Setup node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'
- run: npm ci
- uses: nrwl/nx-set-shas@v3
- name: Check Formatting
run: |
if [[ $(npx nx format:check) ]]; then
npx prettier -w .
git diff --color | cat
exit 1
fi
- name: Lint
run: npx nx affected --target=lint --parallel=3
- name: Run all tests
if: github.event_name == 'push'
run: npx nx run-many --all --target=test --parallel --ci --coverage --coverageReporters=lcov
- name: Run affected tests
if: github.event_name == 'pull_request'
run: npx nx affected --target=test --parallel --ci --coverage --coverageReporters=lcov
- name: Merge Coverage files
run: '[ -d "./coverage/" ] && ./node_modules/.bin/lcov-result-merger ./coverage/**/lcov.info ./coverage/lcov.info || exit 0'
- name: Create Environments
run: |
envsubst < apps/spa/src/environments/environment.template > apps/spa/src/environments/environment.ts
envsubst < apps/api/src/app/environment.template > apps/api/src/app/environment.ts
env:
IS_PRODUCTION: true
ENVIRONMENT_NAME: 'ci'
RELEASE_VERSION: ${{ github.sha }}
- name: Build
run: |
npx nx run-many -t build --prod --all --parallel=3
docker build -t kordis-api:${{ github.sha }} -f ./apps/api/Dockerfile --build-arg NODE_VERSION=$(cat .nvmrc | tr -cd '[:digit:].') . &
docker build -t kordis-spa:${{ github.sha }} -f ./apps/spa/docker/Dockerfile . &
wait
- name: Install Chromium for E2Es
run: npx -y playwright install chromium
- name: Start and prepare MongoDB for E2Es
working-directory: ./tools/db
run: |
export MONGO_HOST=172.17.0.1
./kordis-db.sh init e2edb
- name: Start API and SPA containers
run: |
docker run -d --name kordis-api-container -p 3000:3333 -e MONGODB_URI=mongodb://172.17.0.1:27017/e2edb?replicaSet=rs0 -e AUTH_PROVIDER=dev kordis-api:${{ github.sha }}
docker run -d --name kordis-spa-container -p 4200:8080 -e API_URL=http://localhost:3000 kordis-spa:${{ github.sha }}
- name: Run E2Es
id: e2e-tests
run: npx wait-on -t 90s http://localhost:3000/health-check && npx wait-on -t 30s http://localhost:4200 && npx nx e2e spa-e2e --skipInstall
env:
E2E_BASE_URL: http://localhost:4200/
- uses: actions/upload-artifact@v4
if: failure()
with:
name: e2e-test-results
path: test-results/
if-no-files-found: ignore
- name: Print Container Logs
if: ${{ failure() && steps.e2e-tests.conclusion == 'failure' }}
run: |
echo "::group::Kordis API Container Logs"
docker logs kordis-api-container
echo "::endgroup::"
echo "::group::Kordis SPA Container Logs"
docker logs kordis-spa-container
echo "::endgroup::"
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}