From c98d91f029b5c9247c9a6b8d43c77a5df68b6128 Mon Sep 17 00:00:00 2001 From: Daniel Stevens Date: Tue, 29 Oct 2024 13:28:09 -0600 Subject: [PATCH] Make build dependent on detecting changes on the branch We only run the workflow when there are changes to the docker folder (or the workflow itself), and we only want to run jobs for platforms that have an updated Docker image to build. Of course we can't detect that change at the job level, so instead we disable the steps to build and push the Docker image when there are no changes for the current platform. --- .github/workflows/dockerBuild.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/dockerBuild.yml b/.github/workflows/dockerBuild.yml index 2f89be90..a94dbe35 100644 --- a/.github/workflows/dockerBuild.yml +++ b/.github/workflows/dockerBuild.yml @@ -26,11 +26,25 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Fetch main + run: | + git remote set-branches --add origin main + git fetch --depth 1 + + - name: Check for changes + id: diff + run: | + set +e + git diff --exit-code --no-patch origin/main docker/nas2d-${{ matrix.platform }}.* ; echo "modified=$?" >> $GITHUB_OUTPUT + - name: Docker build + if: ${{ fromJSON(steps.diff.outputs.modified) }} run: make -C docker build-image-${{ matrix.platform }} - name: Docker login + if: ${{ fromJSON(steps.diff.outputs.modified) }} run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io --username "${{ github.repository_owner }}" --password-stdin - name: Docker push + if: ${{ fromJSON(steps.diff.outputs.modified) }} run: make -C docker push-image-${{ matrix.platform }}