-
-
Notifications
You must be signed in to change notification settings - Fork 16
204 lines (182 loc) · 6.76 KB
/
release.yml
File metadata and controls
204 lines (182 loc) · 6.76 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
name: release
on:
# Release only after the CI workflow succeeds on main so Docker publishes
# are tied to a CI-validated commit instead of any direct branch push.
workflow_run:
workflows:
- ci
types:
- completed
branches:
- main
workflow_dispatch:
permissions:
contents: read
concurrency:
group: release-${{ github.event.workflow_run.head_sha || github.sha }}
cancel-in-progress: true
jobs:
guard:
runs-on: ubuntu-latest
outputs:
target_sha: ${{ steps.resolve.outputs.target_sha }}
target_ref: ${{ steps.resolve.outputs.target_ref }}
steps:
- name: Validate release trigger and resolve target
id: resolve
env:
EVENT_NAME: ${{ github.event_name }}
WORKFLOW_CONCLUSION: ${{ github.event.workflow_run.conclusion }}
WORKFLOW_HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
WORKFLOW_HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
GITHUB_REF_VALUE: ${{ github.ref }}
GITHUB_SHA_VALUE: ${{ github.sha }}
run: |
if [ "$EVENT_NAME" = "workflow_run" ]; then
if [ "$WORKFLOW_CONCLUSION" != "success" ]; then
echo "Release requires successful CI on main; got conclusion=$WORKFLOW_CONCLUSION" >&2
exit 1
fi
if [ -z "$WORKFLOW_HEAD_SHA" ] || [ -z "$WORKFLOW_HEAD_BRANCH" ]; then
echo "workflow_run payload missing head SHA or branch" >&2
exit 1
fi
echo "target_sha=$WORKFLOW_HEAD_SHA" >> "$GITHUB_OUTPUT"
echo "target_ref=refs/heads/$WORKFLOW_HEAD_BRANCH" >> "$GITHUB_OUTPUT"
exit 0
fi
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
if [ "$GITHUB_REF_VALUE" != "refs/heads/main" ]; then
echo "Manual release is restricted to refs/heads/main; got $GITHUB_REF_VALUE" >&2
exit 1
fi
echo "target_sha=$GITHUB_SHA_VALUE" >> "$GITHUB_OUTPUT"
echo "target_ref=$GITHUB_REF_VALUE" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "Unsupported event: $EVENT_NAME" >&2
exit 1
release:
needs:
- guard
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
outputs:
release_created: ${{ steps.release.outputs.release_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
steps:
- uses: actions/checkout@v6
with:
ref: ${{ needs.guard.outputs.target_sha }}
fetch-depth: 0
- name: Run release-please
id: release
uses: googleapis/release-please-action@v4
with:
token: ${{ secrets.RELEASE_PLEASE_TOKEN || github.token }}
config-file: .github/release-please-config.json
manifest-file: .github/.release-please-manifest.json
- name: Summarize release outcome
env:
RELEASE_CREATED: ${{ steps.release.outputs.release_created }}
RELEASE_TAG: ${{ steps.release.outputs.tag_name }}
run: |
{
echo "## Release outcome"
echo
echo "- Release created: ${RELEASE_CREATED:-false}"
if [ -n "${RELEASE_TAG}" ]; then
echo "- Release tag: ${RELEASE_TAG}"
else
echo "- Release tag: none"
fi
} >> "$GITHUB_STEP_SUMMARY"
docker-publish:
if: needs.release.outputs.release_created == 'true'
needs:
- guard
- release
runs-on: ubuntu-latest
env:
IMAGE_NAME: html2rss/web
TAG_SHA: ${{ needs.guard.outputs.target_sha }}
RELEASE_TAG: ${{ needs.release.outputs.tag_name }}
steps:
- uses: actions/checkout@v6
with:
ref: ${{ needs.guard.outputs.target_sha }}
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Get Git commit timestamp
run: |
echo "TIMESTAMP_EPOCH=$(git log -1 --format=%ct)" >> "$GITHUB_ENV"
echo "TIMESTAMP_ISO=$(git log -1 --format=%cI)" >> "$GITHUB_ENV"
- name: Compute Docker tags
id: tags
run: |
release_version="${RELEASE_TAG#v}"
echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV"
major="${release_version%%.*}"
{
echo "tags<<EOF"
echo "${IMAGE_NAME}:${release_version}"
echo "${IMAGE_NAME}:${major}"
echo "${IMAGE_NAME}:latest"
echo "${IMAGE_NAME}:${TAG_SHA}"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Log in to DockerHub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build and push Docker image
uses: docker/build-push-action@v7
env:
SOURCE_DATE_EPOCH: ${{ env.TIMESTAMP_EPOCH }}
with:
context: .
push: true
tags: ${{ steps.tags.outputs.tags }}
build-args: |
BUILD_TAG=${{ env.RELEASE_VERSION }}
GIT_SHA=${{ needs.guard.outputs.target_sha }}
platforms: linux/amd64,linux/arm64
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
provenance: true
sbom: true
labels: |
org.opencontainers.image.created=${{ env.TIMESTAMP_ISO }}
org.opencontainers.image.description=Generates RSS feeds of any website & serves to the web!
org.opencontainers.image.ref.name=${{ env.RELEASE_TAG }}
org.opencontainers.image.revision=${{ needs.guard.outputs.target_sha }}
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.title=html2rss-web
org.opencontainers.image.url=https://github.com/${{ github.repository }}/releases/tag/${{ env.RELEASE_TAG }}
org.opencontainers.image.version=${{ env.RELEASE_VERSION }}
- name: Move updated cache into place
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Summarize published image tags
run: |
{
echo "## Docker publish"
echo
echo "- Release tag: ${RELEASE_TAG}"
echo "- Docker tags pushed:"
echo "${{ steps.tags.outputs.tags }}" | sed 's/^/ - /'
} >> "$GITHUB_STEP_SUMMARY"