Skip to content

Commit

Permalink
try to move conditional path checking to a step in job so workflow ca…
Browse files Browse the repository at this point in the history
…n always be a required status

Use 'if' for steps
  • Loading branch information
peteski22 committed Nov 18, 2024
1 parent 9a89c11 commit d9e242b
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions .github/workflows/build_images_uv.yaml
Original file line number Diff line number Diff line change
@@ -1,46 +1,59 @@
name: Docker image CI

on:
pull_request:
paths:
- "lumigator/**"
- ".github/**"
# synchronized is when you push new commits
types: ["opened", "synchronize"]
push:
branches:
- main
- "main"
pull_request:
branches:
- "**"
# required to enable manual triggers on the GH web ui
workflow_dispatch:

jobs:
build:
build-image:
name: Build Docker image
runs-on: ubuntu-latest

steps:
- name: Checkout
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check modified paths
run: |
if git diff --name-only ${{ github.event.before }} ${{ github.event.pull_request.head.sha }} | grep -E '^lumigator/|^\.github/'; then
echo "Changes detected. Rebuilding image..."
is_image_build_required=true
else
echo "No relevant changes detected."
is_image_build_required=false
fi
echo "is_image_build_required=$is_image_build_required" >> $GITHUB_OUTPUT
- name: Get repo version
if: ${{ steps.vars.outputs.is_image_build_required }}
run: |
echo "REPOVERSION=$(git describe --tags --dirty --match \"[0-9\.]*\" --always)" >> $GITHUB_ENV
echo "Version of the repo for this build: $REPOVERSION"
- name: Set up QEMU
if: ${{ steps.vars.outputs.is_image_build_required }}
uses: docker/setup-qemu-action@v3

- name: Set up Docker buildx
if: ${{ steps.vars.outputs.is_image_build_required }}
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
if: ${{ steps.vars.outputs.is_image_build_required && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
if: ${{ steps.vars.outputs.is_image_build_required }}
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
Expand Down

0 comments on commit d9e242b

Please sign in to comment.