ci(publish): add a manual build-only rehearsal trigger
workflow_dispatch with version/push/latest inputs: push defaults to false, so the runner, socket and registry login can be verified without creating a tag or a package version. latest is never moved unless asked.
This commit is contained in:
1 parent
e0c69c1b77
commit
81bfae7489
3 files changed
+75
-4
No files matched your search
@@ -9,6 +9,24 @@ on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
# Manual rehearsal from the Gitea UI (Actions -> Publish image -> Run
|
||||
# workflow). `push` defaults to false: the job builds and smoke-tests, then
|
||||
# stops without publishing, so the runner can be verified without creating
|
||||
# a tag or a package version. Set `push` to true (and `latest` only for a
|
||||
# real release) to publish.
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
description: 'Version to build, e.g. v0.0.1 (vMAJOR.MINOR.PATCH)'
|
||||
required: true
|
||||
push:
|
||||
description: 'Push the image to the registry'
|
||||
required: false
|
||||
default: 'false'
|
||||
latest:
|
||||
description: 'Also move :latest (real releases only)'
|
||||
required: false
|
||||
default: 'false'
|
||||
|
||||
# The runner has capacity 1, so releases already serialize. This keeps a
|
||||
# manual re-run from racing a fresh release on the same tags.
|
||||
@@ -72,10 +90,19 @@ jobs:
|
||||
|
||||
- name: Resolve version and tags
|
||||
id: version
|
||||
env:
|
||||
# Inputs go through env, not direct interpolation: a value pasted
|
||||
# into a `run:` block is shell code before any check can run.
|
||||
INPUT_VERSION: ${{ github.event.inputs.version }}
|
||||
INPUT_LATEST: ${{ github.event.inputs.latest }}
|
||||
run: |
|
||||
# GITHUB_REF_NAME is the tag on a tag push. The git fallback keeps
|
||||
# this working if a runner version does not set it.
|
||||
version="${GITHUB_REF_NAME:-$(git describe --tags --exact-match HEAD)}"
|
||||
# On a tag push GITHUB_REF_NAME is the tag; on workflow_dispatch it
|
||||
# is the BRANCH, so the manual version input must win. The git
|
||||
# fallback keeps tag pushes working if a runner omits the variable.
|
||||
version="$INPUT_VERSION"
|
||||
if [ -z "$version" ]; then
|
||||
version="${GITHUB_REF_NAME:-$(git describe --tags --exact-match HEAD)}"
|
||||
fi
|
||||
# Strict semver, not a `v[0-9]*` prefix match: that would accept
|
||||
# `v1`, `v1-anything` and prereleases, all valid registry tags.
|
||||
if ! printf '%s' "$version" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
|
||||
@@ -91,7 +118,13 @@ jobs:
|
||||
# A tag comparison needs the other tags, which a depth-1 tag
|
||||
# checkout does not have. If the fetch fails, skip `latest` and
|
||||
# say so - a wrong tag is worse than a missing one.
|
||||
if git fetch --tags --force --quiet origin 2>/dev/null; then
|
||||
#
|
||||
# A manual run moves `latest` only when the `latest` input says so;
|
||||
# a rehearsal must never repoint the production tag.
|
||||
if [ "$INPUT_LATEST" = "true" ]; then
|
||||
latest=true
|
||||
echo "manual run requested :latest"
|
||||
elif git fetch --tags --force --quiet origin 2>/dev/null; then
|
||||
newest="$(git tag -l | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1)"
|
||||
if [ "$version" = "$newest" ]; then
|
||||
latest=true
|
||||
@@ -128,6 +161,9 @@ jobs:
|
||||
| docker login git.noelsabia.dev -u "$REGISTRY_USERNAME" --password-stdin
|
||||
|
||||
- name: Refuse to overwrite a published version
|
||||
# Build-only rehearsals publish nothing, so an existing tag is not a
|
||||
# conflict there; the guard only protects actual pushes.
|
||||
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.push == 'true' }}
|
||||
env:
|
||||
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
|
||||
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
|
||||
@@ -213,6 +249,8 @@ jobs:
|
||||
run: docker tag "${IMAGE}:${VERSION}" "${IMAGE}:latest"
|
||||
|
||||
- name: Push image
|
||||
# Manual run with `push` left at false: build and smoke test only.
|
||||
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.push == 'true' }}
|
||||
env:
|
||||
VERSION: ${{ steps.version.outputs.version }}
|
||||
SHA: ${{ steps.version.outputs.sha }}
|
||||
@@ -228,3 +266,13 @@ jobs:
|
||||
else
|
||||
echo "Pushed ${IMAGE}:${VERSION}, :sha-${SHA} (:latest untouched)"
|
||||
fi
|
||||
|
||||
- name: Rehearsal summary
|
||||
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.push != 'true' }}
|
||||
env:
|
||||
VERSION: ${{ steps.version.outputs.version }}
|
||||
SHA: ${{ steps.version.outputs.sha }}
|
||||
run: |
|
||||
echo "Build-only rehearsal for ${VERSION} (${SHA}) - the image passed the smoke test and was NOT pushed."
|
||||
echo "Re-run with push=true to publish it."
|
||||
|
||||
Reference in new issue
Block a user