docker fixed version tag for dev run

This commit is contained in:
aman-17 2025-05-22 16:15:42 -07:00
parent 21e5ab5dd0
commit 90342efc7e

View File

@ -7,6 +7,11 @@ on:
- 'v*'
- '*.*.*'
workflow_dispatch:
inputs:
version:
description: 'Version (e.g., 1.0.0) - leave empty for dev build'
required: false
type: string
env:
REGISTRY: docker.io
@ -43,6 +48,26 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Calculate version tags
id: version
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]] && [[ -n "${{ github.event.inputs.version }}" ]]; then
VERSION="${{ github.event.inputs.version }}"
VERSION="${VERSION#v}" # Remove v prefix if present
# Split version into parts
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
# Generate tags
echo "tags<<EOF" >> $GITHUB_OUTPUT
echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${VERSION}" >> $GITHUB_OUTPUT
echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${MAJOR}.${MINOR}" >> $GITHUB_OUTPUT
echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${MAJOR}" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_OUTPUT
fi
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
@ -54,14 +79,24 @@ jobs:
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value={{date 'YYYYMMDD-HHmmss'}}-{{sha}},enable=${{ github.event_name == 'workflow_dispatch' }}
type=raw,value=dev-{{date 'YYYYMMDD'}}-{{sha}},enable=${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version == '' }}
flavor: |
latest=false
- name: Override tags for manual version
id: tags
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]] && [[ -n "${{ github.event.inputs.version }}" ]]; then
echo "tags=${{ steps.version.outputs.tags }}" >> $GITHUB_OUTPUT
else
echo "tags=${{ steps.meta.outputs.tags }}" >> $GITHUB_OUTPUT
fi
- name: Debug metadata
run: |
echo "Tags: ${{ steps.meta.outputs.tags }}"
echo "Final Tags: ${{ steps.tags.outputs.tags }}"
echo "Labels: ${{ steps.meta.outputs.labels }}"
echo "Version: ${{ steps.version.outputs.version || steps.meta.outputs.version }}"
- name: Build and push Docker image
uses: docker/build-push-action@v5
@ -69,7 +104,7 @@ jobs:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
tags: ${{ steps.tags.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64
outputs: type=registry