2020-12-03 11:34:06 +01:00
|
|
|
name: Containers
|
|
|
|
|
|
|
|
env:
|
2020-12-03 09:44:19 +01:00
|
|
|
zephyr-version: 2.4.0
|
2020-12-03 11:34:06 +01:00
|
|
|
zephyr-sdk-version: 0.11.4
|
2021-05-09 22:43:22 +02:00
|
|
|
cache-repository-name: zmk-docker-cache
|
2020-12-03 11:34:06 +01:00
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
pull_request:
|
|
|
|
workflow_dispatch:
|
|
|
|
|
2021-05-16 17:04:00 +02:00
|
|
|
concurrency: ${{ github.workflow }}
|
|
|
|
|
2020-12-03 11:34:06 +01:00
|
|
|
jobs:
|
|
|
|
docker:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
strategy:
|
2021-05-14 20:12:34 +02:00
|
|
|
max-parallel: 1 # takes advantage of caching between jobs
|
2020-12-03 11:34:06 +01:00
|
|
|
matrix:
|
|
|
|
architecture:
|
|
|
|
- arm
|
|
|
|
target: # ordered from biggest to smallest to take advantage of the registry cache
|
|
|
|
- dev
|
|
|
|
- build
|
|
|
|
steps:
|
2021-05-14 20:12:34 +02:00
|
|
|
- name: Check for Docker Hub credentials (secrets)
|
|
|
|
id: docker-hub-credentials
|
|
|
|
run: if [ ${{ secrets.DOCKER_HUB_USERNAME == null || secrets.DOCKER_HUB_TOKEN == null }} = true ]; then exit 1; fi
|
|
|
|
continue-on-error: true
|
|
|
|
- name: Login to Docker Hub
|
|
|
|
id: docker-hub-login
|
|
|
|
if: ${{ steps.docker-hub-credentials.outcome == 'success' }}
|
|
|
|
uses: docker/login-action@v1
|
|
|
|
with:
|
|
|
|
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
|
|
|
password: ${{ secrets.DOCKER_HUB_TOKEN }}
|
2021-05-11 23:03:46 +02:00
|
|
|
- name: Check for GitHub Container Registry credentials (secrets)
|
|
|
|
id: ghcr-credentials
|
|
|
|
run: if [ ${{ secrets.GHCR_USERNAME == null || secrets.GHCR_TOKEN == null }} = true ]; then exit 1; fi
|
|
|
|
continue-on-error: true
|
2020-12-03 11:34:06 +01:00
|
|
|
- name: Login to GitHub Container Registry
|
2021-05-11 23:03:46 +02:00
|
|
|
id: ghcr-login
|
|
|
|
if: ${{ steps.ghcr-credentials.outcome == 'success' }}
|
2020-12-03 11:34:06 +01:00
|
|
|
uses: docker/login-action@v1
|
|
|
|
with:
|
|
|
|
registry: ghcr.io
|
|
|
|
username: ${{ secrets.GHCR_USERNAME }}
|
|
|
|
password: ${{ secrets.GHCR_TOKEN }}
|
|
|
|
- name: Prepare variables
|
|
|
|
id: vars
|
2021-05-09 15:57:58 +02:00
|
|
|
env:
|
|
|
|
DOCKER_HUB_NAMESPACE: ${{ secrets.DOCKER_HUB_NAMESPACE || github.repository_owner }}
|
2020-12-03 11:34:06 +01:00
|
|
|
run: |
|
2021-05-09 15:57:58 +02:00
|
|
|
echo ::set-output name=docker-hub-namespace::${DOCKER_HUB_NAMESPACE}
|
|
|
|
|
2021-05-14 20:12:34 +02:00
|
|
|
REPOSITORY_NAME=zmk-${{ matrix.target }}-${{ matrix.architecture }}
|
|
|
|
echo ::set-output name=repository-name::${REPOSITORY_NAME}
|
2020-12-03 11:34:06 +01:00
|
|
|
|
2021-05-14 20:12:34 +02:00
|
|
|
CANDIDATE_TAG=${REPOSITORY_NAME}:${{ github.sha }}
|
2020-12-03 11:34:06 +01:00
|
|
|
echo ::set-output name=candidate-tag::${CANDIDATE_TAG}
|
|
|
|
|
2021-05-14 20:12:34 +02:00
|
|
|
VERSIONS_TAG=${REPOSITORY_NAME}:${{ env.zephyr-version }}-${{ env.zephyr-sdk-version }}
|
2020-12-03 11:34:06 +01:00
|
|
|
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}
|
|
|
|
|
2021-05-14 20:12:34 +02:00
|
|
|
LATEST_TAG=${REPOSITORY_NAME}:${MAJOR_MINOR}
|
2020-12-03 11:34:06 +01:00
|
|
|
echo ::set-output name=latest-tag::${LATEST_TAG}
|
|
|
|
|
2021-05-14 20:12:34 +02:00
|
|
|
RELEASE_TRIGGER_TAG=${{ env.zephyr-version }}-${{ env.zephyr-sdk-version }}
|
|
|
|
echo ::set-output name=release-trigger-tag::${RELEASE_TAG}
|
2020-12-03 11:34:06 +01:00
|
|
|
- name: Set up QEMU
|
|
|
|
if: ${{ !startsWith(github.ref, 'refs/tags') }}
|
|
|
|
uses: docker/setup-qemu-action@v1
|
|
|
|
- name: Set up Docker Buildx
|
|
|
|
if: ${{ !startsWith(github.ref, 'refs/tags') }}
|
|
|
|
uses: docker/setup-buildx-action@v1
|
|
|
|
- name: Build and push (candidate)
|
|
|
|
id: build-push
|
|
|
|
if: ${{ !startsWith(github.ref, 'refs/tags') }}
|
|
|
|
uses: docker/build-push-action@v2
|
|
|
|
with:
|
|
|
|
target: ${{ matrix.target }}
|
|
|
|
build-args: |
|
|
|
|
ZEPHYR_VERSION=${{ env.zephyr-version }}
|
|
|
|
ARCHITECTURE=${{ matrix.architecture }}
|
|
|
|
ZEPHYR_SDK_VERSION=${{ env.zephyr-sdk-version }}
|
2021-05-09 21:50:17 +02:00
|
|
|
labels: |
|
|
|
|
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
|
2021-05-14 20:12:34 +02:00
|
|
|
org.opencontainers.image.revision=${{ github.sha }}
|
2020-12-03 11:34:06 +01:00
|
|
|
tags: |
|
2021-05-09 15:57:58 +02:00
|
|
|
docker.io/${{ steps.vars.outputs.docker-hub-namespace }}/${{ steps.vars.outputs.candidate-tag }}
|
|
|
|
cache-from: type=registry,ref=docker.io/${{ steps.vars.outputs.docker-hub-namespace }}/${{ env.cache-repository-name }}:dev
|
2021-05-14 20:12:34 +02:00
|
|
|
cache-to: ${{ (steps.docker-hub-login.outcome == 'success') && (matrix.target == 'dev') && format('type=registry,ref=docker.io/{0}/{1}:{2},mode=max', steps.vars.outputs.docker-hub-namespace, env.cache-repository-name, 'dev') || null }}
|
2021-05-11 23:03:46 +02:00
|
|
|
push: ${{ steps.docker-hub-login.outcome == 'success' }}
|
2021-05-09 16:59:20 +02:00
|
|
|
- name: Release (pull candidate, tag, push)
|
2021-05-14 20:12:34 +02:00
|
|
|
if: ${{ github.ref == format('refs/tags/{0}', steps.vars.outputs.release-trigger-tag) }}
|
2020-12-03 11:34:06 +01:00
|
|
|
run: |
|
2021-05-11 23:03:46 +02:00
|
|
|
if [ "${{ steps.docker-hub-login.outcome }}" != "success" ]; then
|
|
|
|
echo "Docker Hub must be authenticated to perform a release!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ "${{ steps.ghcr-login.outcome }}" != "success" ]; then
|
|
|
|
echo "GitHub Container Registry must be authenticated to perform a release!"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-05-09 15:57:58 +02:00
|
|
|
docker pull docker.io/${{ steps.vars.outputs.docker-hub-namespace }}/${{ steps.vars.outputs.candidate-tag }}
|
|
|
|
docker tag docker.io/${{ steps.vars.outputs.docker-hub-namespace }}/${{ steps.vars.outputs.candidate-tag }} docker.io/${{ steps.vars.outputs.docker-hub-namespace }}/${{ steps.vars.outputs.versions-tag }}
|
|
|
|
docker tag docker.io/${{ steps.vars.outputs.docker-hub-namespace }}/${{ steps.vars.outputs.candidate-tag }} docker.io/${{ steps.vars.outputs.docker-hub-namespace }}/${{ steps.vars.outputs.latest-tag }}
|
|
|
|
docker tag docker.io/${{ steps.vars.outputs.docker-hub-namespace }}/${{ steps.vars.outputs.candidate-tag }} ghcr.io/${{ github.repository_owner }}/${{ steps.vars.outputs.candidate-tag }}
|
|
|
|
docker tag docker.io/${{ steps.vars.outputs.docker-hub-namespace }}/${{ steps.vars.outputs.candidate-tag }} ghcr.io/${{ github.repository_owner }}/${{ steps.vars.outputs.versions-tag }}
|
|
|
|
docker tag docker.io/${{ steps.vars.outputs.docker-hub-namespace }}/${{ steps.vars.outputs.candidate-tag }} ghcr.io/${{ github.repository_owner }}/${{ steps.vars.outputs.latest-tag }}
|
|
|
|
docker push docker.io/${{ steps.vars.outputs.docker-hub-namespace }}/${{ steps.vars.outputs.candidate-tag }}
|
|
|
|
docker push docker.io/${{ steps.vars.outputs.docker-hub-namespace }}/${{ steps.vars.outputs.versions-tag }}
|
|
|
|
docker push docker.io/${{ steps.vars.outputs.docker-hub-namespace }}/${{ steps.vars.outputs.latest-tag }}
|
2020-12-03 11:34:06 +01:00
|
|
|
docker push ghcr.io/${{ github.repository_owner }}/${{ steps.vars.outputs.candidate-tag }}
|
|
|
|
docker push ghcr.io/${{ github.repository_owner }}/${{ steps.vars.outputs.versions-tag }}
|
|
|
|
docker push ghcr.io/${{ github.repository_owner }}/${{ steps.vars.outputs.latest-tag }}
|
2021-05-14 20:12:34 +02:00
|
|
|
git-tag:
|
2021-05-14 20:12:34 +02:00
|
|
|
needs:
|
|
|
|
- docker
|
2020-12-03 11:34:06 +01:00
|
|
|
if: ${{ startsWith(github.ref, 'refs/tags') }}
|
2021-05-14 20:12:34 +02:00
|
|
|
runs-on: ubuntu-latest
|
2020-12-03 11:34:06 +01:00
|
|
|
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}
|
|
|
|
|
2021-05-14 20:12:34 +02:00
|
|
|
RELEASE_TRIGGER_TAG=${{ env.zephyr-version }}-${{ env.zephyr-sdk-version }}
|
|
|
|
echo ::set-output name=release-trigger-tag::${RELEASE_TAG}
|
2020-12-03 11:34:06 +01:00
|
|
|
- name: Checkout
|
|
|
|
uses: actions/checkout@v2
|
2021-05-14 20:12:34 +02:00
|
|
|
if: ${{ github.ref == format('refs/tags/{0}', steps.vars.outputs.release-trigger-tag) }}
|
2020-12-03 11:34:06 +01:00
|
|
|
- name: Tag
|
2021-05-14 20:12:34 +02:00
|
|
|
if: ${{ github.ref == format('refs/tags/{0}', steps.vars.outputs.release-trigger-tag) }}
|
2020-12-03 11:34:06 +01:00
|
|
|
env:
|
|
|
|
TAG: ${{ steps.vars.outputs.major-minor }}
|
|
|
|
run: |
|
|
|
|
git tag ${TAG}
|
|
|
|
git push -f origin ${TAG}
|