barycenter/.github/workflows/release.yml
Till Wegmueller ea876be242
fix(ci): prevent invalid Docker tags for pre-release versions
Disable major and minor version tags for pre-release versions (alpha, beta, rc)
since semver pattern extraction doesn't work correctly with pre-release suffixes.

This fixes the error:
  ERROR: failed to build: invalid tag "ghcr.io/.../barycenter:-1171167"

Pre-release versions will now only get:
- Full version tag: v0.2.0-alpha.1
- SHA tag: main-<sha>

Stable releases will continue to get all tags:
- Full version: v1.0.0
- Major.minor: 1.0
- Major: 1
- SHA: main-<sha>

Also added missing id to build step for attestation.
2025-11-29 16:08:31 +01:00

129 lines
4 KiB
YAML

name: Release
on:
push:
tags:
- 'v*.*.*'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}},enable=${{ !contains(github.ref_name, 'alpha') && !contains(github.ref_name, 'beta') && !contains(github.ref_name, 'rc') }}
type=semver,pattern={{major}},enable=${{ !contains(github.ref_name, 'alpha') && !contains(github.ref_name, 'beta') && !contains(github.ref_name, 'rc') }}
type=sha,prefix={{branch}}-
labels: |
org.opencontainers.image.title=Barycenter
org.opencontainers.image.description=OpenID Connect Identity Provider with federation and auto-registration
org.opencontainers.image.vendor=${{ github.repository_owner }}
- name: Build and push Docker image
id: build
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
VERSION=${{ github.ref_name }}
REVISION=${{ github.sha }}
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
subject-digest: ${{ steps.build.outputs.digest }}
push-to-registry: true
create-github-release:
runs-on: ubuntu-latest
needs: build-and-push
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate changelog
id: changelog
run: |
# Get previous tag
PREVIOUS_TAG=$(git describe --abbrev=0 --tags $(git rev-list --tags --skip=1 --max-count=1) 2>/dev/null || echo "")
# Generate changelog
if [ -z "$PREVIOUS_TAG" ]; then
CHANGELOG=$(git log --pretty=format:"- %s (%h)" --no-merges)
else
CHANGELOG=$(git log ${PREVIOUS_TAG}..HEAD --pretty=format:"- %s (%h)" --no-merges)
fi
# Save to file for multiline output
echo "$CHANGELOG" > /tmp/changelog.txt
# Set output
echo "changelog<<EOF" >> $GITHUB_OUTPUT
cat /tmp/changelog.txt >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
body: |
## What's Changed
${{ steps.changelog.outputs.changelog }}
## Docker Images
Pull the Docker image:
```bash
docker pull ghcr.io/${{ github.repository }}:${{ github.ref_name }}
```
Available platforms:
- linux/amd64
- linux/arm64
## Installation
See [DEPLOYMENT.md](https://github.com/${{ github.repository }}/blob/${{ github.ref_name }}/DEPLOYMENT.md) for installation instructions.
draft: false
prerelease: ${{ contains(github.ref_name, 'alpha') || contains(github.ref_name, 'beta') || contains(github.ref_name, 'rc') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}