Skip to content

Release

Release #64

Workflow file for this run

name: Release
on:
workflow_dispatch:
inputs:
version:
description: "New version, for example 0.1.1"
required: true
type: string
permissions:
contents: write
packages: write
jobs:
release:
name: Create release and publish Docker image
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@v5
with:
ref: main
fetch-depth: 0
- name: Normalize and validate version
id: version
shell: bash
run: |
VERSION="${{ inputs.version }}"
VERSION="${VERSION#v}"
if ! echo "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "Invalid version: $VERSION"
echo "Use semantic versioning, for example: 0.1.1"
exit 1
fi
TAG="v$VERSION"
git fetch --tags
if git rev-parse "refs/tags/$TAG" >/dev/null 2>&1; then
echo "Tag $TAG already exists"
exit 1
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
- name: Update boot/version
shell: bash
run: |
echo "${{ steps.version.outputs.version }}" > boot/version
- name: Commit version change
shell: bash
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git add boot/version
if git diff --cached --quiet; then
echo "boot/version already contains ${{ steps.version.outputs.version }}"
exit 1
fi
git commit -m "Release ${{ steps.version.outputs.tag }} [skip ci]"
git push origin main
- name: Create and push tag
shell: bash
run: |
git tag -a "${{ steps.version.outputs.tag }}" -m "Release ${{ steps.version.outputs.tag }}"
git push origin "${{ steps.version.outputs.tag }}"
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
gh release create "${{ steps.version.outputs.tag }}" \
--title "${{ steps.version.outputs.tag }}" \
--notes "Release ${{ steps.version.outputs.tag }}"
- name: Set Docker image name
id: image
shell: bash
run: |
echo "image=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/workout-relay" >> "$GITHUB_OUTPUT"
- name: Login to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build and push Docker image
uses: docker/build-push-action@v7
with:
context: .
push: true
tags: |
${{ steps.image.outputs.image }}:${{ steps.version.outputs.version }}
${{ steps.image.outputs.image }}:latest