tag_created #21
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: 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: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- 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 for default branch | |
type=raw,value=latest,enable={{is_default_branch}} | |
# Set specific version from dispatch or git tag | |
type=raw,value=${{ github.event.client_payload.tag_name || github.ref_name }} | |
# 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 | |
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: Create Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
tag_name: ${{ github.ref_name }} | |
name: Release ${{ github.ref_name }} | |
body: Automated release for tag ${{ github.ref_name }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |