Skip to content

Add asserts.

Add asserts. #619

Workflow file for this run

name: Build and Push Docker Image for Multiple Architectures
on:
pull_request:
push:
branches:
- master
- develop
tags:
- 'v*.*.*'
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
DOCKER_REGISTRY: index.docker.io
DOCKER_USERNAME: metacall
IMAGE_NAME: core
BUILDKIT_VERSION: 0.30.0
# TODO: Tests failing
# - linux/s390x
# - linux/ppc64le
# TODO: Detour not supported, needs to patch GOT instead of PLT
# - linux/mips64le
# - linux/mips64
# TODO: Debian does not support all packages yet (i.e NodeJS)
# - linux/loong64
PLATFORM_LIST: >
[
"linux/amd64",
"linux/amd64/v2",
"linux/amd64/v3",
"linux/386",
"linux/arm64",
"linux/riscv64",
"linux/arm/v7",
"linux/arm/v6"
]
jobs:
matrix:
name: Generate Platform List
runs-on: ubuntu-latest
outputs:
platform_list: ${{ steps.generate_platform_list.outputs.platform_list }}
steps:
- name: Generate platform list
id: generate_platform_list
run: |
set -exuo pipefail
PLATFORM_STRING=$(cat <<EOF
${{ env.PLATFORM_LIST }}
EOF
)
PLATFORM_LIST=$(echo $PLATFORM_STRING | jq -c .)
echo "PLATFORM_LIST=$PLATFORM_LIST" >> $GITHUB_ENV
echo "platform_list=$PLATFORM_LIST" >> $GITHUB_OUTPUT
build:
name: Build
runs-on: ubuntu-latest
needs: matrix
strategy:
fail-fast: false
matrix:
platform: ${{ fromJSON(needs.matrix.outputs.platform_list) }}
steps:
- name: Checkout Repository
uses: actions/[email protected]
with:
fetch-depth: 0
- name: Docker Metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker BuildX
uses: docker/setup-buildx-action@v3
with:
version: v${{ env.BUILDKIT_VERSION }}
- name: Login to Docker Hub
if: (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) && github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Build MetaCall Docker Images (local)
# Test in develop or pull requests
if: github.ref == 'refs/heads/develop' || github.event_name == 'pull_request'
env:
METACALL_PLATFORM: ${{ matrix.platform }}
DOCKER_BUILDKIT: 1
run: |
./docker-compose.sh platform
- name: Build MetaCall Docker Images (registry)
if: (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) && github.event_name != 'pull_request'
env:
METACALL_PLATFORM: ${{ matrix.platform }}
DOCKER_BUILDKIT: 1
run: |
./docker-compose.sh bake
- name: Run Tests
if: (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) && github.event_name != 'pull_request'
env:
DOCKER_BUILDKIT: 1
run: |
set -exuo pipefail
image=${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}@sha256:$(basename .bake/digests/cli/*)
docker pull --platform ${{ matrix.platform }} ${image}
docker image inspect ${image} --format='{{.Os}}/{{.Architecture}}'
cat <<EOF > Dockerfile.test
FROM ${image}
RUN apt-get update && apt-get install -y file
RUN file /usr/local/bin/metacallcli && ldd /usr/local/bin/metacallcli
RUN echo "console.log('0123456789abcdef')" > script.js
RUN metacallcli script.js | tee output.txt
RUN grep 0123456789abcdef output.txt
EOF
docker buildx build --progress=plain --platform ${{ matrix.platform }} -f Dockerfile.test -t metacall/core:test .
- name: Sanitize platform name
if: (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) && github.event_name != 'pull_request'
shell: bash
# Replaces all '/' with '-' using bash parameter expansion
run: |
PLATFORM_SAFE=${{ matrix.platform }}
echo "PLATFORM_SAFE=${PLATFORM_SAFE//\//-}" >> $GITHUB_ENV
- name: Upload digest
if: (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) && github.event_name != 'pull_request'
uses: actions/[email protected]
with:
name: digests-${{ env.PLATFORM_SAFE }}
path: .bake/digests/*
if-no-files-found: error
retention-days: 1
merge:
name: Merge digests for the manifest
# Only run when master or when tagging a version
if: (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) && github.event_name != 'pull_request'
needs: [matrix, build]
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/[email protected]
with:
fetch-depth: 0
- name: Download digests
uses: actions/[email protected]
with:
path: .bake/digests/
pattern: digests-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: v${{ env.BUILDKIT_VERSION }}
- name: Docker Metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Create manifest list and push
env:
TAG_VERSION: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
./docker-compose.sh manifest