diff --git a/.github/workflows/containers.yml b/.github/workflows/containers.yml index 2ea71d8..499a1ef 100644 --- a/.github/workflows/containers.yml +++ b/.github/workflows/containers.yml @@ -49,11 +49,41 @@ jobs: with open('architectures.yml', 'r') as file: architectures = yaml.safe_load(file) print('::set-output name=json::' + json.dumps(architectures)) + tags: + runs-on: ubuntu-latest + outputs: + candidate: ${{ steps.definitions.outputs.candidate }} + versions: ${{ steps.definitions.outputs.versions }} + major-minor: ${{ steps.definitions.outputs.major-minor }} + latest: ${{ steps.definitions.outputs.latest }} + release-trigger: ${{ steps.definitions.outputs.release-trigger }} + steps: + - name: Definitions + id: definitions + env: + SHA: ${{ github.sha }} + ZEPHYR_VERSION: ${{ env.zephyr-version }} + ZEPHYR_SDK_VERSION: ${{ env.zephyr-sdk-version }} + run: | + CANDIDATE=${SHA} + VERSIONS=${ZEPHYR_VERSION}-${ZEPHYR_SDK_VERSION} + MAJOR=$(echo ${ZEPHYR_VERSION} | cut -d'.' -f 1) + MINOR=$(echo ${ZEPHYR_VERSION} | cut -d'.' -f 2) + MAJOR_MINOR=${MAJOR}.${MINOR} + LATEST=${MAJOR_MINOR} + RELEASE_TRIGGER=${ZEPHYR_VERSION}-${ZEPHYR_SDK_VERSION} + + echo ::set-output name=candidate::${CANDIDATE} + echo ::set-output name=versions::${VERSIONS} + echo ::set-output name=major-minor::${MAJOR_MINOR} + echo ::set-output name=latest::${LATEST} + echo ::set-output name=release-trigger::${RELEASE_TRIGGER} docker: needs: - namespaces - credentials - architectures + - tags runs-on: ubuntu-latest strategy: max-parallel: 1 # takes advantage of caching between jobs @@ -83,23 +113,6 @@ jobs: run: | REPOSITORY_NAME=zmk-${{ matrix.target }}-${{ matrix.architecture }} echo ::set-output name=repository-name::${REPOSITORY_NAME} - - CANDIDATE_TAG=${{ github.sha }} - echo ::set-output name=candidate-tag::${CANDIDATE_TAG} - - VERSIONS_TAG=${{ env.zephyr-version }}-${{ env.zephyr-sdk-version }} - echo ::set-output name=versions-tag::${VERSIONS_TAG} - - MAJOR=$(echo ${{ env.zephyr-version }} | cut -d'.' -f 1) - MINOR=$(echo ${{ env.zephyr-version }} | cut -d'.' -f 2) - MAJOR_MINOR=${MAJOR}.${MINOR} - echo ::set-output name=major-minor::${MAJOR_MINOR} - - LATEST_TAG=${MAJOR_MINOR} - echo ::set-output name=latest-tag::${LATEST_TAG} - - RELEASE_TRIGGER_TAG=${{ env.zephyr-version }}-${{ env.zephyr-sdk-version }} - echo ::set-output name=release-trigger-tag::${RELEASE_TAG} - name: Set up QEMU if: ${{ !startsWith(github.ref, 'refs/tags') }} uses: docker/setup-qemu-action@v1 @@ -120,12 +133,12 @@ jobs: org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} org.opencontainers.image.revision=${{ github.sha }} tags: | - docker.io/${{ needs.namespaces.outputs.docker-hub }}/${{ steps.vars.outputs.repository-name }}:${{ steps.vars.outputs.candidate-tag }} + docker.io/${{ needs.namespaces.outputs.docker-hub }}/${{ steps.vars.outputs.repository-name }}:${{ needs.tags.outputs.candidate }} cache-from: type=registry,ref=docker.io/${{ needs.namespaces.outputs.docker-hub }}/${{ 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', needs.namespaces.outputs.docker-hub, env.cache-repository-name, 'dev') || null }} push: ${{ steps.docker-hub-login.outcome == 'success' }} - name: Release (pull candidate, tag, push) - if: ${{ github.ref == format('refs/tags/{0}', steps.vars.outputs.release-trigger-tag) }} + if: ${{ github.ref == format('refs/tags/{0}', needs.tags.outputs.release-trigger) }} run: | if [ "${{ steps.docker-hub-login.outcome }}" != "success" ]; then echo "Docker Hub must be authenticated to perform a release!" @@ -135,41 +148,32 @@ jobs: echo "GitHub Container Registry must be authenticated to perform a release!" exit 1 fi - docker pull docker.io/${{ needs.namespaces.outputs.docker-hub }}/${{ steps.vars.outputs.repository-name }}:${{ steps.vars.outputs.candidate-tag }} - docker tag docker.io/${{ needs.namespaces.outputs.docker-hub }}/${{ steps.vars.outputs.repository-name }}:${{ steps.vars.outputs.candidate-tag }} docker.io/${{ needs.namespaces.outputs.docker-hub }}/${{ steps.vars.outputs.repository-name }}:${{ steps.vars.outputs.versions-tag }} - docker tag docker.io/${{ needs.namespaces.outputs.docker-hub }}/${{ steps.vars.outputs.repository-name }}:${{ steps.vars.outputs.candidate-tag }} docker.io/${{ needs.namespaces.outputs.docker-hub }}/${{ steps.vars.outputs.repository-name }}:${{ steps.vars.outputs.latest-tag }} - docker tag docker.io/${{ needs.namespaces.outputs.docker-hub }}/${{ steps.vars.outputs.repository-name }}:${{ steps.vars.outputs.candidate-tag }} ghcr.io/${{ needs.namespaces.outputs.ghcr }}/${{ steps.vars.outputs.repository-name }}:${{ steps.vars.outputs.candidate-tag }} - docker tag docker.io/${{ needs.namespaces.outputs.docker-hub }}/${{ steps.vars.outputs.repository-name }}:${{ steps.vars.outputs.candidate-tag }} ghcr.io/${{ needs.namespaces.outputs.ghcr }}/${{ steps.vars.outputs.repository-name }}:${{ steps.vars.outputs.versions-tag }} - docker tag docker.io/${{ needs.namespaces.outputs.docker-hub }}/${{ steps.vars.outputs.repository-name }}:${{ steps.vars.outputs.candidate-tag }} ghcr.io/${{ needs.namespaces.outputs.ghcr }}/${{ steps.vars.outputs.repository-name }}:${{ steps.vars.outputs.latest-tag }} - docker push docker.io/${{ needs.namespaces.outputs.docker-hub }}/${{ steps.vars.outputs.repository-name }}:${{ steps.vars.outputs.candidate-tag }} - docker push docker.io/${{ needs.namespaces.outputs.docker-hub }}/${{ steps.vars.outputs.repository-name }}:${{ steps.vars.outputs.versions-tag }} - docker push docker.io/${{ needs.namespaces.outputs.docker-hub }}/${{ steps.vars.outputs.repository-name }}:${{ steps.vars.outputs.latest-tag }} - docker push ghcr.io/${{ needs.namespaces.outputs.ghcr }}/${{ steps.vars.outputs.repository-name }}:${{ steps.vars.outputs.candidate-tag }} - docker push ghcr.io/${{ needs.namespaces.outputs.ghcr }}/${{ steps.vars.outputs.repository-name }}:${{ steps.vars.outputs.versions-tag }} - docker push ghcr.io/${{ needs.namespaces.outputs.ghcr }}/${{ steps.vars.outputs.repository-name }}:${{ steps.vars.outputs.latest-tag }} + docker pull docker.io/${{ needs.namespaces.outputs.docker-hub }}/${{ steps.vars.outputs.repository-name }}:${{ needs.tags.outputs.candidate }} + docker tag docker.io/${{ needs.namespaces.outputs.docker-hub }}/${{ steps.vars.outputs.repository-name }}:${{ needs.tags.outputs.candidate }} docker.io/${{ needs.namespaces.outputs.docker-hub }}/${{ steps.vars.outputs.repository-name }}:${{ needs.tags.outputs.versions }} + docker tag docker.io/${{ needs.namespaces.outputs.docker-hub }}/${{ steps.vars.outputs.repository-name }}:${{ needs.tags.outputs.candidate }} docker.io/${{ needs.namespaces.outputs.docker-hub }}/${{ steps.vars.outputs.repository-name }}:${{ needs.tags.outputs.latest }} + docker tag docker.io/${{ needs.namespaces.outputs.docker-hub }}/${{ steps.vars.outputs.repository-name }}:${{ needs.tags.outputs.candidate }} ghcr.io/${{ needs.namespaces.outputs.ghcr }}/${{ steps.vars.outputs.repository-name }}:${{ needs.tags.outputs.candidate }} + docker tag docker.io/${{ needs.namespaces.outputs.docker-hub }}/${{ steps.vars.outputs.repository-name }}:${{ needs.tags.outputs.candidate }} ghcr.io/${{ needs.namespaces.outputs.ghcr }}/${{ steps.vars.outputs.repository-name }}:${{ needs.tags.outputs.versions }} + docker tag docker.io/${{ needs.namespaces.outputs.docker-hub }}/${{ steps.vars.outputs.repository-name }}:${{ needs.tags.outputs.candidate }} ghcr.io/${{ needs.namespaces.outputs.ghcr }}/${{ steps.vars.outputs.repository-name }}:${{ needs.tags.outputs.latest }} + docker push docker.io/${{ needs.namespaces.outputs.docker-hub }}/${{ steps.vars.outputs.repository-name }}:${{ needs.tags.outputs.candidate }} + docker push docker.io/${{ needs.namespaces.outputs.docker-hub }}/${{ steps.vars.outputs.repository-name }}:${{ needs.tags.outputs.versions }} + docker push docker.io/${{ needs.namespaces.outputs.docker-hub }}/${{ steps.vars.outputs.repository-name }}:${{ needs.tags.outputs.latest }} + docker push ghcr.io/${{ needs.namespaces.outputs.ghcr }}/${{ steps.vars.outputs.repository-name }}:${{ needs.tags.outputs.candidate }} + docker push ghcr.io/${{ needs.namespaces.outputs.ghcr }}/${{ steps.vars.outputs.repository-name }}:${{ needs.tags.outputs.versions }} + docker push ghcr.io/${{ needs.namespaces.outputs.ghcr }}/${{ steps.vars.outputs.repository-name }}:${{ needs.tags.outputs.latest }} git-tag: needs: + - tags - docker if: ${{ startsWith(github.ref, 'refs/tags') }} runs-on: ubuntu-latest steps: - - name: Prepare variables - id: vars - run: | - MAJOR=$(echo ${{ env.zephyr-version }} | cut -d'.' -f 1) - MINOR=$(echo ${{ env.zephyr-version }} | cut -d'.' -f 2) - MAJOR_MINOR=${MAJOR}.${MINOR} - echo ::set-output name=major-minor::${MAJOR_MINOR} - - RELEASE_TRIGGER_TAG=${{ env.zephyr-version }}-${{ env.zephyr-sdk-version }} - echo ::set-output name=release-trigger-tag::${RELEASE_TAG} - name: Checkout uses: actions/checkout@v2 - if: ${{ github.ref == format('refs/tags/{0}', steps.vars.outputs.release-trigger-tag) }} + if: ${{ github.ref == format('refs/tags/{0}', needs.tags.outputs.release-trigger) }} - name: Tag - if: ${{ github.ref == format('refs/tags/{0}', steps.vars.outputs.release-trigger-tag) }} + if: ${{ github.ref == format('refs/tags/{0}', needs.tags.outputs.release-trigger) }} env: - TAG: ${{ steps.vars.outputs.major-minor }} + TAG: ${{ needs.tags.outputs.major-minor }} run: | git tag ${TAG} git push -f origin ${TAG}