Bump dependencies and switch to conanfile.py #543
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright (C) 2022 Roberto Rossini (roberros@uio.no) | |
# SPDX-License-Identifier: MIT | |
name: Build Docker image | |
on: | |
push: | |
branches: [ main ] | |
paths: | |
- ".github/workflows/build-docker-image.yml" | |
- "cmake/**" | |
- "external/**" | |
- "src/**" | |
- "test/**" | |
- "!test/scripts/devel/**" | |
- "CMakeLists.txt" | |
- ".dockerignore" | |
- "Dockerfile" | |
- "conanfile.txt" | |
tags: | |
- 'v*.*.*' | |
pull_request: | |
paths: | |
- ".github/workflows/build-docker-image.yml" | |
- "cmake/**" | |
- "external/**" | |
- "src/**" | |
- "test/**" | |
- "!test/scripts/devel/**" | |
- "CMakeLists.txt" | |
- "Dockerfile" | |
- ".dockerignore" | |
- "conanfile.txt" | |
# https://stackoverflow.com/a/72408109 | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
cache-test-datasets: | |
uses: paulsengroup/modle/.github/workflows/cache-test-datasets.yml@main | |
build-docker-image: | |
name: Build Docker image | |
needs: cache-test-datasets | |
runs-on: ubuntu-latest | |
permissions: | |
packages: 'write' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Download test datasets | |
uses: actions/download-artifact@v3 | |
with: | |
name: ${{ needs.cache-test-datasets.outputs.artifact-name }} | |
path: test/data/ | |
- name: Generate build args | |
id: build-args | |
run: | | |
set -e | |
set -u | |
set -o pipefail | |
OS_NAME='ubuntu' | |
OS_VERSION='22.04' | |
C_COMPILER='clang-15' | |
CXX_COMPILER='clang++-15' | |
BUILD_BASE_IMAGE="ghcr.io/${{ github.repository_owner }}/ci-docker-images/$OS_NAME-$OS_VERSION-cxx-$C_COMPILER:latest" | |
TEST_BASE_IMAGE="ghcr.io/${{ github.repository_owner }}/ci-docker-images/modle/$OS_NAME-$OS_VERSION-cxx-$C_COMPILER:latest" | |
FINAL_BASE_IMAGE="docker.io/library/$OS_NAME" | |
FINAL_BASE_IMAGE_TAG="$OS_VERSION" | |
sudo docker pull "$FINAL_BASE_IMAGE:$FINAL_BASE_IMAGE_TAG" | |
FINAL_BASE_IMAGE_DIGEST="$(docker inspect --format='{{index .RepoDigests 0}}' "$FINAL_BASE_IMAGE:$FINAL_BASE_IMAGE_TAG" | grep -o '[[:alnum:]:]\+$')" | |
GIT_HASH="$(git rev-parse HEAD)" | |
GIT_SHORT_HASH="$(git rev-parse --short HEAD)" | |
CREATION_DATE="$(date --iso-8601)" | |
GIT_TAG="$(git for-each-ref 'refs/tags/v*.*.*' --count 1 --sort=-v:refname --format "%(refname:short)" --points-at HEAD)" | |
if [ -z "$GIT_TAG" ]; then | |
VERSION="sha-$GIT_SHORT_HASH" | |
GIT_TAG=unknown | |
else | |
VERSION="$GIT_TAG" | |
fi | |
if [[ ${{ github.event_name }} != 'pull_request' ]]; then | |
PLATFORMS='linux/amd64,linux/arm64' | |
else | |
PLATFORMS='linux/amd64' | |
fi | |
echo "C_COMPILER=$C_COMPILER" >> $GITHUB_OUTPUT | |
echo "CXX_COMPILER=$CXX_COMPILER" >> $GITHUB_OUTPUT | |
echo "FINAL_BASE_IMAGE=$FINAL_BASE_IMAGE" >> $GITHUB_OUTPUT | |
echo "FINAL_BASE_IMAGE_TAG=$FINAL_BASE_IMAGE_TAG" >> $GITHUB_OUTPUT | |
echo "BUILD_BASE_IMAGE=$BUILD_BASE_IMAGE" >> $GITHUB_OUTPUT | |
echo "TEST_BASE_IMAGE=$TEST_BASE_IMAGE" >> $GITHUB_OUTPUT | |
echo "FINAL_BASE_IMAGE_DIGEST=$FINAL_BASE_IMAGE_DIGEST" >> $GITHUB_OUTPUT | |
echo "GIT_HASH=$GIT_HASH" >> $GITHUB_OUTPUT | |
echo "GIT_SHORT_HASH=$GIT_SHORT_HASH" >> $GITHUB_OUTPUT | |
echo "CREATION_DATE=$CREATION_DATE" >> $GITHUB_OUTPUT | |
echo "GIT_TAG=$GIT_TAG" >> $GITHUB_OUTPUT | |
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT | |
echo "PLATFORMS=$PLATFORMS" >> $GITHUB_OUTPUT | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ github.repository }},ghcr.io/${{ github.repository }} | |
flavor: | | |
latest=true | |
tags: | | |
type=semver,priority=1000,pattern={{version}} | |
type=sha,priority=900 | |
type=raw,value=stable,priority=800,enable=${{ !startsWith(github.ref, 'refs/tags/v') }} | |
type=ref,priority=700,event=branch | |
type=ref,priority=600,event=pr | |
- name: Login to DockerHub | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
with: | |
platforms: linux/amd64,linux/arm64 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
with: | |
platforms: arm64 | |
- name: Build Docker image and push to registries | |
uses: docker/build-push-action@v4 | |
with: | |
context: ${{ github.workspace }} | |
push: ${{ github.event_name != 'pull_request' }} | |
cache-from: type=gha,scope=build-modle-docker-image | |
cache-to: type=gha,mode=min,scope=build-modle-docker-image | |
tags: ${{ steps.meta.outputs.tags }} | |
platforms: ${{ steps.build-args.outputs.PLATFORMS }} | |
build-args: | | |
C_COMPILER=${{ steps.build-args.outputs.C_COMPILER }} | |
CXX_COMPILER=${{ steps.build-args.outputs.CXX_COMPILER }} | |
BUILD_BASE_IMAGE=${{ steps.build-args.outputs.BUILD_BASE_IMAGE }} | |
TEST_BASE_IMAGE=${{ steps.build-args.outputs.TEST_BASE_IMAGE }} | |
FINAL_BASE_IMAGE=${{ steps.build-args.outputs.FINAL_BASE_IMAGE }} | |
FINAL_BASE_IMAGE_TAG=${{ steps.build-args.outputs.FINAL_BASE_IMAGE_TAG }} | |
FINAL_BASE_IMAGE_DIGEST=${{ steps.build-args.outputs.FINAL_BASE_IMAGE_DIGEST }} | |
GIT_HASH=${{ steps.build-args.outputs.GIT_HASH }} | |
GIT_SHORT_HASH=${{ steps.build-args.outputs.GIT_SHORT_HASH }} | |
CREATION_DATE=${{ steps.build-args.outputs.CREATION_DATE }} | |
GIT_TAG=${{ steps.build-args.outputs.GIT_TAG }} | |
GIT_IS_DIRTY=false | |
VERSION=${{ steps.build-args.outputs.VERSION }} | |
test-docker-image: | |
name: Test Docker image | |
needs: build-docker-image | |
runs-on: ubuntu-latest | |
permissions: | |
packages: 'read' | |
if: github.event_name != 'pull_request' | |
container: | |
image: ghcr.io/${{ github.repository }}:latest | |
options: '--entrypoint /bin/bash' | |
credentials: | |
username: ${{ github.actor }} | |
password: ${{ secrets.github_token }} | |
steps: | |
- name: Test modle | |
run: | | |
set -o pipefail | |
whereis -b modle | |
ls -lah "$(whereis -b modle | cut -d$' ' -f 2)" | |
modle --help | |
modle --version | |
- name: Test modle_tools | |
run: | | |
set -o pipefail | |
whereis -b modle_tools | |
ls -lah "$(whereis -b modle_tools | cut -d$' ' -f 2)" | |
modle_tools --help | |
modle_tools --version | |
build-docker-image-status-check: | |
name: Status Check (Build Docker image) | |
if: ${{ always() }} | |
runs-on: ubuntu-latest | |
needs: | |
- cache-test-datasets | |
- build-docker-image | |
- test-docker-image | |
steps: | |
- name: Collect job results | |
if: | | |
needs.cache-test-datasets.result != 'success' || | |
needs.build-docker-image.result != 'success' || | |
(needs.test-docker-image.result != 'success' && | |
needs.test-docker-image.result != 'skipped') | |
run: exit 1 |