-
Notifications
You must be signed in to change notification settings - Fork 0
190 lines (157 loc) · 6.75 KB
/
publish.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
187
188
189
190
name: Publish
run-name: "Publish: ${{ inputs.version }}: ${{ github.ref_name }}@${{ github.sha }}"
on:
workflow_dispatch:
inputs:
version:
description: novel library version and repository tag to apply (e.g. 1.0.2-post5)
required: true
force-version:
description: omit check for semantic versioning
type: boolean
required: false
jobs:
check:
runs-on: ubuntu-latest
outputs:
git-tags: ${{ steps.tags.outputs.git-tags }}
steps:
- name: Check out repository
uses: actions/checkout@v3
with:
#
# Fetch ALL history s.t. tags may be sorted by date (creatordate)
# (regardless of whether the tag or ls-remote --tags command is used)
#
# Note: This might be slow! ls-remote allows us to avoid this, *except*
# that we want to sort by object creation date, which appears to require
# a complete local clone.
#
fetch-depth: 0
- name: Retrieve tags
id: tags
#
# checkout does not by default load all changesets and tags
#
# as such, this can come up empty:
#
# git tag --list
#
# instead, (and rather than check out repo history), we can query the remote:
#
# git ls-remote -q --tags --refs --sort=-creatordate | awk -F / '{print $3}'
#
# *However* the "creatordate" sort above fails without a deep clone;
# so, we'll rely on a deep clone, regardless.
#
run: |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "git-tags<<$EOF" >> "$GITHUB_OUTPUT"
git tag --list --sort=-creatordate >> "$GITHUB_OUTPUT"
echo "$EOF" >> "$GITHUB_OUTPUT"
- name: Check that tag is novel
env:
TAGS: ${{ steps.tags.outputs.git-tags }}
run: |
echo "$TAGS" |
grep -E "^${{ inputs.version }}$" > /dev/null && {
echo "::error::Tag ${{ inputs.version }} already exists"
exit 1
}
echo "✓ Tag ${{ inputs.version }} is novel"
- name: Check that version is semantic
if: ${{ ! inputs.force-version }}
env:
SEMVAR_PATTERN: ^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$
shell: python
run: |
import os
import re
match = re.fullmatch(os.getenv('SEMVAR_PATTERN'), '${{ inputs.version }}')
if not match:
print("::error::Version ${{ inputs.version }} is non-semantic")
raise SystemExit(1)
items = ('='.join(item) for item in match.groupdict().items() if all(item))
print("✓ Version ${{ inputs.version }} is semantic:", *items)
build-push:
runs-on: ubuntu-latest
needs: [check]
permissions:
contents: read
packages: write
strategy:
matrix:
base-image:
- name: python:3.11-bookworm
tags: |
ghcr.io/${{ github.repository_owner }}/fate-builder:latest
ghcr.io/${{ github.repository_owner }}/fate-builder:bookworm
ghcr.io/${{ github.repository_owner }}/fate-builder:py311
ghcr.io/${{ github.repository_owner }}/fate-builder:bookworm-py311
ghcr.io/${{ github.repository_owner }}/fate-builder:${{ inputs.version }}
ghcr.io/${{ github.repository_owner }}/fate-builder:${{ inputs.version }}-bookworm
ghcr.io/${{ github.repository_owner }}/fate-builder:${{ inputs.version }}-py311
ghcr.io/${{ github.repository_owner }}/fate-builder:${{ inputs.version }}-bookworm-py311
- name: python:3.11-slim-bookworm
tags: |
ghcr.io/${{ github.repository_owner }}/fate-builder:slim
ghcr.io/${{ github.repository_owner }}/fate-builder:slim-bookworm
ghcr.io/${{ github.repository_owner }}/fate-builder:slim-py311
ghcr.io/${{ github.repository_owner }}/fate-builder:slim-bookworm-py311
ghcr.io/${{ github.repository_owner }}/fate-builder:${{ inputs.version }}-slim
ghcr.io/${{ github.repository_owner }}/fate-builder:${{ inputs.version }}-slim-bookworm
ghcr.io/${{ github.repository_owner }}/fate-builder:${{ inputs.version }}-slim-py311
ghcr.io/${{ github.repository_owner }}/fate-builder:${{ inputs.version }}-slim-bookworm-py311
- name: ubuntu:22.04
tags: |
ghcr.io/${{ github.repository_owner }}/fate-builder:jammy
ghcr.io/${{ github.repository_owner }}/fate-builder:jammy-py310
ghcr.io/${{ github.repository_owner }}/fate-builder:${{ inputs.version }}-jammy
ghcr.io/${{ github.repository_owner }}/fate-builder:${{ inputs.version }}-jammy-py310
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
build-args: BASE_IMAGE=${{ matrix.base-image.name }}
labels: org.opencontainers.image.source=https://github.com/${{ github.repository }}
tags: ${{ matrix.base-image.tags }}
platforms: linux/amd64,linux/arm64
provenance: false
push: true
- name: Write to summary
env:
TAGS: ${{ matrix.base-image.tags }}
run: |
TAG="$(echo "$TAGS" | head -n1)"
echo "### Image pushed :ship:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "$TAG for ${{ matrix.base-image.name }}" >> $GITHUB_STEP_SUMMARY
tag:
runs-on: ubuntu-latest
needs: [check, build-push]
permissions:
contents: write
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Set and push tag
env:
TAGS: ${{ needs.check.outputs.git-tags }}
run: |
git tag ${{ inputs.version }}
git push --tags
# write summary information
lastTag="$(echo "$TAGS" | head -n1)"
echo "### Version bumped :arrow_heading_up:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "${{ github.ref_name }}@${{ github.sha }} tagged ${{ inputs.version }} over $lastTag" >> $GITHUB_STEP_SUMMARY