Merge pull request #79 from pascallj/cache_keys

Make cache pre-checks more robust
This commit is contained in:
Andrew Gunnerson
2023-03-06 12:43:55 -05:00
committed by GitHub
2 changed files with 29 additions and 41 deletions
@@ -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
+27 -39
View File
@@ -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]