Skip to content

Commit

Permalink
feat: add no-cache support
Browse files Browse the repository at this point in the history
`no-cache` rebuilds everything from scratch.  This is critical for integrating security patches and bug fixes as soon as possible.
  • Loading branch information
innovaker committed Jun 10, 2021
1 parent 45ab050 commit e8528af
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions .github/workflows/containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Containers
env:
zephyr-version: 2.4.0
zephyr-sdk-version: 0.11.4
no-cache: ${{ github.event_name == 'workflow_dispatch' }}
run-unit-tests: ${{ secrets.RUN_UNIT_TESTS != null }}
docker-hub-credentials: ${{ secrets.DOCKER_HUB_USERNAME != null && secrets.DOCKER_HUB_TOKEN != null }}
ghcr-credentials: ${{ secrets.GHCR_USERNAME != null && secrets.GHCR_TOKEN != null }}
Expand Down Expand Up @@ -74,9 +75,20 @@ jobs:
echo ::set-output name=major-minor-branch::${MAJOR_MINOR_BRANCH}
echo ::set-output name=latest::${LATEST}
echo ::set-output name=release-trigger::${RELEASE_TRIGGER}
no-cache-guard:
if: ${{ !startsWith(github.ref, 'refs/tags') }}
runs-on: ubuntu-latest
steps:
- name: Guard against missing credentials
run: |
if [ "${{ env.no-cache == 'true' && env.docker-hub-credentials != 'true' }}" = "true" ]; then
echo "Fresh (no-cache) builds must have Docker Hub credentials to avoid a mismatch between the different types of caches."
exit 1
fi
dev-generic:
needs:
- tags
- no-cache-guard
if: ${{ !startsWith(github.ref, 'refs/tags') }}
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -124,7 +136,7 @@ jobs:
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' }}
run: echo ::set-output name=value::${{ steps.cache.outputs.cache-hit != 'true' || env.no-cache == 'true' }}
- name: Set up QEMU
if: ${{ steps.should-rebuild.outputs.value == 'true' }}
uses: docker/setup-qemu-action@v1
Expand All @@ -138,6 +150,7 @@ jobs:
target: dev-generic
build-args: |
ZEPHYR_VERSION=${{ env.zephyr-version }}
no-cache: ${{ env.no-cache == 'true' }}
cache-from: |
type=registry,ref=${{ steps.paths.outputs.branch }}
${{ (steps.paths.outputs.base != '') && format('type=registry,ref={0}', steps.paths.outputs.base) || '' }}
Expand Down Expand Up @@ -166,6 +179,7 @@ jobs:
needs:
- architectures
- tags
- no-cache-guard
- dev-generic
if: ${{ !startsWith(github.ref, 'refs/tags') }}
runs-on: ubuntu-latest
Expand Down Expand Up @@ -288,12 +302,12 @@ jobs:
${{ steps.paths.outputs.build-branch }}
cache-from: |
type=local,src=${{ steps.paths.outputs.dev-generic }}
type=registry,ref=${{ steps.paths.outputs.build-candidate }}
type=registry,ref=${{ steps.paths.outputs.build-branch }}
${{ (steps.paths.outputs.build-base != '') && format('type=registry,ref={0}', steps.paths.outputs.build-base) || '' }}
type=registry,ref=${{ steps.paths.outputs.build-major-minor-branch }}
type=registry,ref=${{ steps.paths.outputs.build-branch-upstream }}
type=registry,ref=${{ steps.paths.outputs.build-major-minor-branch-upstream }}
${{ (env.no-cache == 'false') && format('type=registry,ref={0}', steps.paths.outputs.build-candidate) }}
${{ (env.no-cache == 'false') && format('type=registry,ref={0}', steps.paths.outputs.build-branch) }}
${{ (env.no-cache == 'false') && (steps.paths.outputs.build-base != '') && format('type=registry,ref={0}', steps.paths.outputs.build-base) || '' }}
${{ (env.no-cache == 'false') && format('type=registry,ref={0}', steps.paths.outputs.build-major-minor-branch) }}
${{ (env.no-cache == 'false') && format('type=registry,ref={0}', steps.paths.outputs.build-branch-upstream) }}
${{ (env.no-cache == 'false') && format('type=registry,ref={0}', steps.paths.outputs.build-major-minor-branch-upstream) }}
cache-to: type=inline
load: true
- name: Build and load 'dev' candidate image
Expand All @@ -310,12 +324,12 @@ jobs:
cache-from: |
type=registry,ref=${{ steps.paths.outputs.build-candidate }}
type=local,src=${{ steps.paths.outputs.dev-generic }}
type=registry,ref=${{ steps.paths.outputs.dev-candidate }}
type=registry,ref=${{ steps.paths.outputs.dev-branch }}
${{ (steps.paths.outputs.dev-base != '') && format('type=registry,ref={0}', steps.paths.outputs.dev-base) || '' }}
type=registry,ref=${{ steps.paths.outputs.dev-major-minor-branch }}
type=registry,ref=${{ steps.paths.outputs.dev-branch-upstream }}
type=registry,ref=${{ steps.paths.outputs.dev-major-minor-branch-upstream }}
${{ (env.no-cache == 'false') && format('type=registry,ref={0}', steps.paths.outputs.dev-candidate) }}
${{ (env.no-cache == 'false') && format('type=registry,ref={0}', steps.paths.outputs.dev-branch) }}
${{ (env.no-cache == 'false') && (steps.paths.outputs.dev-base != '') && format('type=registry,ref={0}', steps.paths.outputs.dev-base) || '' }}
${{ (env.no-cache == 'false') && format('type=registry,ref={0}', steps.paths.outputs.dev-major-minor-branch) }}
${{ (env.no-cache == 'false') && format('type=registry,ref={0}', steps.paths.outputs.dev-branch-upstream) }}
${{ (env.no-cache == 'false') && format('type=registry,ref={0}', steps.paths.outputs.dev-major-minor-branch-upstream) }}
cache-to: type=inline
load: true
- name: Checkout ZMK
Expand Down

0 comments on commit e8528af

Please sign in to comment.