Skip to content

Update

Update #68

Workflow file for this run

name: Update
env:
IMAGE_NAME: arkmq-org-broker-kubernetes
on:
workflow_dispatch:
inputs:
version:
description: 'Version, i.e. 1.0.0'
required: false
default: '*.*.+'
type: string
update_version:
description: 'Update version'
required: true
default: true
type: boolean
base_image:
description: 'Base image'
required: false
default: 'latest'
type: string
update_base_image:
description: 'Update base image'
required: true
default: true
type: boolean
yacfg_version:
description: 'YAML Configurator Version, i.e. v0.9.3'
required: false
default: 'latest'
type: string
update_yacfg_version:
description: 'Update yacfg version'
required: true
default: true
type: boolean
trigger_release:
description: 'Trigger release'
required: false
default: 'this'
type: choice
options:
- none
- this
- all
jobs:
update:
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v6
with:
token: ${{ secrets.BOT_TOKEN }}
- name: Set up the repo
run: |
git config user.name 'arkmq-bot'
git config user.email 'bot@arkmq.org'
- name: Update version
if: ${{ inputs.update_version }}
run: |
CURRENT_VERSION=$(grep -m 1 -oP '(?<=LABEL version=")[^"]+' Dockerfile)
IFS=. read CURRENT_VERSION_MAJOR CURRENT_VERSION_MINOR CURRENT_VERSION_PATCH <<< ${CURRENT_VERSION}
IFS=. read VERSION_MAJOR VERSION_MINOR VERSION_PATCH <<< ${{ inputs.version }}
VERSION_MAJOR=${VERSION_MAJOR/\*/${CURRENT_VERSION_MAJOR}} && VERSION_MAJOR=${VERSION_MAJOR/+/$((CURRENT_VERSION_MAJOR+1))}
VERSION_MINOR=${VERSION_MINOR/\*/${CURRENT_VERSION_MINOR}} && VERSION_MINOR=${VERSION_MINOR/+/$((CURRENT_VERSION_MINOR+1))}
VERSION_PATCH=${VERSION_PATCH/\*/${CURRENT_VERSION_PATCH}} && VERSION_PATCH=${VERSION_PATCH/+/$((CURRENT_VERSION_PATCH+1))}
VERSION="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}"
sed -i "s~^LABEL version=.*~LABEL version=\"${VERSION}\"~g" Dockerfile
git commit --all --message "Update version to ${VERSION}" || echo "nothing to commit"
- name: Update base image
if: ${{ inputs.update_base_image }}
run: |
if [ "${{ inputs.base_image }}" = "latest" ]; then
BASE_IMAGE="quay.io/${{ secrets.QUAY_NAMESPACE }}/arkmq-org-broker-kubernetes@$(skopeo inspect docker://quay.io/${{ secrets.QUAY_NAMESPACE }}/arkmq-org-broker-kubernetes:latest | jq -r '.Digest')"
else
BASE_IMAGE="${{ inputs.base_image }}"
fi
sed -i "s~FROM.*~FROM ${BASE_IMAGE}~g" Dockerfile
git commit --all --message "[NO-ISSUE] Update base image to ${BASE_IMAGE}" || echo "nothing to commit"
- name: Update YAML Configurator
if: ${{ inputs.update_yacfg_version }}
run: |
if [ "${{ inputs.yacfg_version }}" = "latest" ]; then
YACFG_VER="$(git ls-remote --tags https://github.com/arkmq-org/yacfg.git | grep -oP '(?<=refs/tags/)v\d+.\d+.\d' | sort --reverse --version-sort | head -n 1)"
else
YACFG_VER="${{ inputs.yacfg_version }}"
fi
YACFG_REP='https://github.com/arkmq-org/yacfg.git'
YACFG_REF=$(git ls-remote --tags ${YACFG_REP} | grep -oP ".*(?=refs/tags/${YACFG_VER}\^\{\}\$)" | tr -d '[:blank:]')
if [[ $YACFG_REF != "" ]]; then
echo "found annotated tag"
else
YACFG_REF=$(git ls-remote --tags ${YACFG_REP} | grep -oP ".*(?=refs/tags/${YACFG_VER}\$)" | tr -d '[:blank:]')
if [[ $YACFG_REF == "" ]]; then
echo "tag ${YACFG_VER} not found!"
exit 1
fi
fi
echo "found tag $YACFG_VER point to commit ref $YACFG_REF}"
sed -i -e "s~ARG REMOTE_SOURCE_REF=.*~ARG REMOTE_SOURCE_REF=${YACFG_REF}~" -e "s~ARG REMOTE_SOURCE_REP=.*~ARG REMOTE_SOURCE_REP=${YACFG_REP}~" Dockerfile
git commit --all --message "[NO-ISSUE] Update YAML Configurator to ${YACFG_VER}" || echo "nothing to commit"
- name: Push commits
run: |
git push
- name: Trigger CI
if: ${{ inputs.trigger_release == 'this' || inputs.trigger_release == 'all' }}
env:
TRIGGER_CHILDREN: ${{ inputs.trigger_release == 'all' }}
uses: actions/github-script@v8
with:
github-token: ${{ secrets.BOT_TOKEN }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
ref: context.ref,
workflow_id: 'ci.yml',
inputs: {
trigger_children: process.env.TRIGGER_CHILDREN,
trigger_release: true
}
});