From df9a6c2970e0f8ac80247308bb42a649a887f8d7 Mon Sep 17 00:00:00 2001 From: Pascal Roeleven Date: Mon, 6 Mar 2023 02:07:15 +0100 Subject: [PATCH] Make cache pre-checks more robust Also fix preload Magisk cache workflow --- .../actions/preload-magisk-cache/action.yml | 4 +- .github/workflows/ci.yml | 66 ++++++++----------- 2 files changed, 29 insertions(+), 41 deletions(-) diff --git a/.github/actions/preload-magisk-cache/action.yml b/.github/actions/preload-magisk-cache/action.yml index 3f2050c..f992689 100644 --- a/.github/actions/preload-magisk-cache/action.yml +++ b/.github/actions/preload-magisk-cache/action.yml @@ -13,12 +13,12 @@ runs: key: ${{ inputs.cache-key }} path: tests/files/magisk - - if: ${{ ! steps.cache-img.outputs.cache-hit }} + - if: ${{ ! steps.cache-magisk.outputs.cache-hit }} uses: awalsh128/cache-apt-pkgs-action@v1 with: packages: python3-lz4 python3-protobuf - - if: ${{ ! steps.cache-img.outputs.cache-hit }} + - if: ${{ ! steps.cache-magisk.outputs.cache-hit }} uses: awalsh128/cache-apt-pkgs-action@v1 with: packages: python3-strictyaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 773f3c6..6cf4f25 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,11 +26,11 @@ jobs: outputs: config-path: ${{ steps.load-config.outputs.config-path }} device-list: ${{ steps.load-config.outputs.device-list }} - magisk-key: ${{ steps.get-magisk-cache.outputs.magisk-key }} - img-key-prefix: ${{ steps.get-img-cache.outputs.img-key-prefix }} - img-hit: ${{ steps.get-img-cache.outputs.img-hit }} - tox-key-prefix: ${{ steps.get-tox-cache.outputs.tox-key-prefix }} - tox-hit: ${{ steps.get-tox-cache.outputs.tox-hit }} + magisk-key: ${{ steps.cache-keys.outputs.magisk-key }} + img-key-prefix: ${{ steps.cache-keys.outputs.img-key-prefix }} + img-hit: ${{ steps.get-img-cache.outputs.cache-hit }} + tox-key-prefix: ${{ steps.cache-keys.outputs.tox-key-prefix }} + tox-hit: ${{ steps.get-tox-cache.outputs.cache-hit }} steps: - uses: actions/checkout@v3 with: @@ -58,49 +58,37 @@ jobs: f.write(f'config-path={tests.config.CONFIG_PATH}\n') f.write(f"device-list={json.dumps(devices)}\n") + - name: Generating cache keys + id: cache-keys + run: | + { + echo "tox-key-prefix=tox-${{ hashFiles('tox.ini') }}-"; \ + echo "img-key-prefix=img-${{ hashFiles(steps.load-config.outputs.config-path) }}-"; \ + echo "magisk-key=magisk-${{ hashFiles(steps.load-config.outputs.config-path) }}"; + } >> $GITHUB_OUTPUT + - name: Checking for cached tox environments id: get-tox-cache - env: - tox-key-prefix: tox-${{ hashFiles('tox.ini') }}- - run: | - echo "tox-key-prefix=${{ env.tox-key-prefix }}" >> $GITHUB_OUTPUT - echo "tox-hit=$(gh api \ - --method GET \ - -H 'Accept: application/vnd.github+json' \ - -H 'X-GitHub-Api-Version: 2022-11-28' \ - -f 'key=${{ env.tox-key-prefix }}' \ - /repos/${{ github.repository }}/actions/caches)" >> $GITHUB_OUTPUT + uses: pascallj/cache-key-check@v1 + with: + key: ${{ steps.cache-keys.outputs.tox-key-prefix }} - name: Checking for cached device images id: get-img-cache - env: - img-key-prefix: img-${{ hashFiles(steps.load-config.outputs.config-path) }}- - run: | - echo "img-key-prefix=${{ env.img-key-prefix }}" >> $GITHUB_OUTPUT - echo "img-hit=$(gh api \ - --method GET \ - -H 'Accept: application/vnd.github+json' \ - -H 'X-GitHub-Api-Version: 2022-11-28' \ - -f 'key=${{ env.img-key-prefix }}' \ - /repos/${{ github.repository }}/actions/caches)" >> $GITHUB_OUTPUT + uses: pascallj/cache-key-check@v1 + with: + key: ${{ steps.cache-keys.outputs.img-key-prefix }} - name: Checking for cached magisk apk id: get-magisk-cache - env: - magisk-key: magisk-${{ hashFiles(steps.load-config.outputs.config-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=${{ env.magisk-key }}' \ - /repos/${{ github.repository }}/actions/caches)" >> $GITHUB_OUTPUT + uses: pascallj/cache-key-check@v1 + with: + key: ${{ steps.cache-keys.outputs.magisk-key }} - uses: ./.github/actions/preload-magisk-cache - if: ${{ fromJSON(steps.get-magisk-cache.outputs.magisk-hit).total_count == 0 }} + if: ${{ steps.get-magisk-cache.outputs.cache-hit != 'true' }} with: - cache-key: ${{ steps.get-magisk-cache.outputs.magisk-key }} + cache-key: ${{ steps.cache-keys.outputs.magisk-key }} preload-img: name: Preload device images @@ -110,7 +98,7 @@ jobs: # Assume that preloading always succesfully cached all images before. # If for some reason only some got cached, on the first run, the cache will not be preloaded # which will result in some being downloaded multiple times when running the tests. - if: ${{ fromJSON(needs.setup.outputs.img-hit).total_count == 0 }} + if: ${{ needs.setup.outputs.img-hit != 'true' }} strategy: matrix: device: ${{ fromJSON(needs.setup.outputs.device-list) }} @@ -132,7 +120,7 @@ jobs: # Assume that preloading always succesfully cached all tox environments before. # If for some reason only some got cached, on the first run, the cache will not be preloaded # which will result in some being downloaded multiple times when running the tests. - if: ${{ fromJSON(needs.setup.outputs.tox-hit).total_count == 0 }} + if: ${{ needs.setup.outputs.tox-hit != 'true' }} strategy: matrix: python: [py39, py310, py311]