Update CI and fix PR #37
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
#push: | |
# branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
check-dockerfile-changes: | |
name: Check Dockerfile changes | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repo | |
uses: actions/[email protected] | |
with: | |
fetch-depth: 0 | |
#- name: Add origin remote | |
# id: main-remote | |
# run: git fetch origin main:refs/remotes/origin/main | |
#- name: Add origin new | |
# id: main-new | |
# run: git rev-list --count origin/main..$(git branch --show-current) | |
- name: Check Dockerfile changes | |
id: check | |
run: echo "::set-output name=changed::$(if git diff --name-only remotes/origin/${{ github.base_ref }}..remotes/origin/${{ github.head_ref }} | grep -q 'Dockerfile'; then echo true; else echo false; fi)" | |
# Uncomment if you need to DEBUG | |
#- name: Debug changed value | |
# run: echo ${{ steps.check.outputs.changed }} | |
build-and-push-to-registry: | |
needs: check-dockerfile-changes | |
name: Push Docker image to Docker HUB | |
runs-on: ubuntu-latest | |
if: ${{ needs.check-dockerfile-changes.outputs.changed }} == true | |
env: | |
REPO: ${{ secrets.DOCKER_REPO }} | |
FOLDER: | |
SUBFOLDER: | |
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 folder name | |
id: set-folder | |
run: | | |
FOLDER=$(dirname $(find . -name Dockerfile)) | |
echo "FOLDER=$FOLDER" >> $GITHUB_ENV | |
- name: Set subfolder name | |
id: set-subfolder | |
run: | | |
SUBFOLDER=$(dirname $(find . -name Dockerfile)) | xargs basename | |
echo "SUBFOLDER=$SUBFOLDER" >> $GITHUB_ENV | |
- name: Docker Metadata action | |
id: meta | |
uses: docker/[email protected] | |
with: | |
images: | | |
${{ env.REPO }}/${{ env.SUBFOLDER}} | |
tags: | | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{major}}.{{minor}}.{{patch}} | |
- name: Build and push Docker images | |
uses: docker/[email protected] | |
with: | |
file: ${{ env.FOLDER }}/Dockerfile | |
context: . | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
push: ${{ github.event_name == 'pull_request' }} |