Skip to content

update codecov workflow #3

update codecov workflow

update codecov workflow #3

Workflow file for this run

name: Build and Push Docker on PRs
on:
pull_request:
branches: [ "main" ]
jobs:
check-dockerfile-changes:
if: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
outputs:
affected_folder: ${{ steps.affected-folder.outputs.AFFECTED_FOLDER }}
image_name_folder: ${{ steps.affected-folder.outputs.IMAGE_NAME_FOLDER }}
steps:
- name: Checkout repo
uses: actions/[email protected]
- name: Log in to Docker Hub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Determine affected folder
id: affected-folder
run: |
git remote update
git fetch
AFFECTED_FOLDER=$(git diff --name-only origin/main..origin/${{ github.head_ref }} | grep -i 'Dockerfile' | xargs -I {} dirname {} | sort -u)
IMAGE_NAME_FOLDER=$(git diff --name-only origin/main..origin/${{ github.head_ref }} | grep -i 'Dockerfile' | xargs -I {} dirname {} | sort -u | awk -F/ '{print $(NF-0)}')
echo "AFFECTED_FOLDER=$AFFECTED_FOLDER" >> $GITHUB_OUTPUT
echo "IMAGE_NAME_FOLDER=$IMAGE_NAME_FOLDER" >> $GITHUB_OUTPUT
echo "Affected folders: $AFFECTED_FOLDER"
echo "Image name folder: $IMAGE_NAME_FOLDER"
if [[ $AFFECTED_FOLDER == '' ]]; then
echo "========= No Dockerfile affected on this PR ========="
exit 0
fi
- name: Set Repo Name
id: repo-name
run: |
echo "REPO=natandias1" >> $GITHUB_OUTPUT
build-and-push:
needs: check-dockerfile-changes
if: ${{ github.event_name == 'pull_request' && needs.check-dockerfile-changes.outputs.AFFECTED_FOLDER != '' }}
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/[email protected]
- name: Log in to Docker Hub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Set Repo Name
id: repo-name
run: |
echo "REPO=natandias1" >> $GITHUB_ENV
- name: Docker Metadata action
id: meta
uses: docker/[email protected]
with:
images: ${{ env.REPO }}/${{ needs.check-dockerfile-changes.outputs.IMAGE_NAME_FOLDER }}
tags: |
type=ref,event=branch
type=ref,event=pr
flavor: |
latest=false
- name: Build and push Docker images
uses: docker/[email protected]
with:
file: ${{ needs.check-dockerfile-changes.outputs.AFFECTED_FOLDER }}/Dockerfile
context: .
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: ${{ github.event_name == 'pull_request' }}
- name: Check status
run: echo "Dockerfile check complete"