Skip to content

Commit

Permalink
fix(ci): Update strategy that checks if a Dockerfile was modified
Browse files Browse the repository at this point in the history
GitHub Actions gives us special variables that can be used to get the
last previous ref before the current one.

This works great for 'push' and 'pull_request' events, but we don't have
something similar for 'workflow_dispatch' events.

In the latter case, we just assume the last previous ref is the HEAD of
the 'master' branch.

Fixes #696
  • Loading branch information
guihkx committed Sep 12, 2024
1 parent 51ba67b commit ca298a2
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,19 @@ jobs:
run: |
set -ex
git remote add upstream https://github.com/nuttyartist/notes.git
git fetch --depth=1 upstream master
if git diff --compact-summary --exit-code upstream/master -- 'Dockerfiles/${{ matrix.image }}'
git fetch upstream master
# NOTE: The following should give us the previous commit hash of the base branch, but that will
# only work reliably for 'push' and pull_request events. For workflow_dispatch events, we
# have to fallback to the default branch ('master'), until a better solution is found...
previous_ref=${{ github.event.pull_request.base.sha || github.event.before || 'upstream/master' }}
if ! git diff --compact-summary --exit-code "${previous_ref}" -- 'Dockerfiles/${{ matrix.image }}'
then
needs_rebuild=true
elif ! docker pull '${{ env.REGISTRY }}/guihkx/notes:${{ matrix.image }}'
then
needs_rebuild=false
else
needs_rebuild=true
else
needs_rebuild=false
fi
echo "needs_rebuild=${needs_rebuild}" >> "${GITHUB_OUTPUT}"
Expand Down

0 comments on commit ca298a2

Please sign in to comment.