refactor: always rebuild dev-generic

The `dev-generic` job was originally optimized to only build once per workflow run.  Subsequent re-runs skipped the build steps.  This unfortunately made it difficult to analyze dev-generic cache problems after merging.  This change removes this optimization.

The cache key has a timestamp suffix so that the cache is always built anew.  This provides more integrity, traceability and flexibility at the cost of increased cache turnover across the repository.

PR: zmkfirmware/zmk-docker#74
This commit is contained in:
innovaker 2021-06-12 21:52:10 +01:00
parent 406388461c
commit 67075dfb7b

View File

@ -88,6 +88,7 @@ jobs:
echo ::set-output name=major-minor-branch::${MAJOR_MINOR_BRANCH}
dev-generic:
needs:
- timestamp
- tags
if: ${{ !startsWith(github.ref, 'refs/tags') }}
runs-on: ubuntu-latest
@ -133,18 +134,14 @@ jobs:
cache-name: dev-generic
with:
path: ${{ steps.paths.outputs.local }}
key: ${{ runner.os }}/${{ env.cache-name }}/${{ github.run_id }}
- name: Rebuild cache?
id: should-rebuild
run: echo ::set-output name=value::${{ steps.cache.outputs.cache-hit != 'true' || env.no-cache == 'true' }}
key: ${{ runner.os }}/${{ env.cache-name }}/${{ github.run_id }}/${{ needs.timestamp.outputs.timestamp }}
restore-keys: |
${{ runner.os }}/${{ env.cache-name }}/${{ github.run_id }}
- name: Set up QEMU
if: ${{ steps.should-rebuild.outputs.value == 'true' }}
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
if: ${{ steps.should-rebuild.outputs.value == 'true' }}
uses: docker/setup-buildx-action@v1
- name: Build to local cache
if: ${{ steps.should-rebuild.outputs.value == 'true' }}
uses: docker/build-push-action@v2
with:
target: dev-generic
@ -152,6 +149,7 @@ jobs:
ZEPHYR_VERSION=${{ env.zephyr-version }}
no-cache: ${{ env.no-cache == 'true' }}
cache-from: |
type=local,src=${{ steps.paths.outputs.local }}
type=registry,ref=${{ steps.paths.outputs.branch }}
${{ (steps.paths.outputs.base != '') && format('type=registry,ref={0}', steps.paths.outputs.base) || '' }}
type=registry,ref=${{ steps.paths.outputs.major-minor-branch }}
@ -159,7 +157,7 @@ jobs:
type=registry,ref=${{ steps.paths.outputs.major-minor-branch-upstream }}
cache-to: type=local,dest=${{ steps.paths.outputs.local-new }},mode=max
- name: Push to registry cache
if: ${{ (steps.should-rebuild.outputs.value == 'true') && (env.docker-hub-credentials == 'true') }}
if: ${{ env.docker-hub-credentials == 'true' }}
uses: docker/build-push-action@v2
with:
target: dev-generic
@ -174,12 +172,12 @@ jobs:
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Switch local cache
if: ${{ steps.should-rebuild.outputs.value == 'true' }}
run: |
rm -rf ${{ steps.paths.outputs.local }}
mv ${{ steps.paths.outputs.local-new }} ${{ steps.paths.outputs.local }}
candidates:
needs:
- timestamp
- architectures
- tags
- dev-generic
@ -286,7 +284,7 @@ jobs:
cache-name: dev-generic
with:
path: ${{ steps.paths.outputs.dev-generic }}
key: ${{ runner.os }}/${{ env.cache-name }}/${{ github.run_id }}
key: ${{ runner.os }}/${{ env.cache-name }}/${{ github.run_id }}/${{ needs.timestamp.outputs.timestamp }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx