From 49c1e337e88dc00fdd7c9c8a2a129ae8d7e08c68 Mon Sep 17 00:00:00 2001 From: Nicholas Dudfield Date: Mon, 24 Nov 2025 15:21:22 +0700 Subject: [PATCH] refactor: inline cache clearing into restore action Consolidates cache clearing and restore into a single self-contained action, eliminating the need for a separate clear-cache action. Changes: - Inline cache clearing logic directly into xahau-ga-cache-restore - Delete xahau-ga-clear-cache action (no longer needed) - Add additional-clear-keys input for clearing multiple keys - Remove nd-experiment-overlayfs branch from workflow triggers Benefits: - Single action does everything (clear + restore) - Simpler architecture (one action instead of two) - Self-contained and easier to maintain --- .../actions/xahau-ga-cache-restore/action.yml | 98 +++++++++++++++- .../actions/xahau-ga-clear-cache/action.yml | 110 ------------------ .github/workflows/xahau-ga-nix.yml | 2 +- 3 files changed, 95 insertions(+), 115 deletions(-) delete mode 100644 .github/actions/xahau-ga-clear-cache/action.yml diff --git a/.github/actions/xahau-ga-cache-restore/action.yml b/.github/actions/xahau-ga-cache-restore/action.yml index d8b946708..de7b8c2fa 100644 --- a/.github/actions/xahau-ga-cache-restore/action.yml +++ b/.github/actions/xahau-ga-cache-restore/action.yml @@ -24,6 +24,10 @@ inputs: description: 'Check if a cache entry exists for the given input(s) without downloading it' required: false default: 'false' + additional-clear-keys: + description: 'Additional cache keys to clear (newline separated)' + required: false + default: '' outputs: cache-hit: @@ -40,10 +44,96 @@ runs: using: 'composite' steps: - name: Clear cache if requested via commit message - uses: ./.github/actions/xahau-ga-clear-cache - with: - cache-key: ${{ inputs.key }} - cache-type: ${{ inputs.cache-type }} + shell: bash + env: + GH_TOKEN: ${{ github.token }} + run: | + echo "==========================================" + echo "${{ inputs.cache-type }} cache clear tag detection" + echo "==========================================" + echo "Searching for: [ci-ga-clear-cache] or [ci-ga-clear-cache:*]" + echo "" + + CACHE_KEY="${{ inputs.key }}" + + # Extract search terms if present (e.g., "ccache" from "[ci-ga-clear-cache:ccache]") + SEARCH_TERMS=$(echo "${XAHAU_GA_COMMIT_MSG}" | grep -o '\[ci-ga-clear-cache:[^]]*\]' | sed 's/\[ci-ga-clear-cache://;s/\]//' || echo "") + + SHOULD_CLEAR=false + + if [ -n "${SEARCH_TERMS}" ]; then + # Search terms provided - check if THIS cache key matches ALL terms (AND logic) + echo "🔍 [ci-ga-clear-cache:${SEARCH_TERMS}] detected" + echo "Checking if cache key matches search terms..." + echo " Cache key: ${CACHE_KEY}" + echo " Search terms: ${SEARCH_TERMS}" + echo "" + + MATCHES=true + for term in ${SEARCH_TERMS}; do + if ! echo "${CACHE_KEY}" | grep -q "${term}"; then + MATCHES=false + echo " ✗ Key does not contain '${term}'" + break + else + echo " ✓ Key contains '${term}'" + fi + done + + if [ "${MATCHES}" = "true" ]; then + echo "" + echo "✅ Cache key matches all search terms - will clear cache" + SHOULD_CLEAR=true + else + echo "" + echo "â­ī¸ Cache key doesn't match search terms - skipping cache clear" + fi + elif echo "${XAHAU_GA_COMMIT_MSG}" | grep -q '\[ci-ga-clear-cache\]'; then + # No search terms - always clear this job's cache + echo "đŸ—‘ī¸ [ci-ga-clear-cache] detected in commit message" + echo "Clearing ${{ inputs.cache-type }} cache for key: ${CACHE_KEY}" + SHOULD_CLEAR=true + fi + + if [ "${SHOULD_CLEAR}" = "true" ]; then + echo "" + echo "Deleting ${{ inputs.cache-type }} caches via GitHub API..." + + # Delete primary cache key + echo "Checking for cache: ${CACHE_KEY}" + if gh cache list --key "${CACHE_KEY}" --json key --jq '.[].key' | grep -q "${CACHE_KEY}"; then + echo " Deleting: ${CACHE_KEY}" + gh cache delete "${CACHE_KEY}" || true + echo " ✓ Deleted" + else + echo " â„šī¸ Not found" + fi + + # Delete additional keys if provided + if [ -n "${{ inputs.additional-clear-keys }}" ]; then + echo "" + echo "Checking additional keys..." + while IFS= read -r key; do + [ -z "${key}" ] && continue + echo "Checking for cache: ${key}" + if gh cache list --key "${key}" --json key --jq '.[].key' | grep -q "${key}"; then + echo " Deleting: ${key}" + gh cache delete "${key}" || true + echo " ✓ Deleted" + else + echo " â„šī¸ Not found" + fi + done <<< "${{ inputs.additional-clear-keys }}" + fi + + echo "" + echo "✅ ${{ inputs.cache-type }} cache cleared successfully" + echo "Build will proceed from scratch" + else + echo "" + echo "â„šī¸ No ${{ inputs.cache-type }} cache clear requested" + fi + echo "==========================================" - name: Restore cache id: restore-cache diff --git a/.github/actions/xahau-ga-clear-cache/action.yml b/.github/actions/xahau-ga-clear-cache/action.yml deleted file mode 100644 index 4774d585d..000000000 --- a/.github/actions/xahau-ga-clear-cache/action.yml +++ /dev/null @@ -1,110 +0,0 @@ -name: 'Clear Cache' -description: 'Clears GitHub Actions cache based on commit message tags' - -inputs: - cache-key: - description: 'The cache key to check and potentially clear' - required: true - cache-type: - description: 'Type of cache (for logging purposes, e.g., "ccache", "Conan")' - required: false - default: 'cache' - additional-keys: - description: 'Additional cache keys to clear (newline separated)' - required: false - default: '' - -runs: - using: 'composite' - steps: - - name: Clear cache if requested via commit message - shell: bash - env: - GH_TOKEN: ${{ github.token }} - run: | - echo "==========================================" - echo "${{ inputs.cache-type }} cache clear tag detection" - echo "==========================================" - echo "Searching for: [ci-ga-clear-cache] or [ci-ga-clear-cache:*]" - echo "" - - CACHE_KEY="${{ inputs.cache-key }}" - - # Extract search terms if present (e.g., "ccache" from "[ci-ga-clear-cache:ccache]") - SEARCH_TERMS=$(echo "${XAHAU_GA_COMMIT_MSG}" | grep -o '\[ci-ga-clear-cache:[^]]*\]' | sed 's/\[ci-ga-clear-cache://;s/\]//' || echo "") - - SHOULD_CLEAR=false - - if [ -n "${SEARCH_TERMS}" ]; then - # Search terms provided - check if THIS cache key matches ALL terms (AND logic) - echo "🔍 [ci-ga-clear-cache:${SEARCH_TERMS}] detected" - echo "Checking if cache key matches search terms..." - echo " Cache key: ${CACHE_KEY}" - echo " Search terms: ${SEARCH_TERMS}" - echo "" - - MATCHES=true - for term in ${SEARCH_TERMS}; do - if ! echo "${CACHE_KEY}" | grep -q "${term}"; then - MATCHES=false - echo " ✗ Key does not contain '${term}'" - break - else - echo " ✓ Key contains '${term}'" - fi - done - - if [ "${MATCHES}" = "true" ]; then - echo "" - echo "✅ Cache key matches all search terms - will clear cache" - SHOULD_CLEAR=true - else - echo "" - echo "â­ī¸ Cache key doesn't match search terms - skipping cache clear" - fi - elif echo "${XAHAU_GA_COMMIT_MSG}" | grep -q '\[ci-ga-clear-cache\]'; then - # No search terms - always clear this job's cache - echo "đŸ—‘ī¸ [ci-ga-clear-cache] detected in commit message" - echo "Clearing ${{ inputs.cache-type }} cache for key: ${CACHE_KEY}" - SHOULD_CLEAR=true - fi - - if [ "${SHOULD_CLEAR}" = "true" ]; then - echo "" - echo "Deleting ${{ inputs.cache-type }} caches via GitHub API..." - - # Delete primary cache key - echo "Checking for cache: ${CACHE_KEY}" - if gh cache list --key "${CACHE_KEY}" --json key --jq '.[].key' | grep -q "${CACHE_KEY}"; then - echo " Deleting: ${CACHE_KEY}" - gh cache delete "${CACHE_KEY}" || true - echo " ✓ Deleted" - else - echo " â„šī¸ Not found" - fi - - # Delete additional keys if provided - if [ -n "${{ inputs.additional-keys }}" ]; then - echo "" - echo "Checking additional keys..." - while IFS= read -r key; do - [ -z "${key}" ] && continue - echo "Checking for cache: ${key}" - if gh cache list --key "${key}" --json key --jq '.[].key' | grep -q "${key}"; then - echo " Deleting: ${key}" - gh cache delete "${key}" || true - echo " ✓ Deleted" - else - echo " â„šī¸ Not found" - fi - done <<< "${{ inputs.additional-keys }}" - fi - - echo "" - echo "✅ ${{ inputs.cache-type }} cache cleared successfully" - echo "Build will proceed from scratch" - else - echo "" - echo "â„šī¸ No ${{ inputs.cache-type }} cache clear requested" - fi - echo "==========================================" diff --git a/.github/workflows/xahau-ga-nix.yml b/.github/workflows/xahau-ga-nix.yml index 8dafa4a4b..b482c7e2a 100644 --- a/.github/workflows/xahau-ga-nix.yml +++ b/.github/workflows/xahau-ga-nix.yml @@ -2,7 +2,7 @@ name: Nix - GA Runner on: push: - branches: ["dev", "candidate", "release", "nd-experiment-overlayfs-2025-10-29"] + branches: ["dev", "candidate", "release"] pull_request: branches: ["dev", "candidate", "release"] schedule: