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:
|
2021-05-14 20:12:34 +02:00
|
|
|
credentials:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
outputs:
|
|
|
|
ghcr: ${{ steps.ghcr.outcome == 'success' }}
|
|
|
|
docker-hub: ${{ steps.docker-hub.outcome == 'success' }}
|
|
|
|
steps:
|
|
|
|
- name: Docker Hub
|
|
|
|
id: docker-hub
|
|
|
|
run: if [ ${{ secrets.DOCKER_HUB_USERNAME == null || secrets.DOCKER_HUB_TOKEN == null }} = true ]; then exit 1; fi
|
|
|
|
continue-on-error: true
|
|
|
|
- name: GitHub Container Registry
|
|
|
|
id: ghcr
|
|
|
|
run: if [ ${{ secrets.GHCR_USERNAME == null || secrets.GHCR_TOKEN == null }} = true ]; then exit 1; fi
|
|
|
|
continue-on-error: true
|
2021-05-14 20:12:34 +02:00
|
|
|
architectures:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
outputs:
|
|
|
|
json: ${{ steps.import.outputs.json }}
|
|
|
|
steps:
|
|
|
|
- name: Checkout
|
|
|
|
uses: actions/checkout@v2
|
|
|
|
- name: Import from architectures.yml
|
|
|
|
id: import
|
|
|
|
shell: python
|
|
|
|
run: |
|
|
|
|
import yaml, json
|
|
|
|
with open('architectures.yml', 'r') as file:
|
|
|
|
architectures = yaml.safe_load(file)
|
|
|
|
print('::set-output name=json::' + json.dumps(architectures))
|
2021-05-14 20:12:34 +02:00
|
|
|
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}
|
2021-05-14 20:12:34 +02:00
|
|
|
candidates:
|
2021-05-14 20:12:34 +02:00
|
|
|
needs:
|
2021-05-14 20:12:34 +02:00
|
|
|
- credentials
|
2021-05-14 20:12:34 +02:00
|
|
|
- architectures
|
2021-05-14 20:12:34 +02:00
|
|
|
- tags
|
2021-05-14 20:12:34 +02:00
|
|
|
if: ${{ !startsWith(github.ref, 'refs/tags') }}
|
2020-12-03 11:34:06 +01:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
strategy:
|
2021-05-14 20:12:34 +02:00
|
|
|
max-parallel: 1 # takes advantage of caching between jobs
|
2021-05-14 20:12:34 +02:00
|
|
|
matrix:
|
|
|
|
architecture: ${{ fromJSON(needs.architectures.outputs.json) }}
|
2020-12-03 11:34:06 +01:00
|
|
|
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: Login to Docker Hub
|
|
|
|
id: docker-hub-login
|
2021-05-14 20:12:34 +02:00
|
|
|
if: ${{ needs.credentials.outputs.docker-hub == 'true' }}
|
2021-05-14 20:12:34 +02:00
|
|
|
uses: docker/login-action@v1
|
|
|
|
with:
|
|
|
|
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
|
|
|
password: ${{ secrets.DOCKER_HUB_TOKEN }}
|
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
|
2021-05-14 20:12:34 +02:00
|
|
|
if: ${{ needs.credentials.outputs.ghcr == 'true' }}
|
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 }}
|
2021-05-19 10:47:36 +02:00
|
|
|
- name: Define namespaces
|
|
|
|
id: namespaces
|
|
|
|
env:
|
|
|
|
DOCKER_HUB: ${{ secrets.DOCKER_HUB_NAMESPACE || github.repository_owner }}
|
|
|
|
GHCR: ${{ github.repository_owner }}
|
|
|
|
run: |
|
|
|
|
echo ::set-output name=docker-hub::${DOCKER_HUB}
|
|
|
|
echo ::set-output name=ghcr::${GHCR}
|
2021-05-14 20:12:34 +02:00
|
|
|
- name: Define repository
|
|
|
|
id: repository
|
|
|
|
run: echo ::set-output name=name::zmk-${{ matrix.target }}-${{ matrix.architecture }}
|
2020-12-03 11:34:06 +01:00
|
|
|
- name: Set up QEMU
|
|
|
|
uses: docker/setup-qemu-action@v1
|
|
|
|
- name: Set up Docker Buildx
|
|
|
|
uses: docker/setup-buildx-action@v1
|
|
|
|
- name: Build and push (candidate)
|
|
|
|
id: build-push
|
|
|
|
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-19 10:47:36 +02:00
|
|
|
docker.io/${{ steps.namespaces.outputs.docker-hub }}/${{ steps.repository.outputs.name }}:${{ needs.tags.outputs.candidate }}
|
|
|
|
cache-from: type=registry,ref=docker.io/${{ steps.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', steps.namespaces.outputs.docker-hub, env.cache-repository-name, 'dev') || null }}
|
2021-05-11 23:03:46 +02:00
|
|
|
push: ${{ steps.docker-hub-login.outcome == 'success' }}
|
2021-05-14 20:12:34 +02:00
|
|
|
releases:
|
|
|
|
needs:
|
|
|
|
- credentials
|
|
|
|
- architectures
|
|
|
|
- tags
|
|
|
|
if: ${{ github.ref == format('refs/tags/{0}', needs.tags.outputs.release-trigger) }}
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
strategy:
|
|
|
|
matrix:
|
|
|
|
architecture: ${{ fromJSON(needs.architectures.outputs.json) }}
|
|
|
|
target:
|
|
|
|
- build
|
|
|
|
- dev
|
|
|
|
steps:
|
|
|
|
- name: Login to GitHub Container Registry
|
|
|
|
id: ghcr-login
|
|
|
|
uses: docker/login-action@v1
|
|
|
|
with:
|
|
|
|
registry: ghcr.io
|
|
|
|
username: ${{ secrets.GHCR_USERNAME }}
|
|
|
|
password: ${{ secrets.GHCR_TOKEN }}
|
|
|
|
- name: Login to Docker Hub
|
|
|
|
id: docker-hub-login
|
|
|
|
uses: docker/login-action@v1
|
|
|
|
with:
|
|
|
|
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
|
|
|
password: ${{ secrets.DOCKER_HUB_TOKEN }}
|
2021-05-19 10:47:36 +02:00
|
|
|
- name: Define namespaces
|
|
|
|
id: namespaces
|
|
|
|
env:
|
|
|
|
DOCKER_HUB: ${{ secrets.DOCKER_HUB_NAMESPACE || github.repository_owner }}
|
|
|
|
GHCR: ${{ github.repository_owner }}
|
|
|
|
run: |
|
|
|
|
echo ::set-output name=docker-hub::${DOCKER_HUB}
|
|
|
|
echo ::set-output name=ghcr::${GHCR}
|
2021-05-14 20:12:34 +02:00
|
|
|
- name: Repository name
|
|
|
|
id: repository
|
|
|
|
run: echo ::set-output name=name::zmk-${{ matrix.target }}-${{ matrix.architecture }}
|
2021-05-09 16:59:20 +02:00
|
|
|
- name: Release (pull candidate, tag, push)
|
2020-12-03 11:34:06 +01:00
|
|
|
run: |
|
2021-05-19 10:47:36 +02:00
|
|
|
docker pull docker.io/${{ steps.namespaces.outputs.docker-hub }}/${{ steps.repository.outputs.name }}:${{ needs.tags.outputs.candidate }}
|
|
|
|
docker tag docker.io/${{ steps.namespaces.outputs.docker-hub }}/${{ steps.repository.outputs.name }}:${{ needs.tags.outputs.candidate }} docker.io/${{ steps.namespaces.outputs.docker-hub }}/${{ steps.repository.outputs.name }}:${{ needs.tags.outputs.versions }}
|
|
|
|
docker tag docker.io/${{ steps.namespaces.outputs.docker-hub }}/${{ steps.repository.outputs.name }}:${{ needs.tags.outputs.candidate }} docker.io/${{ steps.namespaces.outputs.docker-hub }}/${{ steps.repository.outputs.name }}:${{ needs.tags.outputs.latest }}
|
|
|
|
docker tag docker.io/${{ steps.namespaces.outputs.docker-hub }}/${{ steps.repository.outputs.name }}:${{ needs.tags.outputs.candidate }} ghcr.io/${{ steps.namespaces.outputs.ghcr }}/${{ steps.repository.outputs.name }}:${{ needs.tags.outputs.candidate }}
|
|
|
|
docker tag docker.io/${{ steps.namespaces.outputs.docker-hub }}/${{ steps.repository.outputs.name }}:${{ needs.tags.outputs.candidate }} ghcr.io/${{ steps.namespaces.outputs.ghcr }}/${{ steps.repository.outputs.name }}:${{ needs.tags.outputs.versions }}
|
|
|
|
docker tag docker.io/${{ steps.namespaces.outputs.docker-hub }}/${{ steps.repository.outputs.name }}:${{ needs.tags.outputs.candidate }} ghcr.io/${{ steps.namespaces.outputs.ghcr }}/${{ steps.repository.outputs.name }}:${{ needs.tags.outputs.latest }}
|
|
|
|
docker push docker.io/${{ steps.namespaces.outputs.docker-hub }}/${{ steps.repository.outputs.name }}:${{ needs.tags.outputs.candidate }}
|
|
|
|
docker push docker.io/${{ steps.namespaces.outputs.docker-hub }}/${{ steps.repository.outputs.name }}:${{ needs.tags.outputs.versions }}
|
|
|
|
docker push docker.io/${{ steps.namespaces.outputs.docker-hub }}/${{ steps.repository.outputs.name }}:${{ needs.tags.outputs.latest }}
|
|
|
|
docker push ghcr.io/${{ steps.namespaces.outputs.ghcr }}/${{ steps.repository.outputs.name }}:${{ needs.tags.outputs.candidate }}
|
|
|
|
docker push ghcr.io/${{ steps.namespaces.outputs.ghcr }}/${{ steps.repository.outputs.name }}:${{ needs.tags.outputs.versions }}
|
|
|
|
docker push ghcr.io/${{ steps.namespaces.outputs.ghcr }}/${{ steps.repository.outputs.name }}:${{ needs.tags.outputs.latest }}
|
2021-05-14 20:12:34 +02:00
|
|
|
git-tag:
|
2021-05-14 20:12:34 +02:00
|
|
|
needs:
|
2021-05-14 20:12:34 +02:00
|
|
|
- tags
|
2021-05-14 20:12:34 +02:00
|
|
|
- releases
|
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: Checkout
|
|
|
|
uses: actions/checkout@v2
|
2021-05-14 20:12:34 +02:00
|
|
|
if: ${{ github.ref == format('refs/tags/{0}', needs.tags.outputs.release-trigger) }}
|
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}', needs.tags.outputs.release-trigger) }}
|
2020-12-03 11:34:06 +01:00
|
|
|
env:
|
2021-05-14 20:12:34 +02:00
|
|
|
TAG: ${{ needs.tags.outputs.major-minor }}
|
2020-12-03 11:34:06 +01:00
|
|
|
run: |
|
|
|
|
git tag ${TAG}
|
|
|
|
git push -f origin ${TAG}
|