From fb2c5122484b3c392b1d1522d2991d4f94402914 Mon Sep 17 00:00:00 2001 From: Pascal Roeleven Date: Mon, 27 Feb 2023 16:31:23 +0100 Subject: [PATCH 1/6] Test all device images in Github Actions --- .github/actions/preload-img-cache/action.yml | 47 +++++ .../actions/preload-magisk-cache/action.yml | 27 +++ .github/actions/preload-tox-cache/action.yml | 24 +++ .github/workflows/ci.yml | 177 ++++++++++++++++++ 4 files changed, 275 insertions(+) create mode 100644 .github/actions/preload-img-cache/action.yml create mode 100644 .github/actions/preload-magisk-cache/action.yml create mode 100644 .github/actions/preload-tox-cache/action.yml create mode 100644 .github/workflows/ci.yml diff --git a/.github/actions/preload-img-cache/action.yml b/.github/actions/preload-img-cache/action.yml new file mode 100644 index 0000000..c6e156b --- /dev/null +++ b/.github/actions/preload-img-cache/action.yml @@ -0,0 +1,47 @@ +name: Preload img cache +inputs: + device: + description: 'Device name' + required: true + filename: + description: 'Name of file in workdir' + required: true + test-db-path: + description: 'Path to test database' + required: true +outputs: + cache-hit: + description: 'Did we hit the cache?' + value: ${{ steps.cache-img.outputs.cache-hit }} + +runs: + using: "composite" + steps: + - uses: actions/cache@v3 + id: cache-img + with: + key: img-${{ inputs.device }}-${{ inputs.filename }} + path: | + workdir/${{ inputs.filename }} + - if: ${{ ! steps.cache-img.outputs.cache-hit }} + uses: awalsh128/cache-apt-pkgs-action@v1 + with: + packages: python3-lz4 python3-protobuf + - if: ${{ ! steps.cache-img.outputs.cache-hit }} + uses: awalsh128/cache-apt-pkgs-action@v1 + with: + packages: python3-tomlkit + - name: Creating workdir + if: ${{ ! steps.cache-img.outputs.cache-hit }} + shell: sh + run: mkdir -p workdir + - name: Downloading device image for ${{ inputs.device }} + if: ${{ ! steps.cache-img.outputs.cache-hit }} + shell: sh + run: | + ./tests_ci/dummy_image.py \ + download \ + --no-compress \ + --db ${{ inputs.test-db-path }} \ + --output workdir/${{ inputs.filename }} \ + ${{ inputs.device }} diff --git a/.github/actions/preload-magisk-cache/action.yml b/.github/actions/preload-magisk-cache/action.yml new file mode 100644 index 0000000..dd835a6 --- /dev/null +++ b/.github/actions/preload-magisk-cache/action.yml @@ -0,0 +1,27 @@ +name: Preload Magisk +inputs: + hash: + description: 'Magisk hash' + required: true + url: + description: 'Magisk URL' + required: true + +runs: + using: "composite" + steps: + - uses: actions/cache@v3 + id: cache-magisk + with: + key: magisk-${{ inputs.hash }} + path: | + workdir/magisk.apk + - name: Creating workdir + if: ${{ ! steps.cache-magisk.outputs.cache-hit }} + shell: sh + run: mkdir -p workdir + - name: Downloading Magisk + if: ${{ ! steps.cache-magisk.outputs.cache-hit }} + shell: sh + run: | + curl -L -o workdir/magisk.apk ${{ inputs.url }} diff --git a/.github/actions/preload-tox-cache/action.yml b/.github/actions/preload-tox-cache/action.yml new file mode 100644 index 0000000..f409d85 --- /dev/null +++ b/.github/actions/preload-tox-cache/action.yml @@ -0,0 +1,24 @@ +name: Preload tox cache +inputs: + python-version: + description: 'Python version' + required: true + +runs: + using: "composite" + steps: + - uses: actions/cache@v3 + with: + key: tox-${{ inputs.python-version }}-${{ hashFiles('tox.ini') }} + restore-keys: | + tox-${{ inputs.python-version }} + path: | + .tox/ + ~/.cache/pip + - uses: awalsh128/cache-apt-pkgs-action@v1 + with: + packages: tox + - uses: actions/setup-python@v4 + with: + python-version: | + ${{ fromJson('{ "py39": "3.9", "py310": "3.10", "py311": "3.11" }')[inputs.python-version] }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..724b75a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,177 @@ +name: CI +on: push + +env: + test-db-path: tests_ci/test_db.toml + +# This allows a subsequently queued workflow run to interrupt previous runs +concurrency: + group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' + cancel-in-progress: true + +jobs: + setup: + name: Prepare workflow data + runs-on: ubuntu-latest + timeout-minutes: 2 + permissions: + # Default + contents: read + packages: read + # Custom, for API cache access + actions: read + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + 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-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 }} + hit-tox: | + ${{ contains(fromJSON(steps.get-tox-cache.outputs.tox-hit).actions_caches.*.key, format('tox-py39-{0}', steps.get-tox-cache.outputs.tox-hash)) + && contains(fromJSON(steps.get-tox-cache.outputs.tox-hit).actions_caches.*.key, format('tox-py310-{0}', steps.get-tox-cache.outputs.tox-hash)) + && contains(fromJSON(steps.get-tox-cache.outputs.tox-hit).actions_caches.*.key, format('tox-py311-{0}', steps.get-tox-cache.outputs.tox-hash)) }} + steps: + - uses: actions/checkout@v3 + - uses: awalsh128/cache-apt-pkgs-action@v1 + with: + packages: python3-tomlkit + - name: Checking for cached tox environments + id: get-tox-cache + run: | + echo "tox-hit=$(gh api \ + --method GET \ + -H 'Accept: application/vnd.github+json' \ + -H 'X-GitHub-Api-Version: 2022-11-28' \ + -f 'key=tox-py3' \ + /repos/${{ github.repository }}/actions/caches)" >> $GITHUB_OUTPUT + echo "tox-hash=${{ hashFiles('tox.ini') }}" >> $GITHUB_OUTPUT + - name: Checking for cached device images + run: | + gh api \ + --method GET \ + -H 'Accept: application/vnd.github+json' \ + -H 'X-GitHub-Api-Version: 2022-11-28' \ + -f 'key=img-' \ + /repos/${{ github.repository }}/actions/caches > cache-data.json + - name: Loading device test database + id: load-db + shell: python + run: | + import json + import os + import tomlkit + + with open('${{ env.test-db-path }}') as f: + db = tomlkit.load(f) + + with open('cache-data.json', 'r') as f: + cache_data = json.load(f) + + cache_names = {'img-' + i + '-' + j['filename']:i for i,j in db['device'].items()} + filenames_cached = [i['key'] for i in cache_data.get('actions_caches') or []] + filenames_to_cache = list(set(cache_names) - set(filenames_cached)) + devices_to_cache = [cache_names[i] for i in filenames_to_cache] + + 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 + run: | + 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 }}' \ + /repos/${{ github.repository }}/actions/caches)" >> $GITHUB_OUTPUT + + preload-magisk: + name: Preload Magisk + runs-on: ubuntu-latest + needs: setup + timeout-minutes: 2 + if: ${{ ! fromJSON(needs.setup.outputs.hit-magisk) }} + steps: + - uses: actions/checkout@v3 + - uses: ./.github/actions/preload-magisk-cache + with: + hash: ${{ needs.setup.outputs.magisk-hash }} + url: ${{ needs.setup.outputs.magisk-url }} + + preload-img: + name: Preload device images + runs-on: ubuntu-latest + needs: setup + timeout-minutes: 5 + if: ${{ needs.setup.outputs.img-to-cache != '[]' }} + strategy: + matrix: + device: ${{ fromJSON(needs.setup.outputs.img-to-cache) }} + env: + filename: ${{ fromJSON(needs.setup.outputs.device-db)[matrix.device]['filename'] }} + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - uses: ./.github/actions/preload-img-cache + with: + device: ${{ matrix.device }} + filename: ${{ env.filename }} + test-db-path: ${{ env.test-db-path }} + + preload-tox: + name: Preload tox environments + runs-on: ubuntu-latest + needs: setup + timeout-minutes: 5 + if: ${{ ! fromJSON(needs.setup.outputs.hit-tox) }} + strategy: + matrix: + python: [py39, py310, py311] + steps: + - uses: actions/checkout@v3 + - uses: ./.github/actions/preload-tox-cache + with: + python-version: ${{ matrix.python }} + - name: Generating tox environment + run: tox -e ${{ matrix.python }} --notest + + tests: + name: Run test for ${{ matrix.device }} with ${{ matrix.python }} + runs-on: ubuntu-latest + needs: [setup, preload-magisk, preload-img, preload-tox] + timeout-minutes: 5 + # Continue on skipped but not on failures or cancels + if: ${{ always() && ! failure() && ! cancelled() }} + strategy: + matrix: + device: ${{ fromJSON(needs.setup.outputs.device-list) }} + python: [py39, py310, py311] + env: + filename: ${{ fromJSON(needs.setup.outputs.device-db)[matrix.device]['filename'] }} + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - uses: ./.github/actions/preload-magisk-cache + with: + hash: ${{ needs.setup.outputs.magisk-hash }} + url: ${{ needs.setup.outputs.magisk-url }} + - uses: ./.github/actions/preload-img-cache + with: + device: ${{ matrix.device }} + filename: ${{ env.filename }} + test-db-path: ${{ env.test-db-path }} + - uses: ./.github/actions/preload-tox-cache + with: + python-version: ${{ matrix.python }} + + # Finally run tests + - name: Run test for ${{ matrix.device }} with ${{ matrix.python }} + run: tox -e ${{ matrix.python }} -- -d ${{ matrix.device }} --db ${{ env.test-db-path }} --workdir workdir From 41ce7d653f24b6d7c705df9ea03037be9057c2a0 Mon Sep 17 00:00:00 2001 From: Pascal Roeleven Date: Wed, 1 Mar 2023 15:01:14 +0100 Subject: [PATCH 2/6] 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: From 0b6f76637f7f559659249671d62c71fbc1be547a Mon Sep 17 00:00:00 2001 From: Pascal Roeleven Date: Wed, 1 Mar 2023 15:14:47 +0100 Subject: [PATCH 3/6] Move caching of Magisk to setup workflow It's unnecessary to spin up an entire runner for just this short and simple task. --- .github/workflows/ci.yml | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e79838d..5f1f589 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,6 @@ jobs: 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 }} hit-tox: | ${{ contains(fromJSON(steps.get-tox-cache.outputs.tox-hit).actions_caches.*.key, format('tox-py39-{0}', steps.get-tox-cache.outputs.tox-hash)) && contains(fromJSON(steps.get-tox-cache.outputs.tox-hit).actions_caches.*.key, format('tox-py310-{0}', steps.get-tox-cache.outputs.tox-hash)) @@ -92,19 +91,11 @@ jobs: -H 'X-GitHub-Api-Version: 2022-11-28' \ -f 'key=${{ env.magisk-key }}' \ /repos/${{ github.repository }}/actions/caches)" >> $GITHUB_OUTPUT - - preload-magisk: - name: Preload Magisk - runs-on: ubuntu-latest - needs: setup - timeout-minutes: 2 - if: ${{ ! fromJSON(needs.setup.outputs.hit-magisk) }} - steps: - - uses: actions/checkout@v3 - uses: ./.github/actions/preload-magisk-cache + if: ${{ fromJSON(steps.get-magisk-cache.outputs.magisk-hit).total_count == 0 }} with: - cache-key: ${{ needs.setup.outputs.magisk-key }} - url: ${{ needs.setup.outputs.magisk-url }} + cache-key: ${{ steps.get-magisk-cache.outputs.magisk-key }} + url: ${{ steps.load-db.outputs.magisk-url }} preload-img: name: Preload device images @@ -147,7 +138,7 @@ jobs: tests: name: Run test for ${{ matrix.device }} with ${{ matrix.python }} runs-on: ubuntu-latest - needs: [setup, preload-magisk, preload-img, preload-tox] + needs: [setup, preload-img, preload-tox] timeout-minutes: 5 # Continue on skipped but not on failures or cancels if: ${{ always() && ! failure() && ! cancelled() }} From 50b8d28779b876b8e51bc14f6215b3697acaf11d Mon Sep 17 00:00:00 2001 From: Pascal Roeleven Date: Wed, 1 Mar 2023 15:50:16 +0100 Subject: [PATCH 4/6] Cache images with database hash --- .github/actions/preload-img-cache/action.yml | 2 +- .github/workflows/ci.yml | 26 ++++++++------------ 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/.github/actions/preload-img-cache/action.yml b/.github/actions/preload-img-cache/action.yml index c6e156b..073fb33 100644 --- a/.github/actions/preload-img-cache/action.yml +++ b/.github/actions/preload-img-cache/action.yml @@ -20,7 +20,7 @@ runs: - uses: actions/cache@v3 id: cache-img with: - key: img-${{ inputs.device }}-${{ inputs.filename }} + key: img-${{ hashFiles(inputs.test-db-path) }}-${{ inputs.device }} path: | workdir/${{ inputs.filename }} - if: ${{ ! steps.cache-img.outputs.cache-hit }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5f1f589..5159353 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: device-list: ${{ steps.load-db.outputs.device-list }} 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-img: ${{ steps.get-img-cache.outputs.img-hit }} hit-tox: | ${{ contains(fromJSON(steps.get-tox-cache.outputs.tox-hit).actions_caches.*.key, format('tox-py39-{0}', steps.get-tox-cache.outputs.tox-hash)) && contains(fromJSON(steps.get-tox-cache.outputs.tox-hit).actions_caches.*.key, format('tox-py310-{0}', steps.get-tox-cache.outputs.tox-hash)) @@ -48,37 +48,28 @@ jobs: /repos/${{ github.repository }}/actions/caches)" >> $GITHUB_OUTPUT echo "tox-hash=${{ hashFiles('tox.ini') }}" >> $GITHUB_OUTPUT - name: Checking for cached device images + id: get-img-cache run: | - gh api \ + echo "img-hit=$(gh api \ --method GET \ -H 'Accept: application/vnd.github+json' \ -H 'X-GitHub-Api-Version: 2022-11-28' \ - -f 'key=img-' \ - /repos/${{ github.repository }}/actions/caches > cache-data.json + -f 'key=img-${{ hashFiles(env.test-db-path) }}-' \ + /repos/${{ github.repository }}/actions/caches)" >> $GITHUB_OUTPUT - name: Loading device test database id: load-db shell: python run: | - import json import os import tomlkit with open('${{ env.test-db-path }}') as f: db = tomlkit.load(f) - with open('cache-data.json', 'r') as f: - cache_data = json.load(f) - - cache_names = {'img-' + i + '-' + j['filename']:i for i,j in db['device'].items()} - filenames_cached = [i['key'] for i in cache_data.get('actions_caches') or []] - filenames_to_cache = list(set(cache_names) - set(filenames_cached)) - devices_to_cache = [cache_names[i] for i in filenames_to_cache] - 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-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: @@ -102,10 +93,13 @@ jobs: runs-on: ubuntu-latest needs: setup timeout-minutes: 5 - if: ${{ needs.setup.outputs.img-to-cache != '[]' }} + # 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.hit-img).total_count == 0 }} strategy: matrix: - device: ${{ fromJSON(needs.setup.outputs.img-to-cache) }} + device: ${{ fromJSON(needs.setup.outputs.device-list) }} env: filename: ${{ fromJSON(needs.setup.outputs.device-db)[matrix.device]['filename'] }} steps: From 4ac7826c32be65147f9469b64a99b8e65c803d8a Mon Sep 17 00:00:00 2001 From: Pascal Roeleven Date: Wed, 1 Mar 2023 15:58:12 +0100 Subject: [PATCH 5/6] Cache tox environments with tox hash --- .github/actions/preload-tox-cache/action.yml | 4 ++-- .github/workflows/ci.yml | 13 ++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/actions/preload-tox-cache/action.yml b/.github/actions/preload-tox-cache/action.yml index f409d85..0275087 100644 --- a/.github/actions/preload-tox-cache/action.yml +++ b/.github/actions/preload-tox-cache/action.yml @@ -9,9 +9,9 @@ runs: steps: - uses: actions/cache@v3 with: - key: tox-${{ inputs.python-version }}-${{ hashFiles('tox.ini') }} + key: tox-${{ hashFiles('tox.ini') }}-${{ inputs.python-version }} restore-keys: | - tox-${{ inputs.python-version }} + tox- path: | .tox/ ~/.cache/pip diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5159353..6965063 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,10 +28,7 @@ jobs: magisk-key: ${{ steps.get-magisk-cache.outputs.magisk-key }} magisk-url: ${{ steps.load-db.outputs.magisk-url }} hit-img: ${{ steps.get-img-cache.outputs.img-hit }} - hit-tox: | - ${{ contains(fromJSON(steps.get-tox-cache.outputs.tox-hit).actions_caches.*.key, format('tox-py39-{0}', steps.get-tox-cache.outputs.tox-hash)) - && contains(fromJSON(steps.get-tox-cache.outputs.tox-hit).actions_caches.*.key, format('tox-py310-{0}', steps.get-tox-cache.outputs.tox-hash)) - && contains(fromJSON(steps.get-tox-cache.outputs.tox-hit).actions_caches.*.key, format('tox-py311-{0}', steps.get-tox-cache.outputs.tox-hash)) }} + hit-tox: ${{ steps.get-tox-cache.outputs.tox-hit }} steps: - uses: actions/checkout@v3 - uses: awalsh128/cache-apt-pkgs-action@v1 @@ -44,9 +41,8 @@ jobs: --method GET \ -H 'Accept: application/vnd.github+json' \ -H 'X-GitHub-Api-Version: 2022-11-28' \ - -f 'key=tox-py3' \ + -f 'key=tox-${{ hashFiles('tox.ini') }}-py3' \ /repos/${{ github.repository }}/actions/caches)" >> $GITHUB_OUTPUT - echo "tox-hash=${{ hashFiles('tox.ini') }}" >> $GITHUB_OUTPUT - name: Checking for cached device images id: get-img-cache run: | @@ -117,7 +113,10 @@ jobs: runs-on: ubuntu-latest needs: setup timeout-minutes: 5 - if: ${{ ! fromJSON(needs.setup.outputs.hit-tox) }} + # 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.hit-tox).total_count == 0 }} strategy: matrix: python: [py39, py310, py311] From f8ef9987949001824d43aee400e41105e471e780 Mon Sep 17 00:00:00 2001 From: Pascal Roeleven Date: Wed, 1 Mar 2023 16:50:12 +0100 Subject: [PATCH 6/6] Reorder steps --- .github/workflows/ci.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6965063..1c66043 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,6 +52,18 @@ jobs: -H 'X-GitHub-Api-Version: 2022-11-28' \ -f 'key=img-${{ hashFiles(env.test-db-path) }}-' \ /repos/${{ github.repository }}/actions/caches)" >> $GITHUB_OUTPUT + - 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=${{ env.magisk-key }}' \ + /repos/${{ github.repository }}/actions/caches)" >> $GITHUB_OUTPUT - name: Loading device test database id: load-db shell: python @@ -66,18 +78,6 @@ jobs: f.write(f"device-db={db['device']}" + '\n') f.write(f"device-list={[i for i in db['device']]}" + '\n') f.write(f"magisk-url={db['magisk']['url']}" + '\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=${{ env.magisk-key }}' \ - /repos/${{ github.repository }}/actions/caches)" >> $GITHUB_OUTPUT - uses: ./.github/actions/preload-magisk-cache if: ${{ fromJSON(steps.get-magisk-cache.outputs.magisk-hit).total_count == 0 }} with: