From e454219d75e39d1ba3f79668ddef54aaa62d4348 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 16 Oct 2020 08:53:15 +0800 Subject: [PATCH] Dynamically builds docker build matrix Similar to https://github.com/golangci/golangci-lint/issues/828 --- .github/workflows/docker-tests.yml | 28 ++++++++++++++++++++-------- docker/hooks/build | 4 +++- docker/hooks/push | 4 +++- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/.github/workflows/docker-tests.yml b/.github/workflows/docker-tests.yml index bf3af7c..72634a2 100644 --- a/.github/workflows/docker-tests.yml +++ b/.github/workflows/docker-tests.yml @@ -8,12 +8,28 @@ on: - master jobs: - build-on-linux: - strategy: - matrix: - project: [armeria, dropwizard, webmvc25-jetty, webmvc3-jetty, webmvc4-boot, webmvc4-jetty] + discover-projects: + name: Build project matrix runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - name: Checkout Sources + uses: actions/checkout@v2 + with: + fetch-depth: 1 + - id: set-matrix + run: | + # Make a string like: [{"project":"armeria"},{"project":"dropwizard"}] + PROJECTS=$(ls */pom.xml|sed 's~\(.*\)/pom.xml~{"project":"\1"}~g'|tr '\n' ','|sed 's/\(.*\),$/[\1]/') + echo "::set-output name=matrix::{\"include\":[${PROJECTS}]}" + build-and-verify-docker: name: Build and verify Docker images + needs: discover-projects + runs-on: ubuntu-latest + strategy: + matrix: + matrix: ${{ fromJson(needs.discover-projects.outputs.matrix) }} steps: - name: Install Docker uses: docker-practice/actions-setup-docker@master @@ -25,10 +41,6 @@ jobs: path: ~/.docker key: ${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile') }} restore-keys: ${{ runner.os }}-docker - - name: Checkout Repository - uses: actions/checkout@v2 - with: - fetch-depth: 1 - name: Build Docker image openzipkin/example-brave:${{ matrix.project }}-test run: docker/build_image ${{ matrix.project }} ${{ matrix.project }}-test - name: Verify Docker image openzipkin/example-brave:${{ matrix.project }}-test diff --git a/docker/hooks/build b/docker/hooks/build index 9fb6551..09481c0 100755 --- a/docker/hooks/build +++ b/docker/hooks/build @@ -1,4 +1,6 @@ -#!/bin/sh -v +#!/bin/sh -x + +set -ue # This hook is called with the current directory set to the same as the Dockerfile, so we go back # to top level. diff --git a/docker/hooks/push b/docker/hooks/push index a31ac83..44a7912 100755 --- a/docker/hooks/push +++ b/docker/hooks/push @@ -1,4 +1,6 @@ -#!/bin/sh -v +#!/bin/sh -x + +set -ue # Override push to avoid pushing a latest tag. We use tags for each example. if [ "$DOCKER_REPO" = "index.docker.io/openzipkin/example-brave" ]; then