ci: redo docker build logic
Some checks failed
Gentoo Utils / docs (push) Failing after 0s
Gentoo Utils / grep (push) Failing after 0s
Gentoo Utils / build-oci-image (push) Successful in 8s
Gentoo Utils / build (push) Failing after 0s
Gentoo Utils / test (push) Has been skipped
Gentoo Utils / fuzz (push) Has been skipped
Gentoo Utils / check-format (push) Failing after 0s

This commit is contained in:
2025-12-27 12:09:08 -06:00
parent 6e1975107a
commit 279741c469

View File

@@ -20,50 +20,47 @@ jobs:
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Check for changes before building - name: Restore git cache
uses: actions/cache@v4
with:
path: .git
key: gitea-repo-${{ gitea.repository }}-${{ gitea.ref }}
- name: Detect Changes
uses: dorny/paths-filter@v3
id: image-changes id: image-changes
# build image only if 1. changes are detected or 2. an image for the working branch doesnt exist with:
filters: |
docker:
- ".docker/**"
- name: Metadata
run: | run: |
set -x
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 }}" default_branch_name="${{ gitea.event.repository.default_branch }}"
image_tag=latest image_tag=latest
comparison_hash="${{ gitea.event.before }}" this_image_tag="$(echo "$branch_name" | sed -E 's/[^a-zA-Z0-9]/-/g')"
echo "steps... ${{ steps.image-changes.outputs.docker }}"
if [[ "$branch_name" != "$default_branch_name" ]]; then if [[ ${{ steps.image-changes.outputs.docker }} == "true" ]] || docker manifest inspect ${{ vars.REGISTRY_URL }}/${{ gitea.repository }}:${this_image_tag} >/dev/null 2>&1; then
image_tag=$branch_name image_tag=$this_image_tag
fi
# slugify
image_tag="$(echo "$image_tag" | sed -E 's/[^a-zA-Z0-9]/-/g')"
# 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
else
if ! docker manifest inspect ${{ vars.REGISTRY_URL }}/${{ gitea.repository }}:${image_tag} >/dev/null 2>&1; then
build_image=true
else
build_image=false
fi
fi fi
set +x
echo "default_branch_name=$default_branch_name" >> $GITEA_OUTPUT echo "default_branch_name=$default_branch_name" >> $GITEA_OUTPUT
echo "branch_name=$branch_name" >> $GITEA_OUTPUT echo "branch_name=$branch_name" >> $GITEA_OUTPUT
echo "image_tag=$image_tag" >> $GITEA_OUTPUT echo "image_tag=$image_tag" >> $GITEA_OUTPUT
echo "comparison_hash=$comparison_hash" >> $GITEA_OUTPUT echo "build_image=${{ steps.image-changes.outputs.docker }}" >> $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
if: steps.image-changes.outputs.build_image == 'true' if: steps.metadata.outputs.build_image == 'true'
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
with: with:
driver-opts: network=runners-net driver-opts: network=runners-net
- name: Log in to Github Container Registry - name: Log in to Github Container Registry
if: steps.image-changes.outputs.build_image == 'true' if: steps.metadata.outputs.build_image == 'true'
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
registry: ${{ vars.REGISTRY_URL }} registry: ${{ vars.REGISTRY_URL }}
@@ -71,22 +68,22 @@ jobs:
password: ${{ secrets.CI_BOT_TOKEN }} password: ${{ secrets.CI_BOT_TOKEN }}
- name: Build and push - name: Build and push
if: steps.image-changes.outputs.build_image == 'true' if: steps.metadata.outputs.build_image == 'true'
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6
with: with:
push: true push: true
tags: ${{ vars.REGISTRY_URL }}/${{ gitea.repository }}:${{ steps.image-changes.outputs.image_tag }} tags: ${{ vars.REGISTRY_URL }}/${{ gitea.repository }}:${{ steps.metadata.outputs.image_tag }}
context: "{{defaultContext}}:.docker" context: "{{defaultContext}}:.docker"
cache-from: type=gha cache-from: type=gha
cache-to: type=gha,mode=max cache-to: type=gha,mode=max
outputs: outputs:
image_tag: ${{ steps.image-changes.outputs.image_tag }} image_tag: ${{ steps.metadata.outputs.image_tag }}
build: build:
runs-on: gentoo runs-on: gentoo
env: env:
CC: 'clang' CC: "clang"
CXX: 'clang++' CXX: "clang++"
needs: build-oci-image needs: build-oci-image
container: container:
image: ${{ vars.REGISTRY_URL }}/${{ gitea.repository }}:${{ needs.build-oci-image.outputs.image_tag }} image: ${{ vars.REGISTRY_URL }}/${{ gitea.repository }}:${{ needs.build-oci-image.outputs.image_tag }}
@@ -110,8 +107,8 @@ jobs:
test: test:
runs-on: gentoo runs-on: gentoo
env: env:
CC: 'clang' CC: "clang"
CXX: 'clang++' CXX: "clang++"
needs: [build-oci-image, build] needs: [build-oci-image, build]
container: container:
image: ${{ vars.REGISTRY_URL }}/${{ gitea.repository }}:${{ needs.build-oci-image.outputs.image_tag }} image: ${{ vars.REGISTRY_URL }}/${{ gitea.repository }}:${{ needs.build-oci-image.outputs.image_tag }}
@@ -133,8 +130,8 @@ jobs:
fuzz: fuzz:
runs-on: gentoo runs-on: gentoo
env: env:
CC: 'clang' CC: "clang"
CXX: 'clang++' CXX: "clang++"
FUZZER_TIMEOUT_S: 300 FUZZER_TIMEOUT_S: 300
needs: [build-oci-image, build] needs: [build-oci-image, build]
container: container: