diff --git a/.github/scripts/configure-sccache.js b/.github/scripts/configure-sccache.js index e5c21ccd30..bd450d0118 100644 --- a/.github/scripts/configure-sccache.js +++ b/.github/scripts/configure-sccache.js @@ -6,7 +6,7 @@ // Note: ACTIONS_CACHE_SERVICE_V2 and SCCACHE_GHA_ENABLED are set at workflow level module.exports = async ({ github, context, core, exec }) => { // Find sccache path (try which command) - let sccachePath = "sccache"; + let sccachePath = "/usr/bin/sccache"; try { const result = await exec.getExecOutput("which", ["sccache"], { ignoreReturnCode: true, @@ -19,6 +19,7 @@ module.exports = async ({ github, context, core, exec }) => { } catch (e) { core.debug(`Could not find sccache path: ${e.message}`); } + // Check sccache version try { const versionResult = await exec.getExecOutput(sccachePath, ["--version"], { @@ -29,6 +30,14 @@ module.exports = async ({ github, context, core, exec }) => { } catch (e) { core.warning(`Could not get sccache version: ${e.message}`); } + + // Enable caching + core.exportVariable("RUSTC_WRAPPER", sccachePath); + core.exportVariable("SCCACHE_GHA_ENABLED", "true"); + + // Disable Cargo incremental builds to not interfere with caching + core.exportVariable("CARGO_INCREMENTAL", "false"); + // Debug: Show what environment variables are available core.info("=== Environment Variables Diagnostic ==="); core.info(`SCCACHE_GHA_ENABLED: ${process.env.SCCACHE_GHA_ENABLED}`); @@ -44,8 +53,10 @@ module.exports = async ({ github, context, core, exec }) => { core.info(`RUSTC_WRAPPER: ${process.env.RUSTC_WRAPPER}`); core.info(`SCCACHE_LOG: ${process.env.SCCACHE_LOG}`); core.info("========================================"); + // Export SCCACHE_PATH so it's available to subsequent steps core.exportVariable("SCCACHE_PATH", sccachePath); + // Expose the GHA cache related variables to make it easier for users to // integrate with GHA support (from upstream mozilla/sccache-action) if (process.env.ACTIONS_RESULTS_URL) { @@ -56,6 +67,7 @@ module.exports = async ({ github, context, core, exec }) => { "ACTIONS_RESULTS_URL is not set - GitHub Actions cache WILL NOT work", ); } + if (process.env.ACTIONS_RUNTIME_TOKEN) { core.exportVariable( "ACTIONS_RUNTIME_TOKEN", @@ -67,6 +79,7 @@ module.exports = async ({ github, context, core, exec }) => { "ACTIONS_RUNTIME_TOKEN is not set - GitHub Actions cache WILL NOT work", ); } + // Set cache version and restore keys for this specific build matrix if (process.env.SCCACHE_GHA_VERSION) { core.exportVariable("SCCACHE_GHA_VERSION", process.env.SCCACHE_GHA_VERSION); @@ -77,6 +90,7 @@ module.exports = async ({ github, context, core, exec }) => { process.env.SCCACHE_GHA_CACHE_FROM, ); } + // Check if cache busting is enabled const inputs = (github && @@ -90,16 +104,20 @@ module.exports = async ({ github, context, core, exec }) => { process.env.INPUT_BUST_CACHE ?? process.env.BUST_CACHE; let bustCache = false; + if (typeof rawBustCache === "string") { const v = rawBustCache.toLowerCase().trim(); bustCache = v === "true" || v === "1" || v === "yes"; } else { bustCache = !!rawBustCache; } + if (bustCache) { + core.exportVariable("SCCACHE_BUST_CACHE", "true"); core.exportVariable("SCCACHE_RECACHE", "1"); core.info("SCCACHE_RECACHE enabled because bust_cache is true"); } + // Stop any running sccache daemon so it picks up the new environment variables core.info("Stopping any running sccache daemon to pick up configuration..."); try { @@ -112,6 +130,7 @@ module.exports = async ({ github, context, core, exec }) => { `Could not stop sccache daemon (it may not be running): ${e.message}`, ); } + // Verify sccache can see the GHA environment variables by starting server with explicit env core.info("Starting sccache server with GHA environment variables..."); const sccacheEnv = { @@ -119,6 +138,7 @@ module.exports = async ({ github, context, core, exec }) => { SCCACHE_GHA_ENABLED: process.env.SCCACHE_GHA_ENABLED || "on", ACTIONS_CACHE_SERVICE_V2: process.env.ACTIONS_CACHE_SERVICE_V2 || "on", }; + try { await exec.exec(sccachePath, ["--start-server"], { ignoreReturnCode: true, @@ -128,6 +148,7 @@ module.exports = async ({ github, context, core, exec }) => { } catch (e) { core.warning(`Could not start sccache server: ${e.message}`); } + // Show the current sccache configuration core.info("Verifying sccache configuration:"); try { @@ -139,6 +160,7 @@ module.exports = async ({ github, context, core, exec }) => { env: sccacheEnv, }, ); + // Check if it's using GitHub Actions cache if (statsResult.stdout.includes("GitHub Actions")) { core.info("✓ sccache is configured to use GitHub Actions cache"); diff --git a/.github/workflows/json-build.yml b/.github/workflows/json-build.yml index 01f2984506..d09af76ac6 100644 --- a/.github/workflows/json-build.yml +++ b/.github/workflows/json-build.yml @@ -55,6 +55,18 @@ jobs: - name: Set up git repository run: git config --global --add safe.directory "$GITHUB_WORKSPACE" + - name: Configure sccache + id: sccache + if: ${{ !contains(matrix.pkg.labels.sccache, '0') }} + uses: actions/github-script@v8 + env: + SCCACHE_GHA_VERSION: ${{ matrix.version }}-${{ matrix.pkg.arch }}-${{ matrix.pkg.pkg }} + SCCACHE_GHA_CACHE_FROM: ${{ matrix.version }}-${{ matrix.pkg.arch }}-${{ matrix.pkg.pkg }} + with: + script: | + const script = require('./.github/scripts/configure-sccache.js') + await script({github, context, core, exec}) + - name: CI Setup Script if: ${{ !contains(matrix.pkg.labels, 'mock') }} run: | @@ -69,20 +81,17 @@ jobs: dir=$(dirname ${{ matrix.pkg.pkg }}) dnf5 builddep -y ${dir}/*.spec - - name: Configure sccache - if: matrix.pkg.labels['sccache'] != '0' - run: | - set -euo pipefail - echo "RUSTC_WRAPPER=/usr/bin/sccache" >> $GITHUB_ENV - echo "CARGO_INCREMENTAL=false" >> $GITHUB_ENV - echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV - if [ "${{ inputs.bust_cache }}" = "true" ]; then - echo "SCCACHE_BUST_CACHE=true" >> $GITHUB_ENV - fi - - name: Build with Andaman run: anda build -D "vendor Terra" -D "__python %{__python3}" ${{ matrix.pkg.pkg }} -c terra-${{ matrix.version }}-${{ matrix.pkg.arch }} ${{ !matrix.pkg.labels.mock == '1' && '-rrpmbuild' || '' }} + - name: Report Cache Summary + if: steps.sccache.outcome == 'success' + uses: actions/github-script@v8 + with: + script: | + const script = require('./.github/scripts/sccache-stats.js') + await script({github, context, core, exec}) + - name: Generating artifact name id: art run: |