Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Commit

Permalink
Updating github-config
Browse files Browse the repository at this point in the history
  • Loading branch information
paketo-bot committed Jul 27, 2022
1 parent ae2ea58 commit ef26767
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 32 deletions.
22 changes: 21 additions & 1 deletion .github/workflows/test-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 }}

Expand Down
26 changes: 26 additions & 0 deletions scripts/.util/builders.sh
Original file line number Diff line number Diff line change
@@ -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}"
}
77 changes: 46 additions & 31 deletions scripts/integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -29,6 +34,11 @@ function main() {
exit 0
;;

--builder|-b)
builderArray+=("${2}")
shift 2
;;

"")
# skip if the argument is empty
shift 1
Expand All @@ -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() {
Expand All @@ -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 <name> -b <name> sets the name of the builder(s) that are pulled / used for testing.
Defaults to "builders" array in integration.json, if present.
USAGE
}

Expand All @@ -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}"

Expand All @@ -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() {
Expand All @@ -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
}
Expand Down

0 comments on commit ef26767

Please sign in to comment.