Repository navigation
206 lines (186 loc) · 6.73 KB
/
Copy pathrelease.yml
File metadata and controls
206 lines (186 loc) · 6.73 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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
name: release
on:
workflow_dispatch:
inputs:
bump:
description: "Version bump from the newest tag (ignored when version is set)"
type: choice
options: [patch, minor, major]
default: patch
version:
description: "Explicit version, e.g. 0.11.0 (overrides bump)"
type: string
latest:
description: "Also push the :latest tag"
type: boolean
default: true
draft:
description: "Create the GitHub Release as a draft"
type: boolean
default: true
discussion:
description: "Create a discussion for this release"
type: boolean
default: false
discussion_category:
description: "Discussion category"
type: choice
options: [Announcements, General, Ideas, "Q&A", Support]
default: Announcements
env:
IMAGE: ghcr.io/${{ github.repository_owner }}/crosswatch
DOCKERHUB_IMAGE: docker.io/${{ github.repository_owner }}/crosswatch
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
discussions: write
steps:
- name: Check branch
if: github.ref_name != 'main'
run: |
echo "Run this from the main branch, got ${{ github.ref_name }}"
exit 1
- name: Check Docker Hub credentials
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
run: |
if [ -z "${DOCKERHUB_USERNAME}" ] || [ -z "${DOCKERHUB_TOKEN}" ]; then
echo "Missing DOCKERHUB_USERNAME or DOCKERHUB_TOKEN repository secret"
exit 1
fi
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Resolve version
id: ver
env:
IN_VERSION: ${{ inputs.version }}
IN_BUMP: ${{ inputs.bump }}
run: |
set -euo pipefail
last="$(git tag -l 'v[0-9]*.[0-9]*.[0-9]*' --sort=-v:refname | head -n1)"
echo "Newest tag: ${last:-none}"
if [ -n "${IN_VERSION}" ]; then
version="${IN_VERSION#v}"
else
base="${last#v}"
base="${base:-0.0.0}"
IFS=. read -r major minor patch <<< "${base}"
case "${IN_BUMP}" in
major) major=$((major + 1)); minor=0; patch=0 ;;
minor) minor=$((minor + 1)); patch=0 ;;
patch) patch=$((patch + 1)) ;;
*) echo "Unknown bump ${IN_BUMP}"; exit 1 ;;
esac
version="${major}.${minor}.${patch}"
fi
if ! [[ "${version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Not a valid version: ${version}"
exit 1
fi
if git rev-parse -q --verify "refs/tags/v${version}" >/dev/null; then
echo "Tag v${version} already exists"
exit 1
fi
if [ -n "${IN_VERSION}" ]; then
if [ -n "${last}" ]; then
IFS=. read -r prev_major prev_minor _prev_patch <<< "${last#v}"
IFS=. read -r new_major new_minor _new_patch <<< "${version}"
if [ "${prev_major}" = "${new_major}" ] && [ "${prev_minor}" = "${new_minor}" ]; then
kind="Update"
else
kind="Release"
fi
else
kind="Release"
fi
elif [ "${IN_BUMP}" = "patch" ]; then
kind="Update"
else
kind="Release"
fi
echo "Releasing v${version} as ${kind} ${version}"
echo "version=${version}" >> "$GITHUB_OUTPUT"
echo "tag=v${version}" >> "$GITHUB_OUTPUT"
echo "previous=${last}" >> "$GITHUB_OUTPUT"
echo "title=${kind} ${version}" >> "$GITHUB_OUTPUT"
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: docker/metadata-action@v5
id: meta
with:
images: |
${{ env.IMAGE }}
${{ env.DOCKERHUB_IMAGE }}
tags: |
type=raw,value=${{ steps.ver.outputs.version }}
type=raw,value=latest,enable=${{ inputs.latest }}
labels: |
org.opencontainers.image.version=${{ steps.ver.outputs.version }}
- uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
build-args: |
APP_VERSION=${{ steps.ver.outputs.tag }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Tag release
env:
TAG: ${{ steps.ver.outputs.tag }}
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag -a "${TAG}" -m "${TAG}"
git push origin "${TAG}"
- name: Publish GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ steps.ver.outputs.tag }}
TITLE: ${{ steps.ver.outputs.title }}
PREVIOUS: ${{ steps.ver.outputs.previous }}
DRAFT: ${{ inputs.draft }}
LATEST: ${{ inputs.latest }}
DISCUSSION: ${{ inputs.discussion }}
DISCUSSION_CATEGORY: ${{ inputs.discussion_category }}
run: |
set -euo pipefail
args=(--title "${TITLE}" --generate-notes --verify-tag)
if [ -n "${PREVIOUS}" ]; then args+=(--notes-start-tag "${PREVIOUS}"); fi
if [ "${DRAFT}" = "true" ]; then args+=(--draft); fi
if [ "${LATEST}" = "true" ]; then args+=(--latest); fi
if [ "${DISCUSSION}" = "true" ]; then
if [ "${DRAFT}" = "true" ]; then
echo "Draft releases cannot open a discussion, skipping"
else
args+=(--discussion-category "${DISCUSSION_CATEGORY}")
fi
fi
gh release create "${TAG}" "${args[@]}"
- name: Summary
run: |
{
echo "### Released ${{ steps.ver.outputs.tag }}"
echo
echo '```'
echo "docker pull ${{ env.IMAGE }}:${{ steps.ver.outputs.version }}"
echo "docker pull ${{ env.DOCKERHUB_IMAGE }}:${{ steps.ver.outputs.version }}"
echo '```'
} >> "$GITHUB_STEP_SUMMARY"