Skip to content

tag_created

tag_created #32

Workflow file for this run

name: Build and Release Docker Image
on:
push:
tags:
- 'v*' # Trigger on tags starting with 'v' (e.g., v1.0.0)
workflow_dispatch: # Allow manual triggering
repository_dispatch:
types: [tag_created]
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get tag without v prefix
id: tag_name
run: |
TAG=${{ github.event.client_payload.tag_name || github.ref_name }}
echo "tag_without_v=${TAG#v}" >> $GITHUB_OUTPUT
# Extract major version (2022)
MAJOR=$(echo ${TAG#v} | cut -d'.' -f1)
echo "major=${MAJOR}" >> $GITHUB_OUTPUT
echo "major_with_v=v${MAJOR}" >> $GITHUB_OUTPUT
# Extract major.minor version (2022.01)
MAJOR_MINOR=$(echo ${TAG#v} | cut -d'.' -f1,2)
echo "major_minor=${MAJOR_MINOR}" >> $GITHUB_OUTPUT
echo "major_minor_with_v=v${MAJOR_MINOR}" >> $GITHUB_OUTPUT
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64/v8,linux/arm/v7
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
# generate Docker tags based on the following events/attributes
tags: |
# Set latest tag only for default branch
type=raw,value=latest,enable={{is_default_branch}}
# Set specific version from dispatch or git tag (with v prefix)
type=raw,value=${{ github.event.client_payload.tag_name || github.ref_name }}
# Set specific version without v prefix
type=raw,value=${{ steps.tag_name.outputs.tag_without_v }}
# Add major version tags (with and without v)
type=raw,value=${{ steps.tag_name.outputs.major_with_v }}
type=raw,value=${{ steps.tag_name.outputs.major }}
# Add major.minor version tags (with and without v)
type=raw,value=${{ steps.tag_name.outputs.major_minor_with_v }}
type=raw,value=${{ steps.tag_name.outputs.major_minor }}
# Add version tags
type=ref,event=tag
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
# Add sha for traceability
type=sha,format=long
type=sha,format=short
- name: Build Docker image
uses: docker/build-push-action@v6
with:
context: . # Or specify a subdirectory if needed
file: ./Dockerfile # Path to your Dockerfile
push: true
platforms: linux/amd64,linux/arm64/v8
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
create-release:
needs: build-and-push # Run after the build job
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate Release Notes
uses: actions/github-script@v7
id: release-notes
with:
script: |
const tag = context.payload.client_payload?.tag_name || context.ref.replace('refs/tags/', '');
const response = await github.rest.repos.generateReleaseNotes({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tag,
});
return response.data.body;
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.event.client_payload.tag_name || github.ref_name }}
name: Release ${{ github.event.client_payload.tag_name || github.ref_name }}
body: ${{ steps.release-notes.outputs.result }}
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}