infra: actions: fix docker changes detector so it doesnt always build on force pushes
Some checks failed
Some checks failed
This commit is contained in:
@@ -16,20 +16,25 @@ jobs:
|
|||||||
id: image-changes
|
id: image-changes
|
||||||
# build image only if 1. changes are detected or 2. an image for the working branch doesnt exist
|
# build image only if 1. changes are detected or 2. an image for the working branch doesnt exist
|
||||||
run: |
|
run: |
|
||||||
|
echo "BEFORE = ${{ gitea.event.before }}"
|
||||||
branch_name="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
|
branch_name="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
|
||||||
|
default_branch_name="${{ gitea.event.repository.default_branch }}"
|
||||||
|
image_tag=latest
|
||||||
|
comparison_hash="${{ gitea.event.before }}"
|
||||||
|
|
||||||
if [[ "$branch_name" == "${{ gitea.event.repository.default_branch }}" ]]; then
|
git --no-pager reflog -n $(git rev-list --count HEAD ^origin/$default_branch_name)
|
||||||
image_tag=latest
|
if [[ "$branch_name" != "${{ gitea.event.repository.default_branch }}" ]]; then
|
||||||
else
|
|
||||||
image_tag=$branch_name
|
image_tag=$branch_name
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "branch_name=$branch_name" >> $GITEA_OUTPUT
|
|
||||||
# slugify
|
# slugify
|
||||||
image_tag="$(echo "$image_tag" | sed -E 's/[^a-zA-Z0-9]/-/g')"
|
image_tag="$(echo "$image_tag" | sed -E 's/[^a-zA-Z0-9]/-/g')"
|
||||||
echo "image_tag=$image_tag" >> $GITEA_OUTPUT
|
|
||||||
|
|
||||||
if ! git diff ${{ gitea.event.before }} ${{ gitea.sha }} --no-patch --exit-code .docker; then
|
# rebase breaks gitea.event.before, so check to make sure the hash provided exists
|
||||||
|
if ! git merge-base --is-ancestor $comparison_hash $branch_name >/dev/null 2>&1; then
|
||||||
|
comparison_hash=$(git merge-base origin/$default_branch_name $branch_name)
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! git diff $comparison_hash ${{ gitea.sha }} --no-patch --exit-code .docker; then
|
||||||
build_image=true
|
build_image=true
|
||||||
else
|
else
|
||||||
if ! docker manifest inspect ${{ vars.REGISTRY_URL }}/${{ gitea.repository }}:${image_tag} >/dev/null 2>&1; then
|
if ! docker manifest inspect ${{ vars.REGISTRY_URL }}/${{ gitea.repository }}:${image_tag} >/dev/null 2>&1; then
|
||||||
@@ -39,6 +44,10 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "default_branch_name=$default_branch_name"
|
||||||
|
echo "branch_name=$branch_name" >> $GITEA_OUTPUT
|
||||||
|
echo "image_tag=$image_tag" >> $GITEA_OUTPUT
|
||||||
|
echo "comparison_hash=$comparison_hash" >> $GITEA_OUTPUT
|
||||||
echo "build_image=$build_image" >> $GITEA_OUTPUT
|
echo "build_image=$build_image" >> $GITEA_OUTPUT
|
||||||
cat $GITEA_OUTPUT
|
cat $GITEA_OUTPUT
|
||||||
- name: Set up Docker buildx
|
- name: Set up Docker buildx
|
||||||
@@ -131,3 +140,4 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
meson setup -Ddocs=enabled docs
|
meson setup -Ddocs=enabled docs
|
||||||
meson compile -C docs
|
meson compile -C docs
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user