From 48d65ae8d18a669a69192f8bb499d8e35a379d79 Mon Sep 17 00:00:00 2001 From: innovaker <66737976+innovaker@users.noreply.github.com> Date: Wed, 19 May 2021 11:00:07 +0100 Subject: [PATCH 1/3] feat: scope cache by branch Lets each branch manage its own cache. PR: #53 --- .github/workflows/containers.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/containers.yml b/.github/workflows/containers.yml index 0923f796..264f12d5 100644 --- a/.github/workflows/containers.yml +++ b/.github/workflows/containers.yml @@ -38,6 +38,7 @@ jobs: tags: runs-on: ubuntu-latest outputs: + branch: ${{ steps.definitions.outputs.branch }} candidate: ${{ steps.definitions.outputs.candidate }} versions: ${{ steps.definitions.outputs.versions }} major-minor: ${{ steps.definitions.outputs.major-minor }} @@ -51,6 +52,8 @@ jobs: ZEPHYR_VERSION: ${{ env.zephyr-version }} ZEPHYR_SDK_VERSION: ${{ env.zephyr-sdk-version }} run: | + BRANCH=${GITHUB_REF#refs/heads/} + BRANCH=${BRANCH//[^A-Za-z0-9_.-]/_} # Substitutes invalid Docker tag characters CANDIDATE=${SHA} VERSIONS=${ZEPHYR_VERSION}-${ZEPHYR_SDK_VERSION} MAJOR=$(echo ${ZEPHYR_VERSION} | cut -d'.' -f 1) @@ -59,6 +62,7 @@ jobs: LATEST=${MAJOR_MINOR} RELEASE_TRIGGER=${ZEPHYR_VERSION}-${ZEPHYR_SDK_VERSION} + echo ::set-output name=branch::${BRANCH} echo ::set-output name=candidate::${CANDIDATE} echo ::set-output name=versions::${VERSIONS} echo ::set-output name=major-minor::${MAJOR_MINOR} @@ -124,8 +128,8 @@ jobs: org.opencontainers.image.revision=${{ github.sha }} tags: | docker.io/${{ env.docker-hub-namespace }}/${{ steps.repository.outputs.name }}:${{ needs.tags.outputs.candidate }} - cache-from: type=registry,ref=docker.io/${{ env.docker-hub-namespace }}/${{ env.cache-repository-name }}:dev - cache-to: ${{ (steps.docker-hub-login.outcome == 'success') && (matrix.target == 'dev') && format('type=registry,ref=docker.io/{0}/{1}:{2},mode=max', env.docker-hub-namespace, env.cache-repository-name, 'dev') || null }} + cache-from: type=registry,ref=docker.io/${{ env.docker-hub-namespace }}/${{ env.cache-repository-name }}:${{ needs.tags.outputs.branch }}-dev + cache-to: ${{ (steps.docker-hub-login.outcome == 'success') && (matrix.target == 'dev') && format('type=registry,ref=docker.io/{0}/{1}:{2}-{3},mode=max', env.docker-hub-namespace, env.cache-repository-name, needs.tags.outputs.branch, 'dev') || null }} load: true - name: Create and run container from candidate image shell: bash From 623339ebc79c40fb33c07e8c14208e5dff59a339 Mon Sep 17 00:00:00 2001 From: innovaker <66737976+innovaker@users.noreply.github.com> Date: Wed, 19 May 2021 11:00:40 +0100 Subject: [PATCH 2/3] refactor: drop `dev` from cache tag `dev` is longer necessary because the branch name was added. PR: #53 --- .github/workflows/containers.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/containers.yml b/.github/workflows/containers.yml index 264f12d5..b16a5bd3 100644 --- a/.github/workflows/containers.yml +++ b/.github/workflows/containers.yml @@ -128,8 +128,8 @@ jobs: org.opencontainers.image.revision=${{ github.sha }} tags: | docker.io/${{ env.docker-hub-namespace }}/${{ steps.repository.outputs.name }}:${{ needs.tags.outputs.candidate }} - cache-from: type=registry,ref=docker.io/${{ env.docker-hub-namespace }}/${{ env.cache-repository-name }}:${{ needs.tags.outputs.branch }}-dev - cache-to: ${{ (steps.docker-hub-login.outcome == 'success') && (matrix.target == 'dev') && format('type=registry,ref=docker.io/{0}/{1}:{2}-{3},mode=max', env.docker-hub-namespace, env.cache-repository-name, needs.tags.outputs.branch, 'dev') || null }} + cache-from: type=registry,ref=docker.io/${{ env.docker-hub-namespace }}/${{ env.cache-repository-name }}:${{ needs.tags.outputs.branch }} + cache-to: ${{ (steps.docker-hub-login.outcome == 'success') && (matrix.target == 'dev') && format('type=registry,ref=docker.io/{0}/{1}:{2},mode=max', env.docker-hub-namespace, env.cache-repository-name, needs.tags.outputs.branch) || null }} load: true - name: Create and run container from candidate image shell: bash From b0cbb6aea162f41a6784ebdc5d1408f4bd1a834c Mon Sep 17 00:00:00 2001 From: innovaker <66737976+innovaker@users.noreply.github.com> Date: Sun, 16 May 2021 15:48:35 +0100 Subject: [PATCH 3/3] feat: restrict workflow concurrency per branch Protects the cache from competing workflow runs on a per branch basis. PR: #53 --- .github/workflows/containers.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/containers.yml b/.github/workflows/containers.yml index b16a5bd3..b2ef9866 100644 --- a/.github/workflows/containers.yml +++ b/.github/workflows/containers.yml @@ -17,8 +17,8 @@ on: pull_request: workflow_dispatch: -concurrency: ${{ github.workflow }} - +concurrency: ${{ github.ref }}/${{ github.workflow }} + jobs: architectures: runs-on: ubuntu-latest