Implement semver for container images

When release git tags are pushed for:

airshipctl e.g. v1.2.3
krm functions e.g. replacement-transformer-v1.2.3

This publishes corresponding image tags to the corresponding quay repo
e.g. 1.2.3 (full), 1.2 (minor), 1 (major).

This follows common practice [0] allowing consumers to keep up to date with
latest changes, while at the same time avoiding risk i.e. breaking changes.

The quay secrets have been imported into github [1] to be accessed
by this github action.

[0]: https://medium.com/@mccode/using-semantic-versioning-for-docker-image-tags-dfde8be06699
[1]: https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets

Closes: #418
Change-Id: Iba2522bcb5d5693fa0e98126bcf31551bb37fc85
This commit is contained in:
Sean Eagan 2020-12-09 10:45:25 -06:00 committed by Kostyantyn Kalynovskyi
parent 8efb786a6a
commit c89b5c21b4

View File

@ -12,13 +12,84 @@
name: release
# Expects git tags in the following formats:
# airshipctl: v1.2.3 (no prefix)
# krm functions: <quay image name>-v1.2.3 e.g. replacement-transformer-v1.2.3
on:
push:
tags:
- 'v*'
- '*'
jobs:
release:
# Parses git tags to determine quay image name and semver version and publishes
# corresponding image tags in quay for the full semver version as well as major
# and minor versions if not a prerelease.
release-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Calculate semver tags
id: semver_tags
run: |
set -x
set -e
TAG=$(echo "${TAG_REF}" | sed -e 's|refs/tags/||')
for i in '' replacement-transformer- templater-
do
if [[ "$TAG" =~ ^($i)?v?(([0-9]+)\.([0-9]+)\.([0-9]+)(-[a-zA-Z]+(\.[0-9]+)?)?)$ ]]
then
if [[ -z ${BASH_REMATCH[1]} ]]
then
IMG=airshipctl
else
IMG=${i%-}
fi
TAGS="${BASH_REMATCH[2]}"
# Prereleases don't count as major and minor
if [[ -z ${BASH_REMATCH[6]} ]]
then
MINOR_TAG="${BASH_REMATCH[3]}.${BASH_REMATCH[4]}"
MAJOR_TAG="${BASH_REMATCH[3]}"
TAGS="$TAGS $MINOR_TAG $MAJOR_TAG"
fi
echo ::set-output name=IMG::$IMG
echo ::set-output name=TAGS::$TAGS
exit 0
fi
done
echo No valid semver tag found
exit 1
env:
TAG_REF: ${{ github.ref }}
- name: Login to image registry
uses: docker/login-action@v1
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
- name: Publish semver image tags
run: |
set -x
set -e
SOURCE_TAG=$IMG:$SOURCE
docker pull $SOURCE_TAG
for i in $TARGETS
do
TARGET_TAG=$IMG:$i
docker tag $SOURCE_TAG $TARGET_TAG
docker push $TARGET_TAG
done
env:
IMG: ${{ format('quay.io/airshipit/{0}', steps.semver_tags.outputs.IMG) }}
SOURCE: ${{ github.sha }}
TARGETS: ${{ steps.semver_tags.outputs.TAGS }}
release-github:
# Only create github releases for airshipctl (unprefixed semver tag), not krm functions.
if: ${{ startsWith(github.ref, 'v') }}
runs-on: ubuntu-latest
steps:
- name: Checkout