From 7d91f218b15f0c822e4ab3dc65eec0a51cc240f9 Mon Sep 17 00:00:00 2001 From: Tom Foster Date: Mon, 22 Sep 2025 16:04:59 +0100 Subject: [PATCH] ci: Migrate to detect-versions with namespaced cache keys Replace local detect-runner-os action with external detect-versions@v1 to reduce custom action maintenance. Add architecture detection for future cross-platform support and namespace all cache keys with "continuwuity-" prefix to prevent collisions with other projects on shared runners. Updates cache mount IDs in Dockerfiles to match the new namespacing convention, ensuring consistent cache isolation across CI and Docker builds. --- .forgejo/actions/detect-runner-os/action.yml | 58 ------------------- .../actions/prepare-docker-build/action.yml | 8 +-- .forgejo/actions/rust-toolchain/action.yml | 2 +- .../actions/setup-llvm-with-apt/action.yml | 4 +- .forgejo/actions/setup-rust/action.yml | 12 ++-- .forgejo/actions/timelord/action.yml | 6 +- .forgejo/workflows/documentation.yml | 6 +- .forgejo/workflows/renovate.yml | 18 +++--- docker/Dockerfile | 2 +- docker/musl.Dockerfile | 2 +- 10 files changed, 30 insertions(+), 88 deletions(-) delete mode 100644 .forgejo/actions/detect-runner-os/action.yml diff --git a/.forgejo/actions/detect-runner-os/action.yml b/.forgejo/actions/detect-runner-os/action.yml deleted file mode 100644 index be8f9b0a..00000000 --- a/.forgejo/actions/detect-runner-os/action.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: detect-runner-os -description: | - Detect the actual OS name and version of the runner. - Provides separate outputs for name, version, and a combined slug. - -outputs: - name: - description: 'OS name (e.g. Ubuntu, Debian)' - value: ${{ steps.detect.outputs.name }} - version: - description: 'OS version (e.g. 22.04, 11)' - value: ${{ steps.detect.outputs.version }} - slug: - description: 'Combined OS slug (e.g. Ubuntu-22.04)' - value: ${{ steps.detect.outputs.slug }} - node_major: - description: 'Major version of Node.js if available (e.g. 22)' - value: ${{ steps.detect.outputs.node_major }} - node_version: - description: 'Full Node.js version if available (e.g. 22.19.0)' - value: ${{ steps.detect.outputs.node_version }} - -runs: - using: composite - steps: - - name: Detect runner OS - id: detect - shell: bash - run: | - # Detect OS version (try lsb_release first, fall back to /etc/os-release) - OS_VERSION=$(lsb_release -rs 2>/dev/null || grep VERSION_ID /etc/os-release | cut -d'"' -f2) - - # Detect OS name and capitalise (try lsb_release first, fall back to /etc/os-release) - OS_NAME=$(lsb_release -is 2>/dev/null || grep "^ID=" /etc/os-release | cut -d'=' -f2 | tr -d '"' | sed 's/\b\(.\)/\u\1/g') - - # Create combined slug - OS_SLUG="${OS_NAME}-${OS_VERSION}" - - # Detect Node.js version if available - if command -v node >/dev/null 2>&1; then - NODE_VERSION=$(node --version | sed 's/v//') - NODE_MAJOR=$(echo $NODE_VERSION | cut -d. -f1) - echo "node_version=${NODE_VERSION}" >> $GITHUB_OUTPUT - echo "node_major=${NODE_MAJOR}" >> $GITHUB_OUTPUT - echo "🔍 Detected Node.js: v${NODE_VERSION}" - else - echo "node_version=" >> $GITHUB_OUTPUT - echo "node_major=" >> $GITHUB_OUTPUT - echo "🔍 Node.js not found" - fi - - # Set OS outputs - echo "name=${OS_NAME}" >> $GITHUB_OUTPUT - echo "version=${OS_VERSION}" >> $GITHUB_OUTPUT - echo "slug=${OS_SLUG}" >> $GITHUB_OUTPUT - - # Log detection results - echo "🔍 Detected Runner OS: ${OS_NAME} ${OS_VERSION}" diff --git a/.forgejo/actions/prepare-docker-build/action.yml b/.forgejo/actions/prepare-docker-build/action.yml index 6a397b8a..decf1286 100644 --- a/.forgejo/actions/prepare-docker-build/action.yml +++ b/.forgejo/actions/prepare-docker-build/action.yml @@ -121,7 +121,7 @@ runs: .cargo/git/checkouts .cargo/registry .cargo/registry/src - key: rust-registry-image-${{hashFiles('**/Cargo.lock') }} + key: continuwuity-rust-registry-image-${{hashFiles('**/Cargo.lock') }} - name: Cache cargo target if: ${{ env.BUILDKIT_ENDPOINT == '' }} @@ -130,7 +130,7 @@ runs: with: path: | cargo-target${{ env.CPU_SUFFIX }}-${{ inputs.slug }}-${{ inputs.profile }} - key: cargo-target${{ env.CPU_SUFFIX }}-${{ inputs.slug }}-${{ inputs.profile }}-${{hashFiles('**/Cargo.lock') }}-${{steps.rust-toolchain.outputs.rustc_version}} + key: continuwuity-cargo-target${{ env.CPU_SUFFIX }}-${{ inputs.slug }}-${{ inputs.profile }}-${{hashFiles('**/Cargo.lock') }}-${{steps.rust-toolchain.outputs.rustc_version}} - name: Cache apt cache if: ${{ env.BUILDKIT_ENDPOINT == '' }} @@ -139,7 +139,7 @@ runs: with: path: | var-cache-apt-${{ inputs.slug }} - key: var-cache-apt-${{ inputs.slug }} + key: continuwuity-var-cache-apt-${{ inputs.slug }} - name: Cache apt lib if: ${{ env.BUILDKIT_ENDPOINT == '' }} @@ -148,7 +148,7 @@ runs: with: path: | var-lib-apt-${{ inputs.slug }} - key: var-lib-apt-${{ inputs.slug }} + key: continuwuity-var-lib-apt-${{ inputs.slug }} - name: inject cache into docker if: ${{ env.BUILDKIT_ENDPOINT == '' }} diff --git a/.forgejo/actions/rust-toolchain/action.yml b/.forgejo/actions/rust-toolchain/action.yml index ae5cfcee..12f2f581 100644 --- a/.forgejo/actions/rust-toolchain/action.yml +++ b/.forgejo/actions/rust-toolchain/action.yml @@ -40,7 +40,7 @@ runs: !~/.rustup/tmp !~/.rustup/downloads # Requires repo to be cloned if toolchain is not specified - key: ${{ runner.os }}-rustup-${{ inputs.toolchain || hashFiles('**/rust-toolchain.toml') }} + key: continuwuity-${{ runner.os }}-rustup-${{ inputs.toolchain || hashFiles('**/rust-toolchain.toml') }} - name: Install Rust toolchain if: steps.rustup-version.outputs.version == '' shell: bash diff --git a/.forgejo/actions/setup-llvm-with-apt/action.yml b/.forgejo/actions/setup-llvm-with-apt/action.yml index b3c4bc45..ff82cada 100644 --- a/.forgejo/actions/setup-llvm-with-apt/action.yml +++ b/.forgejo/actions/setup-llvm-with-apt/action.yml @@ -29,7 +29,7 @@ runs: steps: - name: Detect runner OS id: runner-os - uses: ./.forgejo/actions/detect-runner-os + uses: https://git.tomfos.tr/actions/detect-versions@v1 - name: Configure cross-compilation architecture if: inputs.dpkg-arch != '' @@ -69,7 +69,7 @@ runs: /usr/lib/x86_64-linux-gnu/libclang*.so* /etc/apt/sources.list.d/archive_uri-* /etc/apt/trusted.gpg.d/apt.llvm.org.asc - key: llvm-${{ steps.runner-os.outputs.slug }}-v${{ inputs.llvm-version }}-v3-${{ hashFiles('**/Cargo.lock', 'rust-toolchain.toml') }} + key: continuwuity-llvm-${{ steps.runner-os.outputs.slug }}-${{ steps.runner-os.outputs.arch }}-v${{ inputs.llvm-version }}-${{ hashFiles('**/Cargo.lock', 'rust-toolchain.toml') }} - name: End LLVM cache group shell: bash diff --git a/.forgejo/actions/setup-rust/action.yml b/.forgejo/actions/setup-rust/action.yml index 43bfef4c..d1a070a5 100644 --- a/.forgejo/actions/setup-rust/action.yml +++ b/.forgejo/actions/setup-rust/action.yml @@ -39,7 +39,7 @@ runs: steps: - name: Detect runner OS id: runner-os - uses: ./.forgejo/actions/detect-runner-os + uses: https://git.tomfos.tr/actions/detect-versions@v1 - name: Configure Cargo environment shell: bash @@ -73,9 +73,9 @@ runs: .cargo/git/db # Registry cache saved per workflow, restored from any workflow's cache # Each workflow maintains its own registry that accumulates its needed crates - key: cargo-registry-${{ steps.runner-os.outputs.slug }}-${{ github.workflow }} + key: continuwuity-cargo-registry-${{ steps.runner-os.outputs.slug }}-${{ steps.runner-os.outputs.arch }}-${{ github.workflow }} restore-keys: | - cargo-registry-${{ steps.runner-os.outputs.slug }}- + continuwuity-cargo-registry-${{ steps.runner-os.outputs.slug }}-${{ steps.runner-os.outputs.arch }}- - name: Cache toolchain binaries id: toolchain-cache @@ -86,7 +86,7 @@ runs: .rustup/toolchains .rustup/update-hashes # Shared toolchain cache across all Rust versions - key: toolchain-${{ steps.runner-os.outputs.slug }} + key: continuwuity-toolchain-${{ steps.runner-os.outputs.slug }}-${{ steps.runner-os.outputs.arch }} - name: Setup sccache @@ -106,9 +106,9 @@ runs: /timelord/ # Build artifacts - cache per code change, restore from deps when code changes key: >- - build-${{ steps.runner-os.outputs.slug }}-${{ inputs.rust-version }}${{ inputs.cache-key-suffix && format('-{0}', inputs.cache-key-suffix) || '' }}-${{ hashFiles('rust-toolchain.toml', '**/Cargo.lock') }}-${{ hashFiles('**/*.rs', '**/Cargo.toml') }} + continuwuity-build-${{ steps.runner-os.outputs.slug }}-${{ steps.runner-os.outputs.arch }}-${{ inputs.rust-version }}${{ inputs.cache-key-suffix && format('-{0}', inputs.cache-key-suffix) || '' }}-${{ hashFiles('rust-toolchain.toml', '**/Cargo.lock') }}-${{ hashFiles('**/*.rs', '**/Cargo.toml') }} restore-keys: | - build-${{ steps.runner-os.outputs.slug }}-${{ inputs.rust-version }}${{ inputs.cache-key-suffix && format('-{0}', inputs.cache-key-suffix) || '' }}-${{ hashFiles('rust-toolchain.toml', '**/Cargo.lock') }}- + continuwuity-build-${{ steps.runner-os.outputs.slug }}-${{ steps.runner-os.outputs.arch }}-${{ inputs.rust-version }}${{ inputs.cache-key-suffix && format('-{0}', inputs.cache-key-suffix) || '' }}-${{ hashFiles('rust-toolchain.toml', '**/Cargo.lock') }}- - name: End cache restore group shell: bash diff --git a/.forgejo/actions/timelord/action.yml b/.forgejo/actions/timelord/action.yml index 43ad6c09..590d025f 100644 --- a/.forgejo/actions/timelord/action.yml +++ b/.forgejo/actions/timelord/action.yml @@ -36,7 +36,7 @@ runs: path: | /usr/share/rust/.cargo/bin ~/.cargo/bin - key: timelord-binaries-v3 + key: continuwuity-timelord-binaries - name: Check if binaries need installation shell: bash @@ -82,7 +82,7 @@ runs: path: | /usr/share/rust/.cargo/bin ~/.cargo/bin - key: timelord-binaries-v3 + key: continuwuity-timelord-binaries - name: Restore timelord cache with fallbacks @@ -92,7 +92,7 @@ runs: path: ${{ env.TIMELORD_CACHE_PATH }} key: ${{ env.TIMELORD_KEY }} restore-keys: | - timelord-v1-${{ github.repository }}- + continuwuity-timelord-${{ github.repository }}- - name: Initialize timestamps on complete cache miss if: steps.timelord-restore.outputs.cache-hit != 'true' diff --git a/.forgejo/workflows/documentation.yml b/.forgejo/workflows/documentation.yml index 56db6226..b3da4c2f 100644 --- a/.forgejo/workflows/documentation.yml +++ b/.forgejo/workflows/documentation.yml @@ -51,7 +51,7 @@ jobs: - name: Detect runner environment id: runner-env - uses: ./.forgejo/actions/detect-runner-os + uses: https://git.tomfos.tr/actions/detect-versions@v1 - name: Setup Node.js if: steps.runner-env.outputs.node_major == '' || steps.runner-env.outputs.node_major < '20' @@ -63,9 +63,9 @@ jobs: uses: actions/cache@v3 with: path: ~/.npm - key: ${{ steps.runner-env.outputs.slug }}-node-${{ hashFiles('**/package-lock.json') }} + key: continuwuity-${{ steps.runner-env.outputs.slug }}-${{ steps.runner-env.outputs.arch }}-node-${{ hashFiles('**/package-lock.json') }} restore-keys: | - ${{ steps.runner-env.outputs.slug }}-node- + continuwuity-${{ steps.runner-env.outputs.slug }}-${{ steps.runner-env.outputs.arch }}-node- - name: Install dependencies run: npm install --save-dev wrangler@latest diff --git a/.forgejo/workflows/renovate.yml b/.forgejo/workflows/renovate.yml index 77fa795e..6aa1ff67 100644 --- a/.forgejo/workflows/renovate.yml +++ b/.forgejo/workflows/renovate.yml @@ -59,27 +59,27 @@ jobs: with: path: | /tmp/renovate/cache/renovate/repository - key: repo-cache-${{ github.run_id }} + key: renovate-repo-cache-${{ github.run_id }} restore-keys: | - repo-cache- + renovate-repo-cache- - name: Restore renovate package cache uses: actions/cache/restore@v4 with: path: | /tmp/renovate/cache/renovate/renovate-cache-sqlite - key: package-cache-${{ github.run_id }} + key: renovate-package-cache-${{ github.run_id }} restore-keys: | - package-cache- + renovate-package-cache- - name: Restore renovate OSV cache uses: actions/cache/restore@v4 with: path: | /tmp/osv - key: osv-cache-${{ github.run_id }} + key: renovate-osv-cache-${{ github.run_id }} restore-keys: | - osv-cache- + renovate-osv-cache- - name: Self-hosted Renovate run: renovate @@ -113,7 +113,7 @@ jobs: with: path: | /tmp/renovate/cache/renovate/repository - key: repo-cache-${{ github.run_id }} + key: renovate-repo-cache-${{ github.run_id }} - name: Save renovate package cache if: always() @@ -121,7 +121,7 @@ jobs: with: path: | /tmp/renovate/cache/renovate/renovate-cache-sqlite - key: package-cache-${{ github.run_id }} + key: renovate-package-cache-${{ github.run_id }} - name: Save renovate OSV cache if: always() @@ -129,4 +129,4 @@ jobs: with: path: | /tmp/osv - key: osv-cache-${{ github.run_id }} + key: renovate-osv-cache-${{ github.run_id }} diff --git a/docker/Dockerfile b/docker/Dockerfile index 5cc5db5c..6d34f560 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -166,7 +166,7 @@ ARG RUST_PROFILE=release # Build the binary RUN --mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/usr/local/cargo/git/db \ - --mount=type=cache,target=/app/target,id=cargo-target-${TARGET_CPU}-${TARGETPLATFORM}-${RUST_PROFILE} \ + --mount=type=cache,target=/app/target,id=continuwuity-cargo-target-${TARGET_CPU}-${TARGETPLATFORM}-${RUST_PROFILE} \ bash <<'EOF' set -o allexport set -o xtrace diff --git a/docker/musl.Dockerfile b/docker/musl.Dockerfile index 778eabd4..6201f3f5 100644 --- a/docker/musl.Dockerfile +++ b/docker/musl.Dockerfile @@ -122,7 +122,7 @@ ARG RUST_PROFILE=release # Build the binary RUN --mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/usr/local/cargo/git/db \ - --mount=type=cache,target=/app/target,id=cargo-target-${TARGET_CPU}-${TARGETPLATFORM}-musl-${RUST_PROFILE} \ + --mount=type=cache,target=/app/target,id=continuwuity-cargo-target-${TARGET_CPU}-${TARGETPLATFORM}-musl-${RUST_PROFILE} \ bash <<'EOF' set -o allexport set -o xtrace