From ef26767d97b96f6665920316ac46145a2c37e765 Mon Sep 17 00:00:00 2001 From: paketo-bot Date: Tue, 26 Jul 2022 03:51:51 +0000 Subject: [PATCH] Updating github-config --- .github/workflows/test-pull-request.yml | 22 ++++++- scripts/.util/builders.sh | 26 +++++++++ scripts/integration.sh | 77 +++++++++++++++---------- 3 files changed, 93 insertions(+), 32 deletions(-) create mode 100644 scripts/.util/builders.sh diff --git a/.github/workflows/test-pull-request.yml b/.github/workflows/test-pull-request.yml index 3c297db..1fa837f 100644 --- a/.github/workflows/test-pull-request.yml +++ b/.github/workflows/test-pull-request.yml @@ -5,10 +5,17 @@ on: branches: - main +concurrency: + # only one instance of test suite per PR at one time + group: pr-${{ github.event.number }} + cancel-in-progress: true + jobs: unit: name: Unit Tests runs-on: ubuntu-latest + outputs: + builders: ${{ steps.builders.outputs.builders }} steps: - name: Setup Go uses: actions/setup-go@v3 @@ -21,10 +28,23 @@ jobs: - name: Run Unit Tests run: ./scripts/unit.sh + - name: Get builders from integration.json + id: builders + run: | + source "${{ github.workspace }}/scripts/.util/builders.sh" + + builders="$(util::builders::list "${{ github.workspace }}/integration.json")" + printf "Output: %s\n" "${builders}" + printf "::set-output name=builders::%s\n" "${builders}" + integration: name: Integration Tests runs-on: ubuntu-latest needs: unit + strategy: + matrix: + builder: ${{ fromJSON(needs.unit.outputs.builders) }} + fail-fast: false # don't cancel all test jobs when one fails steps: - name: Setup Go uses: actions/setup-go@v3 @@ -37,7 +57,7 @@ jobs: - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* || true - name: Run Integration Tests - run: ./scripts/integration.sh --use-token + run: ./scripts/integration.sh --use-token --builder ${{ matrix.builder }} env: GIT_TOKEN: ${{ github.token }} diff --git a/scripts/.util/builders.sh b/scripts/.util/builders.sh new file mode 100644 index 0000000..05fa91b --- /dev/null +++ b/scripts/.util/builders.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +set -eu +set -o pipefail + +# shellcheck source=SCRIPTDIR/print.sh +source "$(dirname "${BASH_SOURCE[0]}")/print.sh" + +function util::builders::list() { + local integrationJSON="${1}" + local builders="" + if [[ -f "${integrationJSON}" ]]; then + builders="$(jq --compact-output 'select(.builder != null) | [.builder]' "${integrationJSON}")" + + if [[ -z "${builders}" ]]; then + builders="$(jq --compact-output 'select(.builders != null) | .builders' "${integrationJSON}")" + fi + fi + + if [[ -z "${builders}" ]]; then + util::print::info "No builders specified. Falling back to default builder..." + builders="$(jq --compact-output --null-input '["index.docker.io/paketobuildpacks/builder:buildpackless-base"]')" + fi + + echo "${builders}" +} diff --git a/scripts/integration.sh b/scripts/integration.sh index d6771a4..4110a3c 100755 --- a/scripts/integration.sh +++ b/scripts/integration.sh @@ -15,7 +15,12 @@ source "${PROGDIR}/.util/print.sh" # shellcheck source=SCRIPTDIR/.util/git.sh source "${PROGDIR}/.util/git.sh" +# shellcheck source=SCRIPTDIR/.util/builders.sh +source "${PROGDIR}/.util/builders.sh" + function main() { + local builderArray + builderArray=() while [[ "${#}" != 0 ]]; do case "${1}" in --use-token|-t) @@ -29,6 +34,11 @@ function main() { exit 0 ;; + --builder|-b) + builderArray+=("${2}") + shift 2 + ;; + "") # skip if the argument is empty shift 1 @@ -44,8 +54,32 @@ function main() { fi tools::install - images::pull - tests::run + + if [ ${#builderArray[@]} -eq 0 ]; then + util::print::title "No builders provided. Finding builders in integration.json..." + + local builders + builders="$(util::builders::list "${BUILDPACKDIR}/integration.json" | jq -r '.[]' )" + + # shellcheck disable=SC2206 + IFS=$'\n' builderArray=(${builders}) + unset IFS + fi + + # shellcheck disable=SC2068 + images::pull ${builderArray[@]} + + local testout + testout=$(mktemp) + for builder in "${builderArray[@]}"; do + util::print::title "Setting default pack builder image..." + pack config default-builder "${builder}" + + tests::run "${builder}" "${testout}" + done + + util::tools::tests::checkfocus "${testout}" + util::print::success "** GO Test Succeeded with all builders**" } function usage() { @@ -55,8 +89,10 @@ integration.sh [OPTIONS] Runs the integration test suite. OPTIONS - --help -h prints the command usage - --use-token -t use GIT_TOKEN from lastpass + --help -h prints the command usage + --use-token -t use GIT_TOKEN from lastpass + --builder -b sets the name of the builder(s) that are pulled / used for testing. + Defaults to "builders" array in integration.json, if present. USAGE } @@ -77,22 +113,7 @@ function tools::install() { } function images::pull() { - local builders - builders="" - - if [[ -f "${BUILDPACKDIR}/integration.json" ]]; then - builders="$(jq -r .builder "${BUILDPACKDIR}/integration.json")" - - if [[ "${builders}" == "null" || -z "${builders}" ]]; then - builders="$(jq -r 'select(.builders != null) | .builders[]' "${BUILDPACKDIR}/integration.json")" - fi - fi - - if [[ "${builders}" == "null" || -z "${builders}" ]]; then - builders="index.docker.io/paketobuildpacks/builder:buildpackless-base" - fi - - while read -r builder; do + for builder in "${@}"; do util::print::title "Pulling builder image ${builder}..." docker pull "${builder}" @@ -111,12 +132,7 @@ function images::pull() { util::print::title "Pulling lifecycle image..." docker pull "${lifecycle_image}" - done <<< "${builders}" - - util::print::title "Setting default pack builder image..." - local default - read -r default <<< "${builders}" - pack config default-builder "${default}" + done } function token::fetch() { @@ -126,14 +142,13 @@ function token::fetch() { function tests::run() { util::print::title "Run Buildpack Runtime Integration Tests" + util::print::info "Using ${1} as builder..." - testout=$(mktemp) pushd "${BUILDPACKDIR}" > /dev/null - if GOMAXPROCS="${GOMAXPROCS:-4}" go test -count=1 -timeout 0 ./integration/... -v -run Integration | tee "${testout}"; then - util::tools::tests::checkfocus "${testout}" - util::print::success "** GO Test Succeeded **" + if GOMAXPROCS="${GOMAXPROCS:-4}" go test -count=1 -timeout 0 ./integration/... -v -run Integration | tee "${2}"; then + util::print::info "** GO Test Succeeded with ${1}**" else - util::print::error "** GO Test Failed **" + util::print::error "** GO Test Failed with ${1}**" fi popd > /dev/null }