Skip to content

updated how extracting tag annotation #3

updated how extracting tag annotation

updated how extracting tag annotation #3

Workflow file for this run

name: Build and Push Docker Images
on:
push:
tags:
- '*'
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get the latest tag
id: get-tag
run: |
TAG=$(git describe --tags --abbrev=0)
echo "TAG=$TAG" >> $GITHUB_ENV
- name: Extract image name from tag message
id: extract-image-name
run: |
TAG_MESSAGE=$(git tag -n1 ${{ env.TAG }})
echo ${{ env.TAG }} $TAG_MESSAGE
if [[ "$TAG_MESSAGE" =~ build\/([^ ]+) ]]; then
IMAGE_NAME=${BASH_REMATCH[1]}
echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV
else
echo "No valid image name specified in tag message."
exit 1
fi
- name: Verify Dockerfile exists
run: |
if [ ! -f "$IMAGE_NAME/Dockerfile" ]; then
echo "Dockerfile not found in the specified directory: $IMAGE_NAME"
exit 1
fi
- uses: docker/setup-qemu-action@v2
with:
platforms: amd64
- uses: docker/setup-buildx-action@v2
- uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
uses: docker/metadata-action@v4
id: meta
with:
images: ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
file: ${{ env.IMAGE_NAME }}/Dockerfile
context: .
platforms: linux/amd64
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest
labels: ${{ steps.meta.outputs.labels }}