summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpenguin <penguin@epenguin.net>2025-12-12 22:56:25 -0600
committerpenguin <penguin@epenguin.net>2025-12-12 23:05:53 -0600
commita29052867953fe7cd47a3f55608d6ac3817bcfc7 (patch)
tree4ced1c39d0b79a8bbd818d066e943c2400f44707
parent8a483e6d6c757051f34026ed1e5cd2351346422e (diff)
downloadgentoo-utils-a29052867953fe7cd47a3f55608d6ac3817bcfc7.tar.gz
ci: build-oci-image: cache .git dir in build-oci-image
ci: build-oci-image: fix logic for detecting changes to .docker in build-oci-image ci: build-oci-image: use registry url variable, not hardcoded url ci: build-oci-image: change changes_detected var to build image ci: build-oci-image: output an image tag for other jobs to use ci: build-oci-image: cache the docker image build This wont always speed things up, but occasionally it will speed things up by a lot
-rw-r--r--.gitea/workflows/gentoo-utils.yml56
1 files changed, 47 insertions, 9 deletions
diff --git a/.gitea/workflows/gentoo-utils.yml b/.gitea/workflows/gentoo-utils.yml
index 9e9cf6f..8117039 100644
--- a/.gitea/workflows/gentoo-utils.yml
+++ b/.gitea/workflows/gentoo-utils.yml
@@ -11,6 +11,12 @@ jobs:
runs-on: ubuntu-latest
continue-on-error: true
steps:
+ - name: Restore git cache
+ uses: actions/cache@v4
+ with:
+ path: .git
+ key: gitea-repo-${{ gitea.repository }}-${{ gitea.ref }}
+
- name: Checkout repo
uses: actions/checkout@v5
with:
@@ -18,33 +24,65 @@ jobs:
- name: Check for changes before building
id: image-changes
+ # build image only if 1. changes are detected or 2. an image for the working branch doesnt exist
run: |
- echo "branch_name=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITEA_OUTPUT
- if ! git diff ${{ gitea.event.before }} ${{ gitea.sha }} --no-patch --exit-code .docker; then
- echo changes_detected=true >> $GITEA_OUTPUT
+ 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" != "$default_branch_name" ]]; then
+ image_tag=$branch_name
+ 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
- echo changes_detected=false >> $GITEA_OUTPUT
+ 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
+
+ echo "default_branch_name=$default_branch_name" >> $GITEA_OUTPUT
+ 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
cat $GITEA_OUTPUT
- name: Set up Docker buildx
- if: steps.image-changes.outputs.changes_detected == 'true'
+ if: steps.image-changes.outputs.build_image == 'true'
uses: docker/setup-buildx-action@v3
+ with:
+ driver-opts: network=runners-net
- name: Log in to Github Container Registry
- if: steps.image-changes.outputs.changes_detected == 'true'
+ if: steps.image-changes.outputs.build_image == 'true'
uses: docker/login-action@v3
with:
- registry: git.epenguin.net
+ registry: ${{ vars.REGISTRY_URL }}
username: ${{ vars.CI_BOT_USERNAME }}
password: ${{ secrets.CI_BOT_TOKEN }}
- name: Build and push
- if: steps.image-changes.outputs.changes_detected == 'true'
+ if: steps.image-changes.outputs.build_image == 'true'
uses: docker/build-push-action@v6
with:
push: true
- tags: git.epenguin.net/${{ gitea.repository }}:latest
+ tags: ${{ vars.REGISTRY_URL }}/${{ gitea.repository }}:${{ steps.image-changes.outputs.image_tag }}
context: "{{defaultContext}}:.docker"
+ cache-from: type=gha
+ cache-to: type=gha,mode=max
+ outputs:
+ image_tag: ${{ steps.image-changes.outputs.image_tag }}
build:
runs-on: brutalisk