Skip to content

CI

CI #389

Workflow file for this run

name: CI
on:
push:
branches: ["main"]
tags: ["v*"]
pull_request:
branches: ["main"]
schedule:
- cron: "0 12 * * 3"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
############
# Building #
############
build:
strategy:
fail-fast: false
matrix:
os: ["linux"]
# TODO: Return `arm32v6`, `arm32v7` and `s390x` once
# nodejs/docker-node#1973 is resolved:
# https://github.com/nodejs/docker-node/issues/1973
# TODO: Return `ppc64le` once nodejs/docker-node#2107 is resolved:
# https://github.com/nodejs/docker-node/issues/2107
arch:
- amd64
- arm64v8
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # for correct image labeling via `git describe --tags`
- uses: docker/setup-buildx-action@v3
- run: make docker.image no-cache=yes
platform=${{ matrix.os }}/${{ matrix.arch }}
tag=build-${{ github.run_number }}-${{ matrix.os }}-${{ matrix.arch }}
- run: make docker.tar to-file=.cache/image.tar
tags=build-${{ github.run_number }}-${{ matrix.os }}-${{ matrix.arch }}
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}-${{ matrix.arch }}-${{ github.run_number }}
path: .cache/image.tar
retention-days: 1
###########
# Testing #
###########
test:
needs: ["build"]
strategy:
fail-fast: false
matrix:
os: ["linux"]
# TODO: Return `arm32v6`, `arm32v7` and `s390x` once
# nodejs/docker-node#1973 is resolved:
# https://github.com/nodejs/docker-node/issues/1973
# TODO: Return `ppc64le` once nodejs/docker-node#2107 is resolved:
# https://github.com/nodejs/docker-node/issues/2107
arch:
- amd64
- arm64v8
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- run: make npm.install
- uses: actions/download-artifact@v4
with:
name: ${{ matrix.os }}-${{ matrix.arch }}-${{ github.run_number }}
path: .cache/
- run: make docker.untar from-file=.cache/image.tar
- run: make test.docker
platform=${{ matrix.os }}/${{ matrix.arch }}
tag=build-${{ github.run_number }}-${{ matrix.os }}-${{ matrix.arch }}
#############
# Releasing #
#############
push:
if: ${{ github.event_name == 'push'
&& startsWith(github.ref, 'refs/tags/') }}
needs: ["build", "test"]
strategy:
fail-fast: false
matrix:
registry: ["docker.io", "ghcr.io", "quay.io"]
runs-on: ubuntu-latest
steps:
# Skip if this is fork and no credentials are provided.
- id: skip
run: echo "no=${{ !(
github.repository_owner != 'instrumentisto'
&& ((matrix.registry == 'quay.io'
&& secrets.QUAYIO_ROBOT_USER == '')
|| (matrix.registry == 'docker.io'
&& secrets.DOCKERHUB_BOT_USER == ''))
) }}" >> $GITHUB_OUTPUT
- uses: actions/checkout@v4
if: ${{ steps.skip.outputs.no == 'true' }}
- name: Parse Docker image name from Git repository name
id: image
uses: actions-ecosystem/action-regex-match@v2
with:
text: ${{ github.repository }}
regex: '^${{ github.repository_owner }}/(.+)-docker-image$'
- name: Parse version from Git tag
id: version
uses: actions-ecosystem/action-regex-match@v2
with:
text: ${{ github.ref }}
regex: '^refs/tags/v(.+)$'
- uses: actions/download-artifact@v4
with:
path: .cache/
if: ${{ steps.skip.outputs.no == 'true' }}
- name: Login to ${{ matrix.registry }} container registry
uses: docker/login-action@v3
with:
registry: ${{ matrix.registry }}
username: ${{ (matrix.registry == 'docker.io'
&& secrets.DOCKERHUB_BOT_USER)
|| (matrix.registry == 'quay.io'
&& secrets.QUAYIO_ROBOT_USER)
|| github.repository_owner }}
password: ${{ (matrix.registry == 'docker.io'
&& secrets.DOCKERHUB_BOT_PASS)
|| (matrix.registry == 'quay.io'
&& secrets.QUAYIO_ROBOT_TOKEN)
|| secrets.GITHUB_TOKEN }}
if: ${{ steps.skip.outputs.no == 'true' }}
- name: Tag and push single-platform images
# TODO: Return `arm32v6`, `arm32v7` and `s390x` once
# nodejs/docker-node#1973 is resolved:
# https://github.com/nodejs/docker-node/issues/1973
# TODO: Return `ppc64le` once nodejs/docker-node#2107 is resolved:
# https://github.com/nodejs/docker-node/issues/2107
run: |
for platform in linux-amd64 \
linux-arm64v8
do
make docker.untar \
from-file=.cache/$platform-${{ github.run_number }}/image.tar
make docker.tags \
of=build-${{ github.run_number }}-$platform \
tags=${{ steps.version.outputs.group1 }}-$platform \
registries=${{ matrix.registry }}
make docker.push \
tags=${{ steps.version.outputs.group1 }}-$platform \
registries=${{ matrix.registry }}
done
if: ${{ steps.skip.outputs.no == 'true' }}
- name: Tag and push multi-platform images
# TODO: Return `arm32v6`, `arm32v7` and `s390x` once
# nodejs/docker-node#1973 is resolved:
# https://github.com/nodejs/docker-node/issues/1973
# TODO: Return `ppc64le` once nodejs/docker-node#2107 is resolved:
# https://github.com/nodejs/docker-node/issues/2107
run: make docker.manifest push=yes
registries=${{ matrix.registry }}
of='${{ steps.version.outputs.group1 }}-linux-amd64
${{ steps.version.outputs.group1 }}-linux-arm64v8'
if: ${{ steps.skip.outputs.no == 'true' }}
# On GitHub Container Registry README is automatically updated on pushes.
- name: Update README on Docker Hub
uses: christian-korneck/update-container-description-action@v1
with:
provider: dockerhub
destination_container_repo: ${{ github.repository_owner }}/${{ steps.image.outputs.group1 }}
readme_file: README.md
env:
DOCKER_USER: ${{ secrets.DOCKERHUB_BOT_USER }}
DOCKER_PASS: ${{ secrets.DOCKERHUB_BOT_PASS }}
if: ${{ steps.skip.outputs.no == 'true'
&& matrix.registry == 'docker.io' }}
- name: Update README on Quay.io
uses: christian-korneck/update-container-description-action@v1
with:
provider: quay
destination_container_repo: ${{ matrix.registry }}/${{ github.repository_owner }}/${{ steps.image.outputs.group1 }}
readme_file: README.md
env:
DOCKER_APIKEY: ${{ secrets.QUAYIO_API_TOKEN }}
if: ${{ steps.skip.outputs.no == 'true'
&& matrix.registry == 'quay.io' }}
release-github:
name: release (GitHub)
if: ${{ github.event_name == 'push'
&& startsWith(github.ref, 'refs/tags/') }}
needs: ["push"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Parse version from Git tag
id: version
uses: actions-ecosystem/action-regex-match@v2
with:
text: ${{ github.ref }}
regex: '^refs/tags/v(.+)$'
- name: Parse CHANGELOG link
id: changelog
run: echo "link=${{ github.server_url }}/${{ github.repository }}/blob/v${{ steps.version.outputs.group1 }}/CHANGELOG.md#$(sed -n '/^## \[${{ steps.version.outputs.group1 }}\]/{s/^## \[\(.*\)\][^0-9]*\([0-9].*\)/\1--\2/;s/[^0-9a-z-]*//g;p;}' CHANGELOG.md)"
>> $GITHUB_OUTPUT
- name: Create GitHub release
uses: softprops/action-gh-release@v2
with:
name: ${{ steps.version.outputs.group1 }}
body: |
[Changelog](${{ steps.changelog.outputs.link }})