Files
Plenario/.gitea/workflows/release.yml
T
gnilebeinandClaude Sonnet 5.5 bba877999f
CI / Deploy / test (push) Successful in 1m30s
CI / Deploy / deploy (push) Skipped
Build app package and image only for semver release tags
Replace the Docker workflow with a release workflow that runs on
vX.Y.Z[-suffix] tags: tests first, then an app-only package
(plenario-<version>.tar.gz with production vendor/) attached to the Gitea
release and a container image tagged with the semver versions.
Document the release process and the deployment target in the README.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-12 10:24:26 +01:00

173 lines
6.7 KiB
YAML

# Release (Gitea Actions): runs only when a semantic-version tag is pushed (or a release is created
# from a new such tag in Gitea), e.g. v1.4.0 or v2.0.0-rc.1. Nothing is built on normal pushes.
#
# git tag v1.4.0 && git push origin v1.4.0
#
# - test: PHPUnit + phpcs on the tagged commit; package and image are only built if it is green.
# - package: install package (plenario-<version>.tar.gz: only the app incl. production vendor/, no tests/CI/Docker files)
# + SHA256SUMS, attached to the Gitea release for that tag (created if missing, updated if present).
# Tags with a pre-release suffix (-rc.1, -beta.2, …) become pre-releases.
# - image: container image with the semver tags <major>.<minor>.<patch>, <major>.<minor>, <major> and (stable
# releases only) latest, pushed to the Gitea registry.
#
# Repository variables (Settings → Actions → Variables):
# DOCKER_REPO registry host, e.g. gitea.gnilebein.de
# IMAGE_NAME image name, e.g. plenario
# Repository secrets:
# PAT personal access token with package write permission (registry login)
# The release itself is created with the job token; if your Gitea denies that (HTTP 403), use a PAT with
# repository write permission instead of `gitea.token` in the "Publish release" step.
name: Release
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+-*'
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check tag is a semantic version
env:
REF_NAME: ${{ gitea.ref_name }}
run: |
if ! printf '%s' "$REF_NAME" | grep -Eq '^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z.-]+)?$'; then
echo "'$REF_NAME' is not a semantic version tag (expected vMAJOR.MINOR.PATCH[-prerelease])." >&2
exit 1
fi
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.5'
extensions: mbstring, intl, pdo_sqlite, sqlite3
coverage: none
- name: Install dependencies
run: composer install --no-interaction --prefer-dist --no-progress
- name: Run tests
run: vendor/bin/phpunit
- name: Coding standard
run: vendor/bin/phpcs --warning-severity=0
package:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.5'
extensions: mbstring, intl
coverage: none
- name: Build package
env:
REF_NAME: ${{ gitea.ref_name }}
run: |
set -eu
VERSION="${REF_NAME#v}"
NAME="plenario-${VERSION}"
mkdir -p build dist
# Whitelist: only what the running app needs (no tests, CI, Docker, editor or agent files)
git archive --format=tar --prefix="$NAME/" "$REF_NAME" \
bin config plugins resources src templates webroot \
index.php .htaccess composer.json composer.lock | tar -x -C build
cd "build/$NAME"
rm -f bin/cake.bat bin/bash_completion.sh
# --no-scripts: the installer must not bake a random salt into app_local.php (SECURITY_SALT comes from config/.env)
composer install --no-dev --no-scripts --no-interaction --no-progress --prefer-dist --optimize-autoloader
cp config/app_local.example.php config/app_local.php
mkdir -p tmp/cache/models tmp/cache/persistent tmp/cache/views tmp/sessions logs data
printf '%s\n' "$VERSION" > VERSION
cd ../..
tar -czf "dist/${NAME}.tar.gz" -C build "$NAME"
(cd dist && sha256sum "${NAME}.tar.gz" > SHA256SUMS)
ls -l dist
- name: Publish release
env:
REF_NAME: ${{ gitea.ref_name }}
API: ${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}
TOKEN: ${{ gitea.token }}
run: |
set -eu
auth="Authorization: token ${TOKEN}"
# Changelog: commit subjects since the previous tag (merge commits left out)
PREV="$(git describe --tags --abbrev=0 "${REF_NAME}^" 2>/dev/null || true)"
RANGE="${REF_NAME}"
if [ -n "$PREV" ]; then RANGE="${PREV}..${REF_NAME}"; fi
NOTES="$(git log --no-merges --pretty='- %s' "$RANGE")"
PRERELEASE=false
case "$REF_NAME" in *-*) PRERELEASE=true ;; esac
# Idempotent: reuse the release if this tag already has one (re-run), otherwise create it
status="$(curl -sS -o release.json -w '%{http_code}' -H "$auth" "$API/releases/tags/$REF_NAME")"
if [ "$status" != "200" ]; then
jq -n --arg tag "$REF_NAME" --arg body "$NOTES" --argjson pre "$PRERELEASE" \
'{tag_name: $tag, name: $tag, body: $body, prerelease: $pre}' > payload.json
curl -fsS -o release.json -X POST -H "$auth" -H 'Content-Type: application/json' \
-d @payload.json "$API/releases"
fi
ID="$(jq -r .id release.json)"
for file in dist/*; do
base="$(basename "$file")"
# replace an asset of the same name left over from an earlier run
jq -r --arg n "$base" '.assets[]? | select(.name == $n) | .id' release.json | while read -r aid; do
curl -fsS -X DELETE -H "$auth" "$API/releases/$ID/assets/$aid"
done
curl -fsS -o /dev/null -X POST -H "$auth" -F "attachment=@${file}" \
"$API/releases/$ID/assets?name=${base}"
done
image:
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to registry
uses: docker/login-action@v3
with:
registry: ${{ vars.DOCKER_REPO }}
username: ${{ gitea.actor }}
password: ${{ secrets.PAT }}
- name: Image tags
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ vars.DOCKER_REPO }}/${{ gitea.repository_owner }}/${{ vars.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}},enable=${{ !contains(gitea.ref_name, '-') && !startsWith(gitea.ref_name, 'v0.') }}
- name: Build and push
uses: docker/build-push-action@v6
with:
file: ./Dockerfile
platforms: linux/amd64
pull: true
push: true
provenance: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}