generated from this-is-tobi/template-monorepo-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
178 lines (158 loc) · 5.49 KB
/
tests-unit.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
name: Tests - unit
on:
workflow_call:
inputs:
BUN_VERSION:
required: true
type: string
secrets:
SONAR_HOST_URL:
required: false
SONAR_TOKEN:
required: false
SONAR_PROJECT_KEY:
required: false
workflow_dispatch:
inputs:
BUN_VERSION:
description: Bun version used to run tests
required: true
type: string
default: 1.1.42
jobs:
unit-tests:
name: Unit tests
runs-on: ubuntu-latest
steps:
- name: Checks-out repository
uses: actions/checkout@v4
- name: Install bun
uses: oven-sh/setup-bun@v1
with:
bun-version: "${{ inputs.BUN_VERSION }}"
- name: Get bun store directory
id: bun-store
run: |
echo "STORE_PATH=$(bun pm cache)" >> $GITHUB_OUTPUT
- name: Cache node files
uses: actions/cache@v4
with:
path: |
${{ steps.bun-store.outputs.STORE_PATH }}
key: node-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/bun.lockb') }}
restore-keys: |
node-${{ runner.os }}-${{ runner.arch }}-
- name: Cache turbo files
uses: actions/cache@v4
with:
path: |
./.turbo/cache
./apps/**/coverage
./packages/**/coverage
key: turbo-lint-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('apps/**/src/**','packages/**/src/**','cypress/src/**') }}
restore-keys: |
turbo-unit-${{ runner.os }}-${{ runner.arch }}-
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Run unit tests
run: |
./ci/scripts/init-env.sh
./ci/scripts/run-tests.sh -u
- name: Upload vitest coverage artifacts
uses: actions/upload-artifact@v4
with:
name: unit-tests-coverage
path: |
./apps/**/coverage/lcov.info
./packages/**/coverage/lcov.info
retention-days: 1
check-secrets:
name: Check if Sonar secrets are set
runs-on: ubuntu-latest
needs:
- unit-tests
outputs:
run-scan: ${{ steps.check-secrets.outputs.run-scan }}
steps:
- name: Check for sonar secrets
id: check-secrets
run: |
if [ "${{ secrets.SONAR_HOST_URL }}" != "" ] && [ "${{ secrets.SONAR_TOKEN }}" != "" ] && [ "${{ secrets.SONAR_PROJECT_KEY }}" != "" ]; then
echo "run-scan=true" >> $GITHUB_OUTPUT
else
echo "run-scan=false" >> $GITHUB_OUTPUT
fi
code-scan:
name: Run code quality analysis
runs-on: ubuntu-latest
needs:
- check-secrets
if: ${{ needs.check-secrets.outputs.run-scan == 'true' }}
steps:
- name: Checks-out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: unit-tests-coverage
path: ./coverage
- name: Install bun
uses: oven-sh/setup-bun@v1
with:
bun-version: "${{ inputs.BUN_VERSION }}"
- name: Get bun store directory
id: bun-store
run: |
echo "STORE_PATH=$(bun pm cache)" >> $GITHUB_OUTPUT
- name: Cache node files
uses: actions/cache@v4
with:
path: |
${{ steps.bun-store.outputs.STORE_PATH }}
key: node-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/bun.lockb') }}
restore-keys: |
node-${{ runner.os }}-${{ runner.arch }}-
- name: Cache turbo files
uses: actions/cache@v4
with:
path: |
./.turbo/cache
./apps/**/coverage
./packages/**/coverage
key: turbo-lint-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('apps/**/src/**','packages/**/src/**','cypress/src/**') }}
restore-keys: |
turbo-unit-${{ runner.os }}-${{ runner.arch }}-
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Set sonarqube args
id: sonar-args
run: |
echo "SONAR_ARGS_PR=-Dsonar.pullrequest.provider=github -Dsonar.pullrequest.key=${{ github.event.number }} -Dsonar.pullrequest.branch=${{ github.head_ref }} -Dsonar.pullrequest.base=${{ github.base_ref }} -Dsonar.pullrequest.github.repository=${{ github.repository }}" >> $GITHUB_OUTPUT
echo "SONAR_ARGS_BRANCH=-Dsonar.branch.name=${{ github.ref_name }}" >> $GITHUB_OUTPUT
- name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: >
-Dsonar.projectKey=${{ secrets.SONAR_PROJECT_KEY }}
-Dsonar.sources=apps,packages
-Dsonar.javascript.node.maxspace=4096
-Dsonar.javascript.lcov.reportPaths=coverage/apps/coverage/lcov.info
-Dsonar.coverage.exclusions=**/*.spec.js,**/*.spec.ts,**/*.vue,**/assets/**,**/cypress/**,**/packages/test-utils/**
-Dsonar.cpd.exclusions=**/*.spec.js,**/*.spec.ts,**/cypress/**
-Dsonar.scm.provider=git
${{ github.event_name == 'pull_request' && steps.sonar-args.outputs.SONAR_ARGS_PR || steps.sonar-args.outputs.SONAR_ARGS_BRANCH }}
continue-on-error: true
- name: SonarQube Quality Gate check
id: sonarqube-quality-gate-check
uses: sonarsource/sonarqube-quality-gate-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
timeout-minutes: 5
continue-on-error: true