Skip to content

Change deploy workflow to run on PRs only with [push image] message #23

Change deploy workflow to run on PRs only with [push image] message

Change deploy workflow to run on PRs only with [push image] message #23

Workflow file for this run

name: Deploy image to Docker Hub
on:
push:
branches:
- master
pull_request:
jobs:
check_skip_flags:
name: Check skip flags
runs-on: ubuntu-latest
outputs:
head-commit-message: ${{ steps.get_head_commit_message.outputs.HEAD_COMMIT_MESSAGE }}
steps:
- name: Checkout Commit
uses: actions/checkout@v3
with:
ref: ${{ env.GITHUB_SHA }}
- name: Get Head Commit Message
id: get_head_commit_message
run: echo "HEAD_COMMIT_MESSAGE=$(git show -s --format=%s)" >> "$GITHUB_OUTPUT"
- name: Debug Commit Message
run: |
echo "Commit Message= ${{ steps.get_head_commit_message.outputs.HEAD_COMMIT_MESSAGE }}"
echo "Head_commit_message = $HEAD_COMMIT_MESSAGE"
echo "Github Output = $GITHUB_OUTPUT"
echo "Github Sha = ${{ env.GITHUB_SHA }}"
echo "Github event = ${{ github.event.head_commit.message }}"
echo "Github event[0] = ${{ github.event.commits[0].message }}"
echo "Github commit = $(git log -1 --no-merges --pretty=%B)"
echo "Github ENV = $GITHUB_ENV"
build-and-push-docker-image:
runs-on: ubuntu-latest
needs: check_skip_flags
if: |
github.event_name == 'push' || (
github.event_name == 'pull_request' &&
contains(${{ github.event.head_commit.message }}, '[push image]')
)
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Debug Commit Message
run: echo "Commit Message= ${{ needs.check_skip_flags.outputs.head-commit-message }}"
# - name: Set up JDK
# uses: actions/setup-java@v4
# with:
# distribution: 'temurin'
# java-version: '17'
#
# - name: Build with Gradle
# run: ./gradlew clean build
#
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3
#
# - name: Login to Docker Hub
# uses: docker/login-action@v1
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}
#
# - name: Determine Docker Tag [branch_name/latest]
# id: docker_tag
# run: |
# if [ -n "$GITHUB_HEAD_REF" ]; then
# echo "Setting tag to branch name: $GITHUB_HEAD_REF"
# echo "::set-output name=tag::$GITHUB_HEAD_REF"
# else
# echo "Setting tag to 'latest'"
# echo "::set-output name=tag::latest"
# fi
#
# - name: Build and push Docker image
# env:
# DOCKER_REPO: viepovsky/car-service-garage-backend
# DOCKER_TAG: ${{ steps.docker_tag.outputs.tag }}
# run: |
# docker buildx create --use
# docker buildx build -t $DOCKER_REPO:$DOCKER_TAG --push .