-
Notifications
You must be signed in to change notification settings - Fork 3
90 lines (84 loc) · 2.89 KB
/
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
name: Build
on:
push:
branches: [ master ]
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'
pull_request:
branches: [ master ]
jobs:
build:
name: Build
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Install rye
uses: eifinger/setup-rye@d4c3ac7b15d8bf2e0b45e2d257c6b5cdbebc3643 # v4.2.1
with:
version: '0.36.0'
enable-cache: true
cache-prefix: ${{ github.workflow }}
- name: Decide image tags
id: info
shell: python
run: |
import os
import itertools
registries = ['docker.io', 'ghcr.io']
repos = ['${{ github.repository }}'.lower()]
if '${{ github.ref_type }}' == 'branch':
tags = ['latest']
elif '${{ github.ref_type }}' == 'tag':
version = '${{ github.ref_name }}'[1:]
tags = ['latest', version]
else:
tags = []
def join_tag(t):
registry, repo, tag = t
return f'{registry}/{repo}:{tag}'
product = itertools.product(registries, repos, tags)
tags_csv = ','.join(map(join_tag, product))
push = 'true' if len(tags) >= 2 else 'false'
with open(os.environ['GITHUB_OUTPUT'], 'a') as out:
out.write(f'tags={tags_csv}\n')
out.write(f'push={push}\n')
- name: Set version
run: |
if [ '${{ github.ref_type }}' = 'tag' ]; then
rye version '${{ github.ref_name }}'
else
commit='${{ github.sha }}'
rye version "0.0.0.dev1+commit.${commit:0:7}"
fi
rye version > src/chrisomatic/version.txt
- name: Build Python wheel
run: rye build --wheel --clean
- uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
if: github.event_name == 'push'
id: dockerhub_login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Login to GitHub Container Registry
if: github.event_name == 'push'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/ppc64le,linux/arm64
tags: ${{ steps.info.outputs.tags }}
push: ${{ steps.info.outputs.push }}
- name: Update DockerHub description
uses: peter-evans/dockerhub-description@v4
if: ${{ steps.info.outputs.push }}
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
short-description: ${{ github.event.repository.description }}