infra: actions: cache the docker build
Some checks failed
Gentoo Utils / build-oci-image (push) Has been cancelled
Gentoo Utils / build (push) Has been cancelled
Gentoo Utils / test (push) Has been cancelled
Gentoo Utils / check-format (push) Has been cancelled
Gentoo Utils / docs (push) Has been cancelled

This commit is contained in:
2025-12-12 19:56:04 -06:00
parent 54971bf924
commit 2bbdfbecab

View File

@@ -3,21 +3,6 @@ name: Gentoo Utils
on: [push] on: [push]
jobs: jobs:
cache:
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:
fetch-depth: 0
build-oci-image: build-oci-image:
runs-on: ubuntu-latest runs-on: ubuntu-latest
continue-on-error: true continue-on-error: true
@@ -39,22 +24,17 @@ 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: |
git --no-pager log --oneline -n 10
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 }}" default_branch_name="${{ gitea.event.repository.default_branch }}"
image_tag=latest image_tag=latest
comparison_hash="${{ gitea.event.before }}" comparison_hash="${{ gitea.event.before }}"
git --no-pager reflog
if [[ "$branch_name" != "${{ gitea.event.repository.default_branch }}" ]]; then if [[ "$branch_name" != "${{ gitea.event.repository.default_branch }}" ]]; then
image_tag=$branch_name image_tag=$branch_name
fi fi
# 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')"
# rebase breaks gitea.event.before, so check to make sure the hash provided exists # 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 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) comparison_hash=$(git merge-base origin/$default_branch_name $branch_name)
@@ -95,6 +75,8 @@ jobs:
push: true push: true
tags: ${{ vars.REGISTRY_URL }}/${{ gitea.repository }}:${{ steps.image-changes.outputs.image_tag }} tags: ${{ vars.REGISTRY_URL }}/${{ gitea.repository }}:${{ steps.image-changes.outputs.image_tag }}
context: "{{defaultContext}}:.docker" context: "{{defaultContext}}:.docker"
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: outputs:
image_tag: ${{ steps.image-changes.outputs.image_tag }} image_tag: ${{ steps.image-changes.outputs.image_tag }}