-
Notifications
You must be signed in to change notification settings - Fork 4
130 lines (109 loc) · 4.05 KB
/
test-build.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
name: Test & Build
on: [push, pull_request]
jobs:
test:
name: Test
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12"]
# We want to run on external PRs, but not on our own internal PRs as they'll be run
# by the push to the branch. This prevents duplicated runs on internal PRs.
# Some discussion of this here:
# https://gh.neting.ccmunity/t/duplicate-checks-on-push-and-pull-request-simultaneous-event/18012
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
uses: ThePalaceProject/circulation/.github/actions/poetry@main
with:
version: "1.5.1"
- name: Install Tox
run: |
poetry install --only ci
env:
POETRY_VIRTUALENVS_CREATE: false
- name: Run Tests
run: tox
build:
name: Docker build
runs-on: ubuntu-latest
needs: [test]
permissions:
contents: read
packages: write
env:
REGISTRY_HOST: ghcr.io
# Push the built docker image only in the following cases:
# - The `NO_DOCKER_IMAGE` secret is not set. (Useful if you want to disable pushing
# of docker images in local forks of this repo).
# - The branch name does not start with `dependabot/`. The dependabot service does not
# have the proper security token to push to github packages.
# - The event that triggered this action was a `push`. If it was a PR the github action
# context will not have permissions to push the image to github packages.
IMAGE_PUSH_ENABLED: ${{
secrets.NO_DOCKER_IMAGE == null &&
!startsWith(github.ref, 'refs/heads/dependabot/') &&
github.event_name == 'push'
}}
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Install Poetry
uses: ThePalaceProject/circulation/.github/actions/poetry@main
with:
version: "1.5.1"
- name: Setup Dunamai
run: poetry install --only ci
env:
POETRY_VIRTUALENVS_CREATE: false
- name: Create version file
run: |
echo "__version__ = '$(dunamai from git --style semver)'" >> admin/_version.py
echo "__commit__ = '$(dunamai from git --format {commit} --full-commit)'" >> admin/_version.py
echo "__branch__ = '$(dunamai from git --format {branch})'" >> admin/_version.py
- name: Login to the Docker registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY_HOST }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
if: env.IMAGE_PUSH_ENABLED == 'true'
- name: Generate tags
id: library-registry-tags
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_HOST }}/${{ github.repository_owner }}/library-registry
tags: |
type=semver,pattern={{major}}.{{minor}},priority=10
type=semver,pattern={{version}},priority=20
type=ref,event=branch,priority=30
type=sha,priority=40
- name: Build image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
target: libreg_active
push: ${{ env.IMAGE_PUSH_ENABLED }}
tags: ${{ steps.library-registry-tags.outputs.tags }}
platforms: linux/amd64, linux/arm64