Use separate action to compute cache keys

This commit is contained in:
Felipe Knorr Kuhn 2026-02-15 16:38:55 -08:00
parent 507563a279
commit 2a8a35828d
No known key found for this signature in database
GPG Key ID: 79619B52BB097C1A
3 changed files with 49 additions and 34 deletions

View File

@ -0,0 +1,37 @@
name: 'Compute Asset Cache Hash'
description: 'Compute hash from mining-pool-logos and mempool-promo HEAD SHAs for cache keys'
inputs:
github-token:
description: 'GitHub token for API access'
required: true
cache-version:
description: 'Cache version fallback when remote SHA lookup fails'
required: false
default: 'v1'
outputs:
hash:
description: 'Hash used for cache keys (12-char sha256 of both SHAs or cache-version)'
value: ${{ steps.compute-hash.outputs.hash }}
runs:
using: 'composite'
steps:
- name: Compute asset cache key from remote SHAs
id: compute-hash
shell: bash
env:
FALLBACK_VERSION: ${{ inputs.cache-version }}
run: |
AUTH_HEADER="Authorization: Bearer ${{ inputs.github-token }}"
LOGOS_SHA=$(curl -sf -H "$AUTH_HEADER" -H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/mempool/mining-pool-logos/commits/HEAD" 2>/dev/null | jq -r '.sha // empty') || true
PROMO_SHA=$(curl -sf -H "$AUTH_HEADER" -H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/mempool/mempool-promo/commits/HEAD" 2>/dev/null | jq -r '.sha // empty') || true
if [[ -n "$LOGOS_SHA" && -n "$PROMO_SHA" ]]; then
HASH=$(echo -n "${LOGOS_SHA}${PROMO_SHA}" | sha256sum | cut -c1-12)
else
HASH="$FALLBACK_VERSION"
fi
echo "hash=$HASH" >> $GITHUB_OUTPUT

View File

@ -30,21 +30,10 @@ runs:
steps:
- name: Compute asset cache key from remote SHAs
id: asset-hash
shell: bash
env:
FALLBACK_VERSION: ${{ inputs.cache-version }}
run: |
AUTH_HEADER="Authorization: Bearer ${{ inputs.github-token }}"
LOGOS_SHA=$(curl -sf -H "$AUTH_HEADER" -H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/mempool/mining-pool-logos/commits/HEAD" 2>/dev/null | jq -r '.sha // empty') || true
PROMO_SHA=$(curl -sf -H "$AUTH_HEADER" -H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/mempool/mempool-promo/commits/HEAD" 2>/dev/null | jq -r '.sha // empty') || true
if [[ -n "$LOGOS_SHA" && -n "$PROMO_SHA" ]]; then
HASH=$(echo -n "${LOGOS_SHA}${PROMO_SHA}" | sha256sum | cut -c1-12)
else
HASH="$FALLBACK_VERSION"
fi
echo "hash=$HASH" >> $GITHUB_OUTPUT
uses: ./.github/actions/compute-asset-hash
with:
github-token: ${{ inputs.github-token }}
cache-version: ${{ inputs.cache-version }}
- name: Restore cached mining pool assets
continue-on-error: true
@ -54,7 +43,7 @@ runs:
path: mining-pool-assets.zip
key: mining-pool-assets-${{ steps.asset-hash.outputs.hash }}
restore-keys: |
mining-pool-assets-${{ steps.asset-hash.outputs.hash }}
mining-pool-assets-
- name: Restore cached promo video assets
continue-on-error: true
@ -64,7 +53,7 @@ runs:
path: promo-video-assets.zip
key: promo-video-assets-${{ steps.asset-hash.outputs.hash }}
restore-keys: |
promo-video-assets-${{ steps.asset-hash.outputs.hash }}
promo-video-assets-
- name: Download mining pool artifact
continue-on-error: true

View File

@ -27,21 +27,10 @@ runs:
steps:
- name: Compute asset cache key from remote SHAs
id: asset-hash
shell: bash
env:
FALLBACK_VERSION: ${{ inputs.cache-version }}
run: |
AUTH_HEADER="Authorization: Bearer ${{ inputs.github-token }}"
LOGOS_SHA=$(curl -sf -H "$AUTH_HEADER" -H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/mempool/mining-pool-logos/commits/HEAD" 2>/dev/null | jq -r '.sha // empty') || true
PROMO_SHA=$(curl -sf -H "$AUTH_HEADER" -H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/mempool/mempool-promo/commits/HEAD" 2>/dev/null | jq -r '.sha // empty') || true
if [[ -n "$LOGOS_SHA" && -n "$PROMO_SHA" ]]; then
HASH=$(echo -n "${LOGOS_SHA}${PROMO_SHA}" | sha256sum | cut -c1-12)
else
HASH="$FALLBACK_VERSION"
fi
echo "hash=$HASH" >> $GITHUB_OUTPUT
uses: ./.github/actions/compute-asset-hash
with:
github-token: ${{ inputs.github-token }}
cache-version: ${{ inputs.cache-version }}
# Cache miss is success with cache-hit=false; only real errors (network, permissions) fail the step.
- name: Restore cached mining pool assets
@ -51,7 +40,7 @@ runs:
path: mining-pool-assets.zip
key: mining-pool-assets-${{ steps.asset-hash.outputs.hash }}
restore-keys: |
mining-pool-assets-${{ steps.asset-hash.outputs.hash }}
mining-pool-assets-
# Cache miss is success with cache-hit=false; only real errors (network, permissions) fail the step.
- name: Restore cached promo video assets
@ -61,7 +50,7 @@ runs:
path: promo-video-assets.zip
key: promo-video-assets-${{ steps.asset-hash.outputs.hash }}
restore-keys: |
promo-video-assets-${{ steps.asset-hash.outputs.hash }}
promo-video-assets-
- name: Unzip mining pool assets before sync
continue-on-error: true