From 91389abcb9b4b6ec55d684fd8952e5c8d3610316 Mon Sep 17 00:00:00 2001 From: penguin Date: Mon, 8 Dec 2025 17:18:13 -0600 Subject: [PATCH 1/8] ci: simplify pipeline logic --- .gitea/workflows/gentoo-utils.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.gitea/workflows/gentoo-utils.yml b/.gitea/workflows/gentoo-utils.yml index 8f3456b..7a91fe8 100644 --- a/.gitea/workflows/gentoo-utils.yml +++ b/.gitea/workflows/gentoo-utils.yml @@ -1,11 +1,6 @@ name: Gentoo Utils -on: - push: - branches: - '*' - pull_request: - branches: [master] +on: [push] jobs: build-oci-image: From 59c060df54eb599b6b6bc8755af13fb1c44337c2 Mon Sep 17 00:00:00 2001 From: penguin Date: Mon, 8 Dec 2025 19:41:46 -0600 Subject: [PATCH 2/8] ci: build-oci-image: create entrypoint script and put env sources in it --- .docker/Dockerfile | 4 +++- .docker/entrypoint.sh | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100755 .docker/entrypoint.sh diff --git a/.docker/Dockerfile b/.docker/Dockerfile index 89109cb..a80d0ce 100644 --- a/.docker/Dockerfile +++ b/.docker/Dockerfile @@ -31,4 +31,6 @@ USER gentooligan WORKDIR /workspace -ENTRYPOINT /bin/bash +ENTRYPOINT ["/entrypoint.sh"] + +CMD ["/bin/bash"] diff --git a/.docker/entrypoint.sh b/.docker/entrypoint.sh new file mode 100755 index 0000000..8fe0779 --- /dev/null +++ b/.docker/entrypoint.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env sh + + +source /etc/profile +source /lib/gentoo/functions.sh +exec "$@" From 8a483e6d6c757051f34026ed1e5cd2351346422e Mon Sep 17 00:00:00 2001 From: penguin Date: Fri, 12 Dec 2025 22:55:30 -0600 Subject: [PATCH 3/8] ci: set default shell to login shell This way /etc/profile is sourced in our gentoo jobs --- .gitea/workflows/gentoo-utils.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitea/workflows/gentoo-utils.yml b/.gitea/workflows/gentoo-utils.yml index 7a91fe8..9e9cf6f 100644 --- a/.gitea/workflows/gentoo-utils.yml +++ b/.gitea/workflows/gentoo-utils.yml @@ -2,6 +2,10 @@ name: Gentoo Utils on: [push] +defaults: + run: + shell: bash -l {0} + jobs: build-oci-image: runs-on: ubuntu-latest From a29052867953fe7cd47a3f55608d6ac3817bcfc7 Mon Sep 17 00:00:00 2001 From: penguin Date: Fri, 12 Dec 2025 22:56:25 -0600 Subject: [PATCH 4/8] 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 --- .gitea/workflows/gentoo-utils.yml | 58 +++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 10 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 - else - echo changes_detected=false >> $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 + 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 From 0d1f38f7955be0b903c91668222612294f0b3d61 Mon Sep 17 00:00:00 2001 From: penguin Date: Fri, 12 Dec 2025 23:02:07 -0600 Subject: [PATCH 5/8] ci: update build job to only build --- .gitea/workflows/gentoo-utils.yml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/gentoo-utils.yml b/.gitea/workflows/gentoo-utils.yml index 8117039..94445ff 100644 --- a/.gitea/workflows/gentoo-utils.yml +++ b/.gitea/workflows/gentoo-utils.yml @@ -86,12 +86,21 @@ jobs: build: runs-on: brutalisk - container: - image: git.epenguin.net/gentoo-utils/gentoo-utils-gitea:latest + env: + CC: 'clang' + CXX: 'clang++' needs: build-oci-image + container: + image: ${{ vars.REGISTRY_URL }}/${{ gitea.repository }}:${{ needs.build-oci-image.outputs.image_tag }} steps: - name: Checkout repo uses: actions/checkout@v5 - name: build and check - run: ./check.sh + run: | + echo $USER + echo "CC=$CC" + echo "CXX=$CXX" + source /etc/profile + meson setup -Dfuzz=enabled -Dtests=enabled -Dbuildtype=debugoptimized -Ddocs=enabled build + meson compile -C build From e83ca9aab29526d33c79dd6d7b07dfd83c22cace Mon Sep 17 00:00:00 2001 From: penguin Date: Fri, 12 Dec 2025 23:02:28 -0600 Subject: [PATCH 6/8] ci: add test job Right now this just rebuilds everything the build job built. In a future PR I will either cache the build dir from the build job or I will upload the build dir as an artifact. --- .gitea/workflows/gentoo-utils.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.gitea/workflows/gentoo-utils.yml b/.gitea/workflows/gentoo-utils.yml index 94445ff..6c539a8 100644 --- a/.gitea/workflows/gentoo-utils.yml +++ b/.gitea/workflows/gentoo-utils.yml @@ -104,3 +104,24 @@ jobs: source /etc/profile meson setup -Dfuzz=enabled -Dtests=enabled -Dbuildtype=debugoptimized -Ddocs=enabled build meson compile -C build + + # FIXME: Currently this rebuilds everything. Instead we should bring over the build dir from the build job. This will come in handy + # when we have multiple build targets and configs. What we have currently is fine until we get lots of builds going + test: + runs-on: brutalisk + env: + CC: 'clang' + CXX: 'clang++' + needs: [build-oci-image, build] + container: + image: ${{ vars.REGISTRY_URL }}/${{ gitea.repository }}:${{ needs.build-oci-image.outputs.image_tag }} + steps: + - name: Checkout repo + uses: actions/checkout@v5 + + - name: test + run: | + meson setup -Dfuzz=enabled -Dtests=enabled -Dbuildtype=debugoptimized -Ddocs=enabled build + meson compile -C build + ninja test -C build + From f16545e65b2c106cfaf6f23ce3b1b2856c792cdd Mon Sep 17 00:00:00 2001 From: penguin Date: Fri, 12 Dec 2025 23:03:31 -0600 Subject: [PATCH 7/8] ci: add check-format job --- .gitea/workflows/gentoo-utils.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.gitea/workflows/gentoo-utils.yml b/.gitea/workflows/gentoo-utils.yml index 6c539a8..9f9f612 100644 --- a/.gitea/workflows/gentoo-utils.yml +++ b/.gitea/workflows/gentoo-utils.yml @@ -125,3 +125,17 @@ jobs: meson compile -C build ninja test -C build + check-format: + runs-on: brutalisk + needs: [build-oci-image] + container: + image: ${{ vars.REGISTRY_URL }}/${{ gitea.repository }}:${{ needs.build-oci-image.outputs.image_tag }} + steps: + - name: Checkout repo + uses: actions/checkout@v5 + + - name: Check Formatting + run: | + meson setup -Dfuzz=enabled -Dtests=enabled -Dbuildtype=debugoptimized build + meson format --check-only --recursive + ninja rustfmt -C build From c82152a36583f6a19c2a3f93289ce39b5320d1a8 Mon Sep 17 00:00:00 2001 From: penguin Date: Fri, 12 Dec 2025 23:03:44 -0600 Subject: [PATCH 8/8] ci: add docs job --- .gitea/workflows/gentoo-utils.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.gitea/workflows/gentoo-utils.yml b/.gitea/workflows/gentoo-utils.yml index 9f9f612..683524c 100644 --- a/.gitea/workflows/gentoo-utils.yml +++ b/.gitea/workflows/gentoo-utils.yml @@ -139,3 +139,17 @@ jobs: meson setup -Dfuzz=enabled -Dtests=enabled -Dbuildtype=debugoptimized build meson format --check-only --recursive ninja rustfmt -C build + + docs: + runs-on: brutalisk + needs: [build-oci-image] + container: + image: ${{ vars.REGISTRY_URL }}/${{ gitea.repository }}:${{ needs.build-oci-image.outputs.image_tag }} + steps: + - name: Checkout repo + uses: actions/checkout@v5 + + - name: Build Documentation + run: | + meson setup -Ddocs=enabled docs + ninja rustdoc -C docs