Skip to content

Merge pull request #117 from Deeksha1502/github-actions-fix #2

Merge pull request #117 from Deeksha1502/github-actions-fix

Merge pull request #117 from Deeksha1502/github-actions-fix #2

Workflow file for this run

name: Build and Publish Docker Image
on:
push:
tags:
- "*"
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive
token: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get short commit hash
id: vars
run: echo "commit_hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Prepare Docker image name and tag
run: |
REPO_NAME_LOWERCASE=$(echo "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]')
TAG_NAME=$(echo "${GITHUB_REF_NAME}" | tr '[:upper:]' '[:lower:]')
BUILD_TAG="${TAG_NAME}-${{ steps.vars.outputs.commit_hash }}-${GITHUB_RUN_NUMBER}"
echo "IMAGE_NAME=ghcr.io/${REPO_NAME_LOWERCASE}" >> $GITHUB_ENV
echo "IMAGE_TAG=${BUILD_TAG}" >> $GITHUB_ENV
echo "Generated Image Name: ${IMAGE_NAME}"
echo "Generated Image Tag: ${IMAGE_TAG}"
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
labels: commitHash=${{ steps.vars.outputs.commit_hash }}
tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}