From 3f9d3e0d8af340de6d79783e3877e577cb905b59 Mon Sep 17 00:00:00 2001 From: James Cox Date: Wed, 25 Mar 2026 19:45:48 -0500 Subject: [PATCH] fix(ci): reduce workflow cache churn - GitHub Actions caching: - replace implicit setup-java cache writes with explicit Gradle cache restore/save steps - only persist the shared Gradle cache from long-lived develop and release workflows - remove the unnecessary QEMU setup from the single-arch smoke build - disable QEMU image caching in multi-arch publish workflows to stop repeated binfmt cache entries - CodeQL workflow: - replace the generated advanced template with a pinned repo-owned CodeQL workflow - add per-ref concurrency to cancel superseded CodeQL runs before they create more caches - restrict dependency caching to Java, using restore-only on pull requests and full caching on long-lived runs - disable trap caching and turn off PR overlay database caching to avoid repetitive low-value CodeQL caches - Validation: - validated the edited workflow YAML with yq - did not execute the workflows locally --- .github/workflows/ci-validate.yml | 4 +- .github/workflows/codeql.yml | 117 ++++++++------------------ .github/workflows/publish-nightly.yml | 3 + .github/workflows/publish-release.yml | 2 + .github/workflows/release-main.yml | 1 + .github/workflows/test-suite.yml | 26 +++++- 6 files changed, 67 insertions(+), 86 deletions(-) diff --git a/.github/workflows/ci-validate.yml b/.github/workflows/ci-validate.yml index 43ff5c5d4..6773d1b0d 100644 --- a/.github/workflows/ci-validate.yml +++ b/.github/workflows/ci-validate.yml @@ -46,6 +46,7 @@ jobs: with: checkout_ref: ${{ github.sha }} publish_test_results: false + save_gradle_cache: ${{ github.event_name == 'push' && github.ref == 'refs/heads/develop' }} packaging-smoke-test: name: Packaging Smoke Test @@ -60,9 +61,6 @@ jobs: - name: Checkout Repository uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - - name: Set Up QEMU for Multi-Arch Builds - uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3 - - name: Set Up Docker Buildx uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0 diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index e25dd2c3f..ff6314c6c 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -1,103 +1,56 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "CodeQL Advanced" +name: CodeQL on: push: - branches: [ "develop" ] + branches: + - develop pull_request: - branches: [ "develop" ] + branches: + - develop schedule: - cron: '17 13 * * 0' +concurrency: + group: codeql-${{ github.ref }} + cancel-in-progress: true + jobs: analyze: name: Analyze (${{ matrix.language }}) - # Runner size impacts CodeQL analysis time. To learn more, please see: - # - https://gh.io/recommended-hardware-resources-for-running-codeql - # - https://gh.io/supported-runners-and-hardware-resources - # - https://gh.io/using-larger-runners (GitHub.com only) - # Consider using larger runners or machines with greater resources for possible analysis time improvements. - runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} + runs-on: ubuntu-latest + permissions: - # required for all workflows - security-events: write - - # required to fetch internal or private CodeQL packs - packages: read - - # only required for workflows in private repositories actions: read contents: read + packages: read + security-events: write strategy: fail-fast: false matrix: include: - - language: actions - build-mode: none - - language: java-kotlin - build-mode: none # This mode only analyzes Java. Set this to 'autobuild' or 'manual' to analyze Kotlin too. - - language: javascript-typescript - build-mode: none - # CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'rust', 'swift' - # Use `c-cpp` to analyze code written in C, C++ or both - # Use 'java-kotlin' to analyze code written in Java, Kotlin or both - # Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both - # To learn more about changing the languages that are analyzed or customizing the build mode for your analysis, - # see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning. - # If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how - # your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages + - language: actions + build-mode: none + - language: java-kotlin + build-mode: none + - language: javascript-typescript + build-mode: none + steps: - - name: Checkout repository - uses: actions/checkout@v4 + - name: Checkout Repository + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - # Add any setup steps before running the `github/codeql-action/init` action. - # This includes steps like installing compilers or runtimes (`actions/setup-node` - # or others). This is typically only required for manual builds. - # - name: Setup runtime (example) - # uses: actions/setup-example@v1 + - name: Initialize CodeQL + uses: github/codeql-action/init@38697555549f1db7851b81482ff19f1fa5c4fedc # v4 + env: + CODEQL_OVERLAY_DATABASE_MODE: ${{ github.event_name == 'pull_request' && 'none' || '' }} + with: + languages: ${{ matrix.language }} + build-mode: ${{ matrix.build-mode }} + dependency-caching: ${{ matrix.language == 'java-kotlin' && (github.event_name == 'pull_request' && 'restore' || 'full') || 'none' }} + trap-caching: false - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v4 - with: - languages: ${{ matrix.language }} - build-mode: ${{ matrix.build-mode }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - - # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs - # queries: security-extended,security-and-quality - - # If the analyze step fails for one of the languages you are analyzing with - # "We were unable to automatically build your code", modify the matrix above - # to set the build mode to "manual" for that language. Then modify this step - # to build your code. - # â„šī¸ Command-line programs to run using the OS shell. - # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun - - name: Run manual build steps - if: matrix.build-mode == 'manual' - shell: bash - run: | - echo 'If you are using a "manual" build mode for one or more of the' \ - 'languages you are analyzing, replace this with the commands to build' \ - 'your code, for example:' - echo ' make bootstrap' - echo ' make release' - exit 1 - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v4 - with: - category: "/language:${{matrix.language}}" + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@38697555549f1db7851b81482ff19f1fa5c4fedc # v4 + with: + category: /language:${{ matrix.language }} diff --git a/.github/workflows/publish-nightly.yml b/.github/workflows/publish-nightly.yml index d35bce84e..6901a9e22 100644 --- a/.github/workflows/publish-nightly.yml +++ b/.github/workflows/publish-nightly.yml @@ -34,6 +34,7 @@ jobs: checks: write with: checkout_ref: ${{ needs.resolve_ref.outputs.commit_sha }} + save_gradle_cache: true build-and-push: name: Build and Push Nightly Image @@ -62,6 +63,8 @@ jobs: - name: Set Up QEMU for Multi-Arch Builds uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3 + with: + cache-image: false - name: Set Up Docker Buildx uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0 diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index ed8ad105c..6ba680596 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -48,6 +48,8 @@ jobs: - name: Set Up QEMU for Multi-Arch Builds uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3 + with: + cache-image: false - name: Set Up Docker Buildx uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0 diff --git a/.github/workflows/release-main.yml b/.github/workflows/release-main.yml index dcc2b4d3d..efd2a6812 100644 --- a/.github/workflows/release-main.yml +++ b/.github/workflows/release-main.yml @@ -29,6 +29,7 @@ jobs: checks: write with: checkout_ref: ${{ github.sha }} + save_gradle_cache: true semantic-release: name: Compute Release, Update Changelog, and Draft GitHub Release diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml index a9386f95b..5c4ba1830 100644 --- a/.github/workflows/test-suite.yml +++ b/.github/workflows/test-suite.yml @@ -12,6 +12,11 @@ on: required: false type: boolean default: true + save_gradle_cache: + description: 'Whether this run should persist the shared Gradle cache' + required: false + type: boolean + default: false jobs: backend-tests: @@ -39,7 +44,17 @@ jobs: with: java-version: '25' distribution: 'temurin' - cache: gradle + + - name: Restore Gradle Cache + id: restore_gradle_cache + uses: actions/cache/restore@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: gradle-${{ runner.os }}-${{ hashFiles('booklore-api/**/*.gradle*', 'booklore-api/settings.gradle*', 'booklore-api/gradle.properties', 'booklore-api/gradle/wrapper/gradle-wrapper.properties') }} + restore-keys: | + gradle-${{ runner.os }}- - name: Execute Backend Tests id: backend_tests @@ -65,6 +80,15 @@ jobs: booklore-api/build/test-results/ retention-days: 30 + - name: Save Gradle Cache + if: ${{ always() && inputs.save_gradle_cache }} + uses: actions/cache/save@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ steps.restore_gradle_cache.outputs.cache-primary-key }} + - name: Validate Backend Test Results if: steps.backend_tests.outcome == 'failure' run: |