-
-
Notifications
You must be signed in to change notification settings - Fork 0
184 lines (157 loc) · 4.82 KB
/
ci.yml
File metadata and controls
184 lines (157 loc) · 4.82 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
name: CI Pipeline
on:
push:
branches: [ "**" ]
pull_request:
branches: [ "**" ]
workflow_dispatch:
permissions:
contents: read
packages: write
env:
PYTHON_VERSION: "3.11"
UV_VERSION: "0.7.2"
UV_LINK_MODE: "copy"
ENV: "ci"
POSTGRES_DB: "test"
POSTGRES_USER: "test"
POSTGRES_PASSWORD: "test"
POSTGRES_HOST_AUTH_METHOD: "trust"
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
ruff:
name: lint (ruff)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set derived env
run: |
echo "IMAGE_PYTHON=python:${PYTHON_VERSION}-slim" >> $GITHUB_ENV
echo "UV_CACHE_DIR=${UV_CACHE_DIR:-$HOME/.cache/uv}" >> $GITHUB_ENV
- name: Cache uv
uses: actions/cache@v4
with:
path: ${{ env.UV_CACHE_DIR }}
key: uv-${{ hashFiles('uv.lock') }}
restore-keys: uv-
- name: Install uv
run: |
export PATH="$HOME/.local/bin:$PATH"
curl -LsSf "https://astral.sh/uv/${UV_VERSION}/install.sh" | sh
uv tool install go-task-bin || true
- name: Run linter
run: |
export PATH="$HOME/.local/bin:$PATH"
RUNNER="uv run" task lint
mypy:
name: typecheck (mypy)
runs-on: ubuntu-latest
needs: ruff
steps:
- uses: actions/checkout@v4
- name: Set derived env
run: |
echo "UV_CACHE_DIR=${UV_CACHE_DIR:-$HOME/.cache/uv}" >> $GITHUB_ENV
- name: Cache uv
uses: actions/cache@v4
with:
path: ${{ env.UV_CACHE_DIR }}
key: uv-${{ hashFiles('uv.lock') }}
restore-keys: uv-
- name: Install uv
run: |
export PATH="$HOME/.local/bin:$PATH"
curl -LsSf "https://astral.sh/uv/${UV_VERSION}/install.sh" | sh
uv tool install go-task-bin || true
- name: Run typecheck
run: |
export PATH="$HOME/.local/bin:$PATH"
RUNNER="uv run" task typecheck
pytest:
name: tests (pytest)
runs-on: ubuntu-latest
needs: mypy
services:
postgres:
image: postgres:15-alpine
env:
POSTGRES_DB: "test"
POSTGRES_USER: "test"
POSTGRES_PASSWORD: "test"
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U test -d test"
--health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v4
- name: Set derived env
run: |
echo "UV_CACHE_DIR=${UV_CACHE_DIR:-$HOME/.cache/uv}" >> $GITHUB_ENV
- name: Wait for Postgres
run: |
for i in $(seq 1 30); do
pg_isready -h localhost -p 5432 -U test && break
sleep 1
done
- name: Cache uv
uses: actions/cache@v4
with:
path: ${{ env.UV_CACHE_DIR }}
key: uv-${{ hashFiles('uv.lock') }}
restore-keys: uv-
- name: Install uv
run: |
export PATH="$HOME/.local/bin:$PATH"
curl -LsSf "https://astral.sh/uv/${UV_VERSION}/install.sh" | sh
uv tool install go-task-bin || true
- name: Run tests
env:
DATABASE_URL: "postgresql://test:test@localhost:5432/test"
run: |
export PATH="$HOME/.local/bin:$PATH"
RUNNER="uv run" task test-ci
build-image:
name: build & push image
runs-on: ubuntu-latest
#if: github.event_name == 'workflow_dispatch'
needs: pytest
steps:
- uses: actions/checkout@v4
- name: Install uv
run: |
export PATH="$HOME/.local/bin:$PATH"
curl -LsSf "https://astral.sh/uv/${UV_VERSION}/install.sh" | sh
uv tool install go-task-bin || true
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: deployments/compose/backend/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:main
cache-to: type=inline
- name: Print pushed tags
run: |
echo "✅ Pushed image tags:"
echo "${{ steps.meta.outputs.tags }}"