Skip to content

testing workflow

testing workflow #1

name: Build and Push Docker Image
on:
release:
types: [created]
workflow_dispatch:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+-dev'
- '[0-9]+.[0-9]+.[0-9]+-dev.[0-9]+'
- '[0-9]+.[0-9]+.[0-9]+-rc'
- '[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+'
- '[0-9]+.[0-9]+.[0-9]+'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
name: Build and Push Docker Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract tag name
id: vars
run: |
TAG_NAME=${GITHUB_REF#refs/tags/}
echo "tag=${TAG_NAME}" >> $GITHUB_OUTPUT
# Check if it's a release version (not a pre-release)
if [[ "$TAG_NAME" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "latest=true" >> $GITHUB_OUTPUT
else
echo "latest=false" >> $GITHUB_OUTPUT
fi
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: src/docker/Dockerfile
push: true
build-args: |
IMAGE_TAG=${{ steps.vars.outputs.tag }}
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.tag }}
${{ steps.vars.outputs.latest == 'true' && format('{0}/{1}:latest', env.REGISTRY, env.IMAGE_NAME) || '' }}
labels: |
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.version=${{ steps.vars.outputs.tag }}
org.opencontainers.image.created=${{ github.event.head_commit.timestamp || github.event.release.published_at || github.event.repository.updated_at }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.title=${{ github.repository }}
- name: Confirm tags pushed
run: |
echo "Published ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.tag }}"
if [ "${{ steps.vars.outputs.latest }}" = "true" ]; then
echo "Also tagged as :latest"
fi