Merge pull request #124 from topolvm/fix-cronjob-name #22
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Release" | |
on: | |
push: | |
tags: | |
- "v*" | |
jobs: | |
release: | |
name: "release" | |
runs-on: "ubuntu-22.04" | |
steps: | |
- name: "Validate Release Version" | |
id: check_version | |
run: | | |
VERSION=$(echo $GITHUB_REF | sed -ne 's/[^0-9]*\([0-9]\+\.[0-9]\+\.[0-9]\+\(-.*\)\?\).*/\1/p') | |
if [ "$VERSION" = "" ]; then | |
echo "Invalid version format. $GITHUB_REF" | |
exit 1 | |
fi | |
if [ $(echo $VERSION | grep "-") ]; then PRERELEASE=true; else PRERELEASE=false; fi | |
echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
echo "prerelease=${PRERELEASE}" >> $GITHUB_OUTPUT | |
- name: "Export IMAGE_PREFIX" | |
run: | | |
if [ "${{ secrets.IMAGE_PREFIX }}" != "" ]; then IMAGE_PREFIX=${{ secrets.IMAGE_PREFIX }}; else IMAGE_PREFIX=ghcr.io/topolvm/; fi | |
echo "IMAGE_PREFIX=${IMAGE_PREFIX}" >> $GITHUB_ENV | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v5 | |
with: | |
go-version-file: "go.mod" | |
- run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
- run: make docker-build IMG=ghcr.io/topolvm/pie:${{ steps.check_version.outputs.version }} | |
- run: docker push ghcr.io/topolvm/pie:${{ steps.check_version.outputs.version }} | |
- name: "Push branch tag" | |
if: ${{ steps.check_version.outputs.prerelease == 'false' }} | |
run: | | |
BRANCH=$(echo ${{ steps.check_version.outputs.version }} | cut -d "." -f 1-2) | |
docker tag ghcr.io/topolvm/pie:${{ steps.check_version.outputs.version }} ghcr.io/topolvm/pie:${BRANCH} | |
docker push ghcr.io/topolvm/pie:${BRANCH} | |
- name: "Get previous tag" | |
id: get_previous_tag | |
run: | | |
# see https://docs.github.com/en/rest/git/refs?apiVersion=2022-11-28#list-matching-references | |
RESP=$(gh api \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
/repos/${{ github.repository }}/git/matching-refs/tags/v) | |
PREV_TAG=$(echo ${RESP} | jq -r '.[].ref' | awk -F "/" '{print $3}' | \ | |
grep -E "^v[0-9]+\.[0-9]+\.[0-9]+" | sort -V -r | tail -n +2 | head -n 1) | |
if [ -z "${PREV_TAG}" ]; then | |
echo "PREV_TAG is empty." | |
exit 1 | |
fi | |
echo "previous_tag=${PREV_TAG}" >> ${GITHUB_OUTPUT} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: "Create Release" | |
id: create_release | |
run: | | |
# see https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#create-a-release | |
gh api \ | |
-H "Accept: application/vnd.github+json" \ | |
--method POST \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
/repos/${{ github.repository }}/releases \ | |
-f name="Release ${GITHUB_REF_NAME}" \ | |
-f tag_name="${GITHUB_REF_NAME}" \ | |
-f previous_tag_name="${{ steps.get_previous_tag.outputs.previous_tag }}" \ | |
-F draft=true \ | |
-F prerelease=${{ steps.check_version.outputs.prerelease }} \ | |
-F generate_release_notes=true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |