Skip to content

Bump to 1.0.0-alpha.2 (#61) #12

Bump to 1.0.0-alpha.2 (#61)

Bump to 1.0.0-alpha.2 (#61) #12

# This workflow is used to tag an existing container image with a semver version
# and create a GitHub Release
name: Publish a Versioned Release
on:
push:
tags:
- v*
env:
image-name: hutch/bunny
repo-owner: ${{ github.repository_owner }}
registry: ghcr.io
jobs:
version-tag:
runs-on: ubuntu-latest
permissions:
packages: write # container images
contents: write # releases
steps:
- name: Check out the repo
uses: actions/checkout@v4
# some docker actions need all lowercase, but our org name is mixed case 😠
- name: downcase repo-owner
run: |
echo "REPO_OWNER_LOWER=${GITHUB_REPOSITORY_OWNER,,}" >>${GITHUB_ENV}
# read source version
- uses: SebRollen/toml-action@v1.2.0
id: read_version
with:
file: pyproject.toml
field: project.version
- name: Parse version from tag
id: version
uses: release-kit/semver@v2
- name: Fail on Version Mismatch
if: ${{ steps.read_version.outputs.value != steps.version.outputs.full }}
run: |
echo "::error::Tag version '${{ steps.version.outputs.full }}' doesn't match source version '${{ steps.read_version.outputs.value }}'"
exit 1
# check image exists for commit
- uses: tyriis/docker-image-tag-exists@v2.1.0
with:
registry: ${{ env.registry }}
repository: ${{ env.REPO_OWNER_LOWER }}/${{ env.image-name }}
tag: ${{ github.sha }}
# standard login to the container registry
- name: Docker Login
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.registry }}
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}
# We still use the metadata action to help build out our tags from the Workflow Run
- name: Docker Metadata action
id: meta
uses: docker/metadata-action@v5.5.1
with:
images: ${{ env.registry }}/${{ env.repo-owner }}/${{ env.image-name }}
tags: | # new tags only
type=semver,pattern={{version}}
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}}
# Create Github Release
- uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref_name }}
name: ${{ github.ref_name }}
body: |
# Hutch Bunny ${{ github.ref_name }}
[Tagged Container images](https://github.com/Health-Informatics-UoN/hutch-bunny/pkgs/container/hutch%2Fbunny)
generateReleaseNotes: true
prerelease: ${{ steps.version.outputs.prerelease != '' }}
makeLatest: false # TODO: can we reliably detect and automate this in future?
# apply the new tags to the existing images
- name: Push updated image tags
uses: akhilerm/tag-push-action@v2.1.0
with:
src: ${{ env.registry }}/${{ env.REPO_OWNER_LOWER }}/${{ env.image-name }}:${{ github.sha }}
dst: |
${{ steps.meta.outputs.tags }}