diff --git a/.github/workflows/push-registrar-image.yaml b/.github/workflows/push-registrar-image.yaml index b10114d..aefb134 100644 --- a/.github/workflows/push-registrar-image.yaml +++ b/.github/workflows/push-registrar-image.yaml @@ -1,6 +1,12 @@ name: Build and Push Docker Images on: + workflow_dispatch: + inputs: + branch: + description: "Target branch from which the source Dockerfile will be sourced" + required: true + pull_request: branches: - '**' # Trigger workflow on commits to any branch in a PR @@ -12,10 +18,17 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 + with: + ref: ${{ github.event.inputs.branch || github.head_ref }} - - name: Get commit SHA for tagging - id: get-commit-sha - run: echo "COMMIT_SHA=${GITHUB_SHA::8}" >> $GITHUB_ENV + - name: Get tag for the image + id: get-tag + run: | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + echo "TAG=${{ github.event.inputs.branch }}" >> $GITHUB_ENV + else + echo "TAG=${GITHUB_SHA::8}" >> $GITHUB_ENV + # This sets the tag to the branch name for manual trigger and commit SHA for PR - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -35,7 +48,7 @@ jobs: file: ./dockerfiles/registrar.Dockerfile push: true target: dev - tags: farhan943/practise:${{ env.COMMIT_SHA }} # Use commit SHA as tag + tags: farhan943/practise:${{ env.TAG }} - name: Send failure notification if: failure() @@ -45,7 +58,7 @@ jobs: server_port: 465 username: ${{ secrets.edx_smtp_username }} password: ${{ secrets.edx_smtp_password }} - subject: Docker Image push failed for commit ${{ env.COMMIT_SHA }} + subject: Docker image push failed for ${{ env.TAG }} to: muhammad.farhan@arbisoft.com from: github-actions - body: Docker image push failed for PR commit! For details see "github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" + body: Docker image push failed for tag ${{ env.TAG }}! For details see "github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"