Publish Odiglet Base Builder #5
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: Publish Odiglet Base Builder | |
on: | |
workflow_dispatch: | |
inputs: | |
image_tag: | |
description: 'The new image tag for the base builder docker image (e.g. v1.0)' | |
required: true | |
permissions: | |
contents: write | |
packages: write | |
env: | |
DOCKERHUB_ORG: "keyval" | |
jobs: | |
publish-odiglet-base-builder: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Validate New Version | |
run: | | |
# Fetch tags from Docker Hub | |
TAGS=$(curl -s "https://hub.docker.com/v2/repositories/${{ env.DOCKERHUB_ORG }}/odiglet-base/tags/" | jq -r '.results[].name' | sort -Vr) | |
# Extract the latest version | |
LATEST_VERSION=$(echo "$TAGS" | head -n 1) | |
# New version from workflow input | |
NEW_VERSION=${{ github.event.inputs.image_tag }} | |
# Parse major and minor from latest and new versions | |
LATEST_MAJOR=$(echo $LATEST_VERSION | cut -d. -f1) | |
LATEST_MINOR=$(echo $LATEST_VERSION | cut -d. -f2) | |
NEW_MAJOR=$(echo $NEW_VERSION | cut -d. -f1) | |
NEW_MINOR=$(echo $NEW_VERSION | cut -d. -f2) | |
# Compare versions | |
if [[ $NEW_MAJOR -eq $((LATEST_MAJOR + 1)) && $NEW_MINOR -eq 0 ]]; then | |
echo "New version is a valid major version increment." | |
elif [[ $NEW_MAJOR -eq $LATEST_MAJOR && $NEW_MINOR -eq $((LATEST_MINOR + 1)) ]]; then | |
echo "New version is a valid minor version increment." | |
else | |
echo "Error: New version $NEW_VERSION does not follow the versioning rules." | |
exit 1 | |
fi | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Publish Odiglet Base Builder | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64 | |
file: ./odiglet/base.Dockerfile | |
push: true | |
tags: ${{ env.DOCKERHUB_ORG }}/odiglet-base:${{ github.event.inputs.image_tag }} |