Jenkinsfile: force validate on master, and some fixes/improvements
Sebastiaan van Stijn authored on 2019/12/23 21:39:43... | ... |
@@ -9,6 +9,7 @@ pipeline { |
9 | 9 |
} |
10 | 10 |
parameters { |
11 | 11 |
booleanParam(name: 'unit_validate', defaultValue: true, description: 'amd64 (x86_64) unit tests and vendor check') |
12 |
+ booleanParam(name: 'validate_force', defaultValue: false, description: 'force validation steps to be run, even if no changes were detected') |
|
12 | 13 |
booleanParam(name: 'amd64', defaultValue: true, description: 'amd64 (x86_64) Build/Test') |
13 | 14 |
booleanParam(name: 'arm64', defaultValue: true, description: 'ARM (arm64) Build/Test') |
14 | 15 |
booleanParam(name: 's390x', defaultValue: true, description: 'IBM Z (s390x) Build/Test') |
... | ... |
@@ -62,6 +63,12 @@ pipeline { |
62 | 62 |
expression { params.unit_validate } |
63 | 63 |
} |
64 | 64 |
agent { label 'amd64 && ubuntu-1804 && overlay2' } |
65 |
+ environment { |
|
66 |
+ // On master ("non-pull-request"), force running some validation checks (vendor, swagger), |
|
67 |
+ // even if no files were changed. This allows catching problems caused by pull-requests |
|
68 |
+ // that were merged out-of-sequence. |
|
69 |
+ TEST_FORCE_VALIDATE = sh returnStdout: true, script: 'if [ "${BRANCH_NAME%%-*}" != "PR" ] || [ "${CHANGE_TARGET:-master}" != "master" ] || [ "${validate_force}" = "true" ]; then echo "1"; fi' |
|
70 |
+ } |
|
65 | 71 |
|
66 | 72 |
stages { |
67 | 73 |
stage("Print info") { |
... | ... |
@@ -90,6 +97,7 @@ pipeline { |
90 | 90 |
-e DOCKER_EXPERIMENTAL \ |
91 | 91 |
-e DOCKER_GITCOMMIT=${GIT_COMMIT} \ |
92 | 92 |
-e DOCKER_GRAPHDRIVER \ |
93 |
+ -e TEST_FORCE_VALIDATE \ |
|
93 | 94 |
-e VALIDATE_REPO=${GIT_URL} \ |
94 | 95 |
-e VALIDATE_BRANCH=${CHANGE_TARGET} \ |
95 | 96 |
docker:${GIT_COMMIT} \ |
... | ... |
@@ -197,6 +205,7 @@ pipeline { |
197 | 197 |
-e DOCKER_EXPERIMENTAL \ |
198 | 198 |
-e DOCKER_GITCOMMIT=${GIT_COMMIT} \ |
199 | 199 |
-e DOCKER_GRAPHDRIVER \ |
200 |
+ -e TEST_FORCE_VALIDATE \ |
|
200 | 201 |
-e VALIDATE_REPO=${GIT_URL} \ |
201 | 202 |
-e VALIDATE_BRANCH=${CHANGE_TARGET} \ |
202 | 203 |
docker:${GIT_COMMIT} \ |
... | ... |
@@ -4,13 +4,13 @@ |
4 | 4 |
|
5 | 5 |
export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
6 | 6 |
|
7 |
-. ${SCRIPTDIR}/dco |
|
8 |
-. ${SCRIPTDIR}/default-seccomp |
|
9 |
-. ${SCRIPTDIR}/golangci-lint |
|
10 |
-. ${SCRIPTDIR}/pkg-imports |
|
11 |
-. ${SCRIPTDIR}/swagger |
|
12 |
-. ${SCRIPTDIR}/swagger-gen |
|
13 |
-. ${SCRIPTDIR}/toml |
|
14 |
-. ${SCRIPTDIR}/changelog-well-formed |
|
15 |
-. ${SCRIPTDIR}/changelog-date-descending |
|
16 |
-#. ${SCRIPTDIR}/deprecate-integration-cli |
|
7 |
+. "${SCRIPTDIR}"/dco |
|
8 |
+. "${SCRIPTDIR}"/default-seccomp |
|
9 |
+. "${SCRIPTDIR}"/pkg-imports |
|
10 |
+. "${SCRIPTDIR}"/swagger |
|
11 |
+. "${SCRIPTDIR}"/swagger-gen |
|
12 |
+. "${SCRIPTDIR}"/toml |
|
13 |
+. "${SCRIPTDIR}"/changelog-well-formed |
|
14 |
+. "${SCRIPTDIR}"/changelog-date-descending |
|
15 |
+. "${SCRIPTDIR}"/deprecate-integration-cli |
|
16 |
+. "${SCRIPTDIR}"/golangci-lint |
... | ... |
@@ -7,7 +7,7 @@ IFS=$'\n' |
7 | 7 |
files=( $(validate_diff --diff-filter=ACMR --name-only -- 'profiles/seccomp' || true) ) |
8 | 8 |
unset IFS |
9 | 9 |
|
10 |
-if [ ${#files[@]} -gt 0 ]; then |
|
10 |
+if [ -n "${TEST_FORCE_VALIDATE:-}" ] || [ ${#files[@]} -gt 0 ]; then |
|
11 | 11 |
# We run 'go generate' and see if we have a diff afterwards |
12 | 12 |
go generate ./profiles/seccomp/ >/dev/null |
13 | 13 |
# Let see if the working directory is clean |
... | ... |
@@ -23,6 +23,6 @@ if [ ${#files[@]} -gt 0 ]; then |
23 | 23 |
} >&2 |
24 | 24 |
false |
25 | 25 |
else |
26 |
- echo 'Congratulations! Seccomp profile generation is done correctly.' |
|
26 |
+ echo 'Congratulations! Seccomp profile generation is done correctly.' |
|
27 | 27 |
fi |
28 | 28 |
fi |
... | ... |
@@ -5,21 +5,21 @@ export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
5 | 5 |
source "${SCRIPTDIR}/.validate" |
6 | 6 |
|
7 | 7 |
new_tests=$( |
8 |
- validate_diff --diff-filter=ACMR --unified=0 -- 'integration-cli/*_cli_*.go' | |
|
8 |
+ validate_diff --diff-filter=ACMR --unified=0 -- 'integration-cli/*_api_*.go' 'integration-cli/*_cli_*.go' | |
|
9 | 9 |
grep -E '^\+func (.*) Test' || true |
10 | 10 |
) |
11 | 11 |
|
12 |
-if [ -z "$new_tests" ]; then |
|
13 |
- echo 'Congratulations! No new tests added to integration-cli.' |
|
14 |
- exit |
|
12 |
+if [ -n "$new_tests" ]; then |
|
13 |
+ { |
|
14 |
+ echo "The following new tests were added to integration-cli:" |
|
15 |
+ echo |
|
16 |
+ echo "$new_tests" |
|
17 |
+ echo |
|
18 |
+ echo "integration-cli is deprecated. Please add an API integration test to" |
|
19 |
+ echo "./integration/COMPONENT/. See ./TESTING.md for more details." |
|
20 |
+ echo |
|
21 |
+ } >&2 |
|
22 |
+ false |
|
23 |
+else |
|
24 |
+ echo 'Congratulations! No new tests were added to integration-cli.' |
|
15 | 25 |
fi |
16 |
- |
|
17 |
-echo "The following new tests were added to integration-cli:" |
|
18 |
-echo |
|
19 |
-echo "$new_tests" |
|
20 |
-echo |
|
21 |
-echo "integration-cli is deprecated. Please add an API integration test to" |
|
22 |
-echo "./integration/COMPONENT/. See ./TESTING.md for more details." |
|
23 |
-echo |
|
24 |
- |
|
25 |
-exit 1 |
... | ... |
@@ -17,6 +17,8 @@ elif ${PKG_CONFIG} 'libsystemd-journal' 2> /dev/null ; then |
17 | 17 |
DOCKER_BUILDTAGS+=" journald journald_compat" |
18 | 18 |
fi |
19 | 19 |
|
20 |
+echo -e "\n\033[0;36mINFO\033[0m Start validation with golang-ci-lint" |
|
21 |
+ |
|
20 | 22 |
# TODO use --out-format=junit-xml and store artifacts |
21 | 23 |
# shellcheck disable=SC2086 |
22 | 24 |
GOGC=75 golangci-lint run \ |
... | ... |
@@ -20,7 +20,7 @@ for f in "${files[@]}"; do |
20 | 20 |
done |
21 | 21 |
|
22 | 22 |
if [ ${#badFiles[@]} -eq 0 ]; then |
23 |
- echo 'Congratulations! "./pkg/..." is safely isolated from internal code.' |
|
23 |
+ echo 'Congratulations! Packages in "./pkg/..." are safely isolated from internal code.' |
|
24 | 24 |
else |
25 | 25 |
{ |
26 | 26 |
echo 'These files import internal code: (either directly or indirectly)' |
... | ... |
@@ -7,7 +7,12 @@ IFS=$'\n' |
7 | 7 |
files=( $(validate_diff --diff-filter=ACMR --name-only -- 'api/swagger.yaml' || true) ) |
8 | 8 |
unset IFS |
9 | 9 |
|
10 |
-if [ ${#files[@]} -gt 0 ]; then |
|
11 |
- LANG=C.UTF-8 yamllint -c ${SCRIPTDIR}/.swagger-yamllint api/swagger.yaml |
|
12 |
- swagger validate api/swagger.yaml |
|
10 |
+if [ -n "${TEST_FORCE_VALIDATE:-}" ] || [ ${#files[@]} -gt 0 ]; then |
|
11 |
+ LANG=C.UTF-8 yamllint -c "${SCRIPTDIR}"/.swagger-yamllint api/swagger.yaml |
|
12 |
+ if out=$(swagger validate api/swagger.yaml); then |
|
13 |
+ echo "Congratulations! ${out}" |
|
14 |
+ else |
|
15 |
+ echo "${out}" >&2 |
|
16 |
+ false |
|
17 |
+ fi |
|
13 | 18 |
fi |
... | ... |
@@ -7,8 +7,8 @@ IFS=$'\n' |
7 | 7 |
files=( $(validate_diff --diff-filter=ACMR --name-only -- 'api/types/' 'api/swagger.yaml' || true) ) |
8 | 8 |
unset IFS |
9 | 9 |
|
10 |
-if [ ${#files[@]} -gt 0 ]; then |
|
11 |
- ${SCRIPTDIR}/../generate-swagger-api.sh 2> /dev/null |
|
10 |
+if [ -n "${TEST_FORCE_VALIDATE:-}" ] || [ ${#files[@]} -gt 0 ]; then |
|
11 |
+ "${SCRIPTDIR}"/../generate-swagger-api.sh 2> /dev/null |
|
12 | 12 |
# Let see if the working directory is clean |
13 | 13 |
diffs="$(git diff -- api/types/)" |
14 | 14 |
if [ "$diffs" ]; then |
... | ... |
@@ -17,12 +17,12 @@ if [ ${#files[@]} -gt 0 ]; then |
17 | 17 |
echo |
18 | 18 |
echo "$diffs" |
19 | 19 |
echo |
20 |
- echo 'Please update api/swagger.yaml with any api changes, then ' |
|
21 |
- echo 'run `hack/generate-swagger-api.sh`.' |
|
20 |
+ echo 'Please update api/swagger.yaml with any API changes, then ' |
|
21 |
+ echo 'run hack/generate-swagger-api.sh.' |
|
22 | 22 |
} >&2 |
23 | 23 |
false |
24 | 24 |
else |
25 |
- echo 'Congratulations! All api changes are done the right way.' |
|
25 |
+ echo 'Congratulations! All API changes are done the right way.' |
|
26 | 26 |
fi |
27 | 27 |
else |
28 | 28 |
echo 'No api/types/ or api/swagger.yaml changes in diff.' |
... | ... |
@@ -9,22 +9,22 @@ unset IFS |
9 | 9 |
|
10 | 10 |
badFiles=() |
11 | 11 |
for f in "${files[@]}"; do |
12 |
- # we use "git show" here to validate that what's committed has valid toml syntax |
|
12 |
+ # we use "git show" here to validate that what's committed has valid TOML syntax |
|
13 | 13 |
if ! git show "$VALIDATE_HEAD:$f" | tomlv /proc/self/fd/0 ; then |
14 | 14 |
badFiles+=( "$f" ) |
15 | 15 |
fi |
16 | 16 |
done |
17 | 17 |
|
18 | 18 |
if [ ${#badFiles[@]} -eq 0 ]; then |
19 |
- echo 'Congratulations! All toml source files changed here have valid syntax.' |
|
19 |
+ echo 'Congratulations! All TOML source files changed here have valid syntax.' |
|
20 | 20 |
else |
21 | 21 |
{ |
22 |
- echo "These files are not valid toml:" |
|
22 |
+ echo "These files are not valid TOML:" |
|
23 | 23 |
for f in "${badFiles[@]}"; do |
24 | 24 |
echo " - $f" |
25 | 25 |
done |
26 | 26 |
echo |
27 |
- echo 'Please reformat the above files as valid toml' |
|
27 |
+ echo 'Please reformat the above files as valid TOML' |
|
28 | 28 |
echo |
29 | 29 |
} >&2 |
30 | 30 |
false |
... | ... |
@@ -8,7 +8,7 @@ validate_vendor_diff(){ |
8 | 8 |
files=( $(validate_diff --diff-filter=ACMR --name-only -- 'vendor.conf' 'vendor/' || true) ) |
9 | 9 |
unset IFS |
10 | 10 |
|
11 |
- if [ ${#files[@]} -gt 0 ]; then |
|
11 |
+ if [ -n "${TEST_FORCE_VALIDATE:-}" ] || [ ${#files[@]} -gt 0 ]; then |
|
12 | 12 |
# recreate vendor/ |
13 | 13 |
vndr |
14 | 14 |
# check if any files have changed |