2023-05-16 01:48:58 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -eu -o pipefail
|
|
|
|
|
|
|
|
: "${BUILDX_CMD=docker buildx}"
|
2023-05-30 06:44:21 +08:00
|
|
|
|
2024-06-11 15:35:26 +08:00
|
|
|
: "${TEST_COVERAGE=}"
|
2023-05-30 06:44:21 +08:00
|
|
|
: "${TEST_IMAGE_BUILD=1}"
|
|
|
|
: "${TEST_IMAGE_ID=buildx-tests}"
|
2023-05-16 01:48:58 +08:00
|
|
|
|
2023-05-30 06:24:01 +08:00
|
|
|
: "${TEST_REPORT_SUFFIX=}"
|
|
|
|
: "${TEST_KEEP_CACHE=}"
|
|
|
|
: "${TEST_DOCKERD=}"
|
2024-03-10 02:10:58 +08:00
|
|
|
: "${TEST_BUILDKIT_TAG=}"
|
2023-05-30 06:24:01 +08:00
|
|
|
: "${TEST_BUILDKIT_IMAGE=}"
|
2024-04-02 19:48:11 +08:00
|
|
|
: "${TEST_BUILDX_EXPERIMENTAL=}"
|
2023-05-16 01:48:58 +08:00
|
|
|
|
2023-05-30 06:44:21 +08:00
|
|
|
if [ "$TEST_IMAGE_BUILD" = "1" ]; then
|
|
|
|
${BUILDX_CMD} bake integration-test --set "*.output=type=docker,name=$TEST_IMAGE_ID"
|
2023-05-16 01:48:58 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
testReportsDir="$(pwd)/bin/testreports"
|
|
|
|
mkdir -p "$testReportsDir"
|
|
|
|
testReportsVol="-v $testReportsDir:/testreports"
|
|
|
|
gotestsumArgs="--format=standard-verbose --jsonfile=/testreports/go-test-report$TEST_REPORT_SUFFIX.json --junitfile=/testreports/junit-report$TEST_REPORT_SUFFIX.xml"
|
2024-06-11 15:35:26 +08:00
|
|
|
gotestArgs="-mod=vendor"
|
2023-05-16 01:48:58 +08:00
|
|
|
|
|
|
|
cacheVolume="buildx-test-cache"
|
|
|
|
if ! docker container inspect "$cacheVolume" >/dev/null 2>/dev/null; then
|
2024-03-10 07:29:40 +08:00
|
|
|
docker create -v /root/.cache -v /root/.cache/registry -v /root/.cache/undock -v /go/pkg/mod --name "$cacheVolume" alpine
|
2023-05-16 01:48:58 +08:00
|
|
|
fi
|
2023-05-30 06:30:25 +08:00
|
|
|
if [ "$TEST_KEEP_CACHE" != "1" ]; then
|
|
|
|
trap 'docker rm -v $cacheVolume' EXIT
|
|
|
|
fi
|
2023-05-16 01:48:58 +08:00
|
|
|
|
2024-06-11 15:35:26 +08:00
|
|
|
if [ "$TEST_COVERAGE" = "1" ]; then
|
|
|
|
export GO_TEST_COVERPROFILE="/testreports/coverage-report$TEST_REPORT_SUFFIX.txt"
|
|
|
|
fi
|
|
|
|
|
|
|
|
cid=$(docker create --rm --privileged \
|
|
|
|
-v /tmp $testReportsVol \
|
|
|
|
--volumes-from=$cacheVolume \
|
|
|
|
-e GITHUB_REF \
|
|
|
|
-e TEST_DOCKERD \
|
|
|
|
-e TEST_BUILDKIT_IMAGE \
|
|
|
|
-e TEST_BUILDKIT_TAG \
|
|
|
|
-e TEST_BUILDX_EXPERIMENTAL \
|
|
|
|
-e SKIP_INTEGRATION_TESTS \
|
|
|
|
-e GOTESTSUM_FORMAT \
|
|
|
|
-e GO_TEST_COVERPROFILE \
|
|
|
|
${BUILDKIT_INTEGRATION_SNAPSHOTTER:+"-eBUILDKIT_INTEGRATION_SNAPSHOTTER"} \
|
|
|
|
-e BUILDKIT_REGISTRY_MIRROR_DIR=/root/.cache/registry \
|
|
|
|
$TEST_IMAGE_ID gotestsumandcover $gotestsumArgs --packages="${TESTPKGS:-./...}" -- $gotestArgs ${TESTFLAGS:--v})
|
|
|
|
|
2023-05-30 06:24:01 +08:00
|
|
|
docker start -a -i $cid
|