-
Notifications
You must be signed in to change notification settings - Fork 209
130 lines (119 loc) · 3.82 KB
/
publish.yaml
File metadata and controls
130 lines (119 loc) · 3.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
name: test&build
on:
merge_group:
workflow_dispatch:
push:
branches:
- main
- dev
tags:
- 'v*'
paths:
- '.github/workflows/publish.yaml'
- 'src/server/api/**'
- '!src/server/api/**/*.md'
pull_request:
branches:
- main
- dev
paths:
- '.github/workflows/publish.yaml'
- 'src/server/api/**'
- '!src/server/api/**/*.md'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
test:
name: Tests on ${{ matrix.os }} for ${{ matrix.python-version }}
strategy:
matrix:
python-version: [3.12]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v6
- name: Set up Python
run: uv python install
- name: Install dependencies
working-directory: ./src/server/api
run: |
uv sync --frozen --no-dev --no-cache-dir
- name: Start containers
working-directory: ./src/server
run: |
cp .env.example .env
cp api/config.yaml.example api/config.yaml
sh script/up-dev.sh &
- name: Wait for containers to start
working-directory: ./src/server
run: |
until docker compose exec memobase-server-db pg_isready -U $DATABASE_USER -d $DATABASE_NAME; do
echo "Waiting for PostgreSQL to be ready..."
sleep 5
done
- name: Test with pytest
working-directory: ./src/server/api
run: |
cp .env.example .env
uv run -m pytest --junit-xml=junit/test-results-${{ matrix.python-version }}.xml --cov=. --cov-report=xml:coverage-${{ matrix.python-version }}.xml tests/ -s -v
- name: Upload pytest test results and coverage
uses: actions/upload-artifact@v4
with:
name: pytest-results-${{ matrix.python-version }}
path: |
./src/server/api/junit/test-results-${{ matrix.python-version }}.xml
./src/server/api/coverage-${{ matrix.python-version }}.xml
if: ${{ always() }}
- name: Stop containers
working-directory: ./src/server
if: ${{ always() }}
run: |
docker compose down
build-image:
needs: test
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
SHOULD_PUSH: ${{ github.event_name == 'push' || (github.event_name == 'pull_request' && !github.event.pull_request.head.repo.fork) || github.event_name == 'workflow_dispatch' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Login to the Container Registry
if: ${{ env.SHOULD_PUSH == 'true' }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
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=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and Push Docker image
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
context: ./src/server/api
push: ${{ env.SHOULD_PUSH == 'true' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha