-
Notifications
You must be signed in to change notification settings - Fork 0
202 lines (179 loc) · 5.89 KB
/
ci.yml
File metadata and controls
202 lines (179 loc) · 5.89 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
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
name: CI/CD
on:
push:
branches: [ main, beta ]
tags: ['v*']
paths-ignore:
- '**.md'
- 'docs/**'
- 'screenshots/**'
- '.gitignore'
- 'LICENSE'
- 'to-do.md'
pull_request:
branches: [ main ]
paths-ignore:
- '**.md'
- 'docs/**'
- 'screenshots/**'
- '.gitignore'
- 'LICENSE'
- 'to-do.md'
env:
REGISTRY: ghcr.io
IMAGE_PREFIX: ghcr.io/${{ github.repository }}
jobs:
changes:
runs-on: ubuntu-latest
outputs:
backend: ${{ steps.filter.outputs.backend }}
frontend: ${{ steps.filter.outputs.frontend }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
backend:
- 'backend/**'
- 'VERSION'
- '.github/workflows/ci.yml'
- 'docker-compose.yml'
frontend:
- 'frontend/**'
- 'VERSION'
- '.github/workflows/ci.yml'
- 'docker-compose.yml'
backend-tests:
needs: changes
if: ${{ needs.changes.outputs.backend == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- name: Set up Python
run: uv python install 3.12
- name: Install dependencies
run: |
cd backend
uv venv
uv pip install -r requirements.txt -r requirements-dev.txt pytest-cov
- name: Run tests with coverage
run: |
cd backend
source .venv/bin/activate
export PYTHONPATH=$PYTHONPATH:.
pytest --cov=app --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: ./backend/coverage.xml
flags: backend
token: ${{ secrets.CODECOV_TOKEN }}
continue-on-error: true
frontend-tests:
needs: changes
if: ${{ needs.changes.outputs.frontend == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Install dependencies
run: |
cd frontend
npm ci
- name: Lint
run: |
cd frontend
npm run lint
- name: Run tests with coverage
run: |
cd frontend
npm test -- --coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: ./frontend/coverage/clover.xml
flags: frontend
token: ${{ secrets.CODECOV_TOKEN }}
continue-on-error: true
build-and-push:
needs: [changes, backend-tests, frontend-tests]
if: |
always() &&
github.event_name != 'pull_request' &&
(github.ref == 'refs/heads/main' || github.ref == 'refs/heads/beta' || startsWith(github.ref, 'refs/tags/v')) &&
(startsWith(github.ref, 'refs/tags/v') ||
needs.changes.outputs.backend == 'true' ||
needs.changes.outputs.frontend == 'true') &&
(needs.backend-tests.result == 'success' || needs.backend-tests.result == 'skipped') &&
(needs.frontend-tests.result == 'success' || needs.frontend-tests.result == 'skipped')
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
component: [backend, frontend]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Skip if component didn't change
id: check
run: |
# Tag builds always publish both images so the semver tag on ghcr.io
# covers a full release, even if only one side actually changed.
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
echo "skip=false" >> $GITHUB_OUTPUT
elif [[ "${{ matrix.component }}" == "backend" && "${{ needs.changes.outputs.backend }}" != "true" ]]; then
echo "skip=true" >> $GITHUB_OUTPUT
elif [[ "${{ matrix.component }}" == "frontend" && "${{ needs.changes.outputs.frontend }}" != "true" ]]; then
echo "skip=true" >> $GITHUB_OUTPUT
else
echo "skip=false" >> $GITHUB_OUTPUT
fi
- name: Set up QEMU
if: steps.check.outputs.skip != 'true'
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
if: steps.check.outputs.skip != 'true'
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
if: steps.check.outputs.skip != 'true'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
if: steps.check.outputs.skip != 'true'
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_PREFIX }}/${{ matrix.component }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=beta,enable=${{ github.ref == 'refs/heads/beta' }}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=
- name: Build and push ${{ matrix.component }}
if: steps.check.outputs.skip != 'true'
uses: docker/build-push-action@v6
with:
context: .
file: ./${{ matrix.component }}/Dockerfile
push: true
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max