Skip to content

Commit f382fd8

Browse files
committed
Updating github-config
1 parent 50f7fdc commit f382fd8

3 files changed

Lines changed: 100 additions & 31 deletions

File tree

.github/workflows/test-pull-request.yml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,37 @@ on:
55
branches:
66
- main
77

8+
concurrency:
9+
# only one instance of test suite per PR at one time
10+
group: pr-${{ github.event.number }}
11+
cancel-in-progress: true
12+
813
jobs:
14+
builders:
15+
name: Get Builders for Testing
16+
runs-on: ubuntu-latest
17+
outputs:
18+
builders: ${{ steps.builders.outputs.builders }}
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v3
22+
- name: Get builders from integration.json
23+
id: builders
24+
run: |
25+
source "${{ github.workspace }}/scripts/.util/builders.sh"
26+
27+
builders="$(util::builders::list "${{ github.workspace }}/integration.json")"
28+
printf "Output: %s\n" "${builders}"
29+
printf "::set-output name=builders::%s\n" "${builders}"
30+
931
integration:
1032
name: Integration Tests
1133
runs-on: ubuntu-latest
34+
needs: [builders]
35+
strategy:
36+
matrix:
37+
builder: ${{ fromJSON(needs.builders.outputs.builders) }}
38+
fail-fast: false # don't cancel all test jobs when one fails
1239
steps:
1340
- name: Setup Go
1441
uses: actions/setup-go@v3
@@ -21,7 +48,7 @@ jobs:
2148
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* || true
2249

2350
- name: Run Integration Tests
24-
run: ./scripts/integration.sh
51+
run: ./scripts/integration.sh --builder ${{ matrix.builder }}
2552

2653
upload:
2754
name: Upload Workflow Event Payload

scripts/.util/builders.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
set -o pipefail
5+
6+
# shellcheck source=SCRIPTDIR/print.sh
7+
source "$(dirname "${BASH_SOURCE[0]}")/print.sh"
8+
9+
function util::builders::list() {
10+
local integrationJSON="${1}"
11+
local builders=""
12+
if [[ -f "${integrationJSON}" ]]; then
13+
builders="$(jq --compact-output 'select(.builder != null) | [.builder]' "${integrationJSON}")"
14+
15+
if [[ -z "${builders}" ]]; then
16+
builders="$(jq --compact-output 'select(.builders != null) | .builders' "${integrationJSON}")"
17+
fi
18+
fi
19+
20+
if [[ -z "${builders}" ]]; then
21+
util::print::info "No builders specified. Falling back to default builder..."
22+
builders="$(jq --compact-output --null-input '["index.docker.io/paketobuildpacks/builder:buildpackless-base"]')"
23+
fi
24+
25+
echo "${builders}"
26+
}

scripts/integration.sh

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ source "${PROGDIR}/.util/tools.sh"
1111
# shellcheck source=SCRIPTDIR/.util/print.sh
1212
source "${PROGDIR}/.util/print.sh"
1313

14+
# shellcheck source=SCRIPTDIR/.util/builders.sh
15+
source "${PROGDIR}/.util/builders.sh"
16+
1417
function main() {
18+
local builderArray
19+
builderArray=()
1520
while [[ "${#}" != 0 ]]; do
1621
case "${1}" in
1722
--help|-h)
@@ -20,6 +25,11 @@ function main() {
2025
exit 0
2126
;;
2227

28+
--builder|-b)
29+
builderArray+=("${2}")
30+
shift 2
31+
;;
32+
2333
"")
2434
# skip if the argument is empty
2535
shift 1
@@ -35,8 +45,32 @@ function main() {
3545
fi
3646

3747
tools::install
38-
images::pull
39-
tests::run
48+
49+
if [ ${#builderArray[@]} -eq 0 ]; then
50+
util::print::title "No builders provided. Finding builders in integration.json..."
51+
52+
local builders
53+
builders="$(util::builders::list "${BUILDPACKDIR}/integration.json" | jq -r '.[]' )"
54+
55+
# shellcheck disable=SC2206
56+
IFS=$'\n' builderArray=(${builders})
57+
unset IFS
58+
fi
59+
60+
# shellcheck disable=SC2068
61+
images::pull ${builderArray[@]}
62+
63+
local testout
64+
testout=$(mktemp)
65+
for builder in "${builderArray[@]}"; do
66+
util::print::title "Setting default pack builder image..."
67+
pack config default-builder "${builder}"
68+
69+
tests::run "${builder}" "${testout}"
70+
done
71+
72+
util::tools::tests::checkfocus "${testout}"
73+
util::print::success "** GO Test Succeeded with all builders**"
4074
}
4175

4276
function usage() {
@@ -46,7 +80,9 @@ integration.sh [OPTIONS]
4680
Runs the integration test suite.
4781
4882
OPTIONS
49-
--help -h prints the command usage
83+
--help -h prints the command usage
84+
--builder <name> -b <name> sets the name of the builder(s) that are pulled / used for testing.
85+
Defaults to "builders" array in integration.json, if present.
5086
USAGE
5187
}
5288

@@ -59,22 +95,7 @@ function tools::install() {
5995
}
6096

6197
function images::pull() {
62-
local builders
63-
builders=""
64-
65-
if [[ -f "${BUILDPACKDIR}/integration.json" ]]; then
66-
builders="$(jq -r .builder "${BUILDPACKDIR}/integration.json")"
67-
68-
if [[ "${builders}" == "null" || -z "${builders}" ]]; then
69-
builders="$(jq -r 'select(.builders != null) | .builders[]' "${BUILDPACKDIR}/integration.json")"
70-
fi
71-
fi
72-
73-
if [[ "${builders}" == "null" || -z "${builders}" ]]; then
74-
builders="index.docker.io/paketobuildpacks/builder:buildpackless-base"
75-
fi
76-
77-
while read -r builder; do
98+
for builder in "${@}"; do
7899
util::print::title "Pulling builder image ${builder}..."
79100
docker pull "${builder}"
80101

@@ -93,24 +114,19 @@ function images::pull() {
93114

94115
util::print::title "Pulling lifecycle image..."
95116
docker pull "${lifecycle_image}"
96-
done <<< "${builders}"
97-
98-
util::print::title "Setting default pack builder image..."
99-
local default
100-
read -r default <<< "${builders}"
101-
pack config default-builder "${default}"
117+
done
102118
}
103119

104120
function tests::run() {
105121
util::print::title "Run Buildpack Runtime Integration Tests"
122+
util::print::info "Using ${1} as builder..."
106123

107-
testout=$(mktemp)
108124
pushd "${BUILDPACKDIR}" > /dev/null
109-
if GOMAXPROCS="${GOMAXPROCS:-4}" go test -count=1 -timeout 0 ./integration/... -v -run Integration | tee "${testout}"; then
110-
util::tools::tests::checkfocus "${testout}"
111-
util::print::success "** GO Test Succeeded **"
125+
#shellcheck disable=SC2068
126+
if GOMAXPROCS="${GOMAXPROCS:-4}" go test -count=1 -timeout 0 ./integration/... -v -run Integration | tee "${2}"; then
127+
util::print::info "** GO Test Succeeded with ${1}**"
112128
else
113-
util::print::error "** GO Test Failed **"
129+
util::print::error "** GO Test Failed with ${1}**"
114130
fi
115131
popd > /dev/null
116132
}

0 commit comments

Comments
 (0)