Update CI and fix PR #27
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: Set base branch | |
# id: base_branch | |
# run: echo "::set-output name=base::$(git merge-base HEAD ${{ github.event.before }})" | |
- 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)" | |
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 }} | |
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 subfolder name | |
run: echo "::set-env name=SUBFOLDER::$(dirname $(find . -name Dockerfile))" | |
- name: Docker Metadata action | |
id: meta | |
uses: docker/[email protected] | |
with: | |
images: | | |
${{ secrets.DOCKER_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.SUBFOLDER }}/Dockerfile | |
context: . | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
push: ${{ github.event_name == 'pull_request' }} |