From 41ce7d653f24b6d7c705df9ea03037be9057c2a0 Mon Sep 17 00:00:00 2001 From: Pascal Roeleven Date: Wed, 1 Mar 2023 15:01:14 +0100 Subject: [PATCH] Cache Magisk with database hash Simplify caching by caching on database hash instead of Magisk hash. hashFiles is only available in the steps, hence the reason for it being exported to the outputs from the steps (and not directly). --- .github/actions/preload-magisk-cache/action.yml | 6 +++--- .github/workflows/ci.yml | 12 +++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/actions/preload-magisk-cache/action.yml b/.github/actions/preload-magisk-cache/action.yml index dd835a6..a83676f 100644 --- a/.github/actions/preload-magisk-cache/action.yml +++ b/.github/actions/preload-magisk-cache/action.yml @@ -1,7 +1,7 @@ name: Preload Magisk inputs: - hash: - description: 'Magisk hash' + cache-key: + description: 'Magisk cache-key' required: true url: description: 'Magisk URL' @@ -13,7 +13,7 @@ runs: - uses: actions/cache@v3 id: cache-magisk with: - key: magisk-${{ inputs.hash }} + key: ${{ inputs.cache-key }} path: | workdir/magisk.apk - name: Creating workdir diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 724b75a..e79838d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,7 @@ jobs: outputs: device-db: ${{ steps.load-db.outputs.device-db }} device-list: ${{ steps.load-db.outputs.device-list }} - magisk-hash: ${{ steps.load-db.outputs.magisk-hash }} + magisk-key: ${{ steps.get-magisk-cache.outputs.magisk-key }} magisk-url: ${{ steps.load-db.outputs.magisk-url }} img-to-cache: ${{ steps.load-db.outputs.img-to-cache }} hit-magisk: ${{ fromJSON(steps.get-magisk-cache.outputs.magisk-hit).total_count != 0 }} @@ -78,17 +78,19 @@ jobs: with open(os.environ['GITHUB_OUTPUT'], 'a') as f: f.write(f"device-db={db['device']}" + '\n') f.write(f"device-list={[i for i in db['device']]}" + '\n') - f.write(f"magisk-hash={db['magisk']['sha256']}" + '\n') f.write(f"magisk-url={db['magisk']['url']}" + '\n') f.write(f"img-to-cache={devices_to_cache}" + '\n') - name: Checking for cached magisk apk id: get-magisk-cache + env: + magisk-key: magisk-${{ hashFiles(env.test-db-path) }} run: | + echo "magisk-key=${{ env.magisk-key }}" >> $GITHUB_OUTPUT echo "magisk-hit=$(gh api \ --method GET \ -H 'Accept: application/vnd.github+json' \ -H 'X-GitHub-Api-Version: 2022-11-28' \ - -f 'key=magisk-${{ steps.load-db.outputs.magisk-hash }}' \ + -f 'key=${{ env.magisk-key }}' \ /repos/${{ github.repository }}/actions/caches)" >> $GITHUB_OUTPUT preload-magisk: @@ -101,7 +103,7 @@ jobs: - uses: actions/checkout@v3 - uses: ./.github/actions/preload-magisk-cache with: - hash: ${{ needs.setup.outputs.magisk-hash }} + cache-key: ${{ needs.setup.outputs.magisk-key }} url: ${{ needs.setup.outputs.magisk-url }} preload-img: @@ -161,7 +163,7 @@ jobs: submodules: true - uses: ./.github/actions/preload-magisk-cache with: - hash: ${{ needs.setup.outputs.magisk-hash }} + cache-key: ${{ needs.setup.outputs.magisk-key }} url: ${{ needs.setup.outputs.magisk-url }} - uses: ./.github/actions/preload-img-cache with: