Skip to content

Release - Tag Based #22

Release - Tag Based

Release - Tag Based #22

name: Release - Tag Based
on:
workflow_dispatch:
inputs:
releaseType:
description: 'Release Type (patch/minor/major)'
required: true
default: 'patch'
appName:
description: 'Application Name (data/sample)'
required: true
default: 'data'
branches:
- master
- release/*
jobs:
# sanity-check:
# runs-on: ubuntu-latest
# steps:
# - name: Check branch for patch release
# if: ${{ github.event.inputs.releaseType == 'patch' }}
# run: |
# BRANCH_NAME=$(echo $GITHUB_REF | sed 's/refs\/heads\///')
# if [[ $BRANCH_NAME == release* ]]; then
# echo "Valid branch for patch release."
# else
# echo "::error::Patch releases are only allowed on branches prefixed with 'release'."
# exit 1
# fi
sanity-check:
runs-on: ubuntu-latest
steps:
- name: Check branch for patch release
if: ${{ github.event.inputs.releaseType == 'patch' }}
run: |
echo "Valid branch for patch release."
build-docker-image:
needs: sanity-check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Log in to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ vars.USERNAME }}
password: ${{ secrets.TOKEN }}
- name: Build Docker image with 'latest' tag
uses: docker/build-push-action@v2
with:
context: ./ckan
file: ./ckan/Dockerfile
push: true
tags: ghcr.io/auscope/auscope-ckan:latest
prepare-release:
needs: build-docker-image
runs-on: ubuntu-latest
outputs:
new-version: ${{ steps.bump_version.outputs.version }}
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install bump2version
run: pip install bump2version
- name: Set up Git identity
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "GitHub Actions"
- name: Bump version
id: bump_version
run: |
bump2version ${{ github.event.inputs.releaseType }} --config-file ./ckan/setup.cfg
NEW_VERSION=$(grep 'current_version = ' ./ckan/setup.cfg | sed -r 's/current_version = //')
echo "::set-output name=version::$NEW_VERSION"
- name: Push the tags and changes
run: |
git push origin --tags
git push
retag-and-push-docker-image:
needs: prepare-release
runs-on: ubuntu-latest
steps:
- name: Log in to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ vars.USERNAME }}
password: ${{ secrets.TOKEN }}
- name: Pull 'latest' Docker image
run: docker pull ghcr.io/auscope/auscope-ckan:latest
- name: Tag Docker image with new version and AppName
run: docker tag ghcr.io/auscope/auscope-ckan:latest ghcr.io/auscope/auscope-ckan:${{ github.event.inputs.AppName }}-${{ needs.prepare-release.outputs.new-version }}
- name: Push Docker image with new version
run: docker push ghcr.io/auscope/auscope-ckan:${{ github.event.inputs.AppName }}-${{ needs.prepare-release.outputs.new-version }}