-
Notifications
You must be signed in to change notification settings - Fork 5
186 lines (178 loc) · 6.88 KB
/
ci-cd.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
179
180
181
182
183
184
185
186
name: ci/cd
on:
push:
pull_request:
workflow_dispatch:
schedule:
- cron: '0 6 * * 6' # weekly integration tests
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu-24.04
strategy:
matrix:
arch: [amd64, arm64]
if: github.event_name != 'schedule'
outputs:
coverage-percentage: ${{ steps.percentage.outputs.percentage }}
steps:
- uses: actions/checkout@v4
- name: Install qemu-user-static
if: matrix.arch != 'amd64'
run: |
sudo apt-get update
sudo apt-get install qemu-user-static
- name: Cache veekun database
uses: actions/cache@v4
with:
path: data/veekun.sqlite
key: veekun-${{ hashFiles('src/cerbottana/data/veekun/*.csv', 'src/cerbottana/databases/veekun.py', 'src/cerbottana/tasks/veekun.py') }}
- name: Cache pokedex database
uses: actions/cache@v4
with:
path: data/pokedex.sqlite
key: pokedex-${{ hashFiles('uv.lock') }}
restore-keys: |
pokedex-
- name: Create folders
run: mkdir -p coverage data
- name: Lint and test in container
run: podman build --platform linux/${{ matrix.arch }} --volume "$PWD"/coverage:/coverage:z --volume "$PWD"/data:/data:z --target test .
- name: Output coverage percentage
id: percentage
if: github.event_name == 'push' && github.ref_name == 'main' && matrix.arch == 'amd64'
run: echo "percentage=$(jq '.totals.percent_covered_display' coverage/coverage.json)" >> $GITHUB_OUTPUT
- name: Save coverage report
run: cat coverage/coverage.md >> $GITHUB_STEP_SUMMARY
secrets-check:
runs-on: ubuntu-24.04
outputs:
has-secrets: ${{ steps.secrets-check.outputs.has-secrets }}
steps:
- name: Check if secrets are available
id: secrets-check
run: echo "has-secrets=${{ secrets.TESTS_BOT_USERNAME != '' }}" >> $GITHUB_OUTPUT
integration:
runs-on: ubuntu-24.04
needs: secrets-check
if: needs.secrets-check.outputs.has-secrets == 'true'
steps:
- uses: actions/checkout@v4
- name: Cache veekun database
uses: actions/cache@v4
with:
path: data/veekun.sqlite
key: veekun-${{ hashFiles('src/cerbottana/data/veekun/*.csv', 'src/cerbottana/databases/veekun.py', 'src/cerbottana/tasks/veekun.py') }}
- name: Cache pokedex database
uses: actions/cache@v4
with:
path: data/pokedex.sqlite
key: pokedex-${{ hashFiles('uv.lock') }}
restore-keys: |
pokedex-
- name: Cache pokemon-showdown instance
uses: actions/cache@v4
with:
path: pokemon-showdown
key: pokemon-showdown-${{ github.run_id }}
restore-keys: |
pokemon-showdown-
- name: Create folders
run: mkdir -p data pokemon-showdown
- name: Run integration tests
run: podman build --env USERNAME --env PASSWORD --env TESTS_MOD_USERNAME --env TESTS_MOD_PASSWORD --volume "$PWD"/pokemon-showdown:/pokemon-showdown:z --volume "$PWD"/data:/data:z --target integration .
env:
USERNAME: ${{ secrets.TESTS_BOT_USERNAME }}
PASSWORD: ${{ secrets.TESTS_BOT_PASSWORD }}
TESTS_MOD_USERNAME: ${{ secrets.TESTS_MOD_USERNAME }}
TESTS_MOD_PASSWORD: ${{ secrets.TESTS_MOD_PASSWORD }}
coverage-badge:
runs-on: ubuntu-24.04
needs: test
if: github.event_name == 'push' && github.ref_name == 'main'
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: "coverage-badge"
- name: Calculate badge color
id: color
run: |
echo "color=$(python3 -Ic 'print(
min(
(percentage, color)
for percentage, color in [
(100, "brightgreen"),
(90, "green"),
(70, "yellowgreen"),
(50, "yellow"),
(30, "orange"),
(0, "red"),
]
if percentage >= int(${{ needs.test.outputs.coverage-percentage }})
)[1]
)')" >> $GITHUB_OUTPUT
- name: Update JSON file
run: |
jq -n \
--argjson schemaVersion 1 \
--arg label coverage \
--arg message ${{ needs.test.outputs.coverage-percentage }}% \
--arg color ${{ steps.color.outputs.color }} \
'$ARGS.named' > coverage-badge.json
- name: Create commit
run: |
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git commit -am "Update coverage" && git push || true
publish:
permissions:
contents: read
packages: write
needs: [test, integration]
if: contains(fromJSON('["push", "workflow_dispatch"]'), github.event_name) && github.ref_name == 'main'
runs-on: ubuntu-24.04
strategy:
matrix:
arch: [amd64, arm64]
steps:
- uses: actions/checkout@v4
- name: Install qemu-user-static
if: matrix.arch != 'amd64'
run: |
sudo apt-get update
sudo apt-get install qemu-user-static
- name: Get target image name
id: image
run: echo "image_name=${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT
- name: Build image
run: podman build --platform linux/${{ matrix.arch }} --tag ${{ steps.image.outputs.image_name }}:latest-${{ matrix.arch }} .
- name: Push to ghcr.io
run: podman push --creds=${{ github.actor }}:${{ github.token }} ${{ steps.image.outputs.image_name }}:latest-${{ matrix.arch }} ghcr.io/${{ steps.image.outputs.image_name }}:latest-${{ matrix.arch }}
publish-multiarch:
permissions:
contents: read
packages: write
needs: publish
runs-on: ubuntu-24.04
steps:
- name: Get target image name
id: image
run: echo "image_name=${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT
- name: Create manifest
run: podman manifest create ${{ steps.image.outputs.image_name }}:latest
- name: Add images to the manifest
run: |
podman manifest add ${{ steps.image.outputs.image_name }}:latest ghcr.io/${{ steps.image.outputs.image_name }}:latest-amd64
podman manifest add ${{ steps.image.outputs.image_name }}:latest ghcr.io/${{ steps.image.outputs.image_name }}:latest-arm64
- name: Push to ghcr.io
run: podman manifest push --creds=${{ github.actor }}:${{ github.token }} ${{ steps.image.outputs.image_name }}:latest ghcr.io/${{ steps.image.outputs.image_name }}:latest
- name: Delete old image versions
uses: actions/delete-package-versions@v5
with:
package-name: ${{ github.event.repository.name }}
package-type: container
min-versions-to-keep: 10