diff --git a/actions/compute-asset-hash/action.yml b/actions/compute-asset-hash/action.yml new file mode 100644 index 0000000..e7c5831 --- /dev/null +++ b/actions/compute-asset-hash/action.yml @@ -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 diff --git a/actions/restore-assets/action.yml b/actions/restore-assets/action.yml index c08d4ef..bcffedb 100644 --- a/actions/restore-assets/action.yml +++ b/actions/restore-assets/action.yml @@ -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 diff --git a/actions/sync-assets/action.yml b/actions/sync-assets/action.yml index 8f4c9e2..c079d33 100644 --- a/actions/sync-assets/action.yml +++ b/actions/sync-assets/action.yml @@ -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