-
Notifications
You must be signed in to change notification settings - Fork 28
133 lines (113 loc) · 3.39 KB
/
Copy pathbackend-test.yml
File metadata and controls
133 lines (113 loc) · 3.39 KB
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
name: Backend Test and Coverage
permissions:
contents: read
pull-requests: write
on:
push:
branches: [main]
pull_request:
branches: [main]
paths:
- "backend/**"
- "shared/**"
workflow_dispatch:
jobs:
test:
name: Node ${{ matrix.node-version }} Test
runs-on: ubuntu-latest
defaults:
run:
working-directory: backend
needs: set-matrix
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.set-matrix.outputs.matrix) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Start Redis
uses: supercharge/redis-github-action@1.8.1
with:
redis-version: ${{ matrix.redis-version }}
- name: Start MongoDB
uses: supercharge/mongodb-github-action@1.12.1
with:
mongodb-version: ${{ matrix.mongodb-version }}
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10
run_install: false
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build shared
run: pnpm --filter shared build
- name: Run tests
run: pnpm test
env:
CI: true
- name: Run coverage
if: matrix.node-version == '22'
run: pnpm coverage
env:
CI: true
- name: Upload coverage artifacts
if: matrix.node-version == '22'
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: backend/coverage.lcov
set-matrix:
name: Decide matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Detect backend changes
id: detect
run: |
if git diff --quiet HEAD^ HEAD -- backend shared; then
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Set matrix
id: set
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo 'matrix={"node-version":[22,24],"redis-version":[7],"mongodb-version":["8.0"]}' >> $GITHUB_OUTPUT
elif [[ "${{ steps.detect.outputs.changed }}" == "true" ]]; then
echo 'matrix={"node-version":[22,24],"redis-version":[7],"mongodb-version":["8.0"]}' >> $GITHUB_OUTPUT
else
echo 'matrix={"node-version":[22],"redis-version":[7],"mongodb-version":["8.0"]}' >> $GITHUB_OUTPUT
fi
coverage:
name: Upload Coverage
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
defaults:
run:
working-directory: backend
steps:
- uses: actions/checkout@v4
- name: Download coverage artifacts
uses: actions/download-artifact@v4
with:
name: coverage-report
path: backend/coverage.lcov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
fail_ci_if_error: true
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}