Skip to content

Commit

Permalink
[FAB-11032] Handle no package changes on CI
Browse files Browse the repository at this point in the history
This change adds a check to handle the case where no
packages have changed.

Additionally Gopkg.lock is treated as a test script change.

Change-Id: I04e86e6fc04422b24b3be2b0dafc582bdac03186
Signed-off-by: Troy Ronda <troy@troyronda.com>
  • Loading branch information
troyronda committed Jul 3, 2018
1 parent c113065 commit 139bfdf
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -9,7 +9,8 @@
.vscode
debug.test
vendor/

scripts/_go/pkg/
scripts/_go/bin/

# Files auto-generated by docker-compose
test/fixtures/fabricca/tls/certs/server/ca.org*.example.com-cert.pem
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/expiredorderer.sh
Expand Up @@ -58,7 +58,7 @@ if [ "$TEST_CHANGED_ONLY" = true ]; then
findChangedFiles
cd ${PWD}

if [[ "${CHANGED_FILES[@]}" =~ ( |^)(test/fixtures/|test/metadata/|test/scripts/|Makefile( |$)) ]]; then
if [[ "${CHANGED_FILES[@]}" =~ ( |^)(test/fixtures/|test/metadata/|test/scripts/|Makefile( |$)|Gopkg.lock( |$)) ]]; then
echo "Test scripts, fixtures or metadata changed - running all tests"
else
findChangedPackages
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/expiredpeer.sh
Expand Up @@ -58,7 +58,7 @@ if [ "$TEST_CHANGED_ONLY" = true ]; then
findChangedFiles
cd ${PWD}

if [[ "${CHANGED_FILES[@]}" =~ ( |^)(test/fixtures/|test/metadata/|test/scripts/|Makefile( |$)) ]]; then
if [[ "${CHANGED_FILES[@]}" =~ ( |^)(test/fixtures/|test/metadata/|test/scripts/|Makefile( |$)|Gopkg.lock( |$)) ]]; then
echo "Test scripts, fixtures or metadata changed - running all tests"
else
findChangedPackages
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/integration.sh
Expand Up @@ -62,7 +62,7 @@ if [ "$TEST_CHANGED_ONLY" = true ]; then
findChangedFiles
cd ${PWD}

if [[ "${CHANGED_FILES[@]}" =~ ( |^)(test/fixtures/|test/metadata/|test/scripts/|Makefile( |$)) ]]; then
if [[ "${CHANGED_FILES[@]}" =~ ( |^)(test/fixtures/|test/metadata/|test/scripts/|Makefile( |$)|Gopkg.lock( |$)) ]]; then
echo "Test scripts, fixtures or metadata changed - running all tests"
else
findChangedPackages
Expand Down
22 changes: 14 additions & 8 deletions test/scripts/lib/find_packages.sh
Expand Up @@ -67,7 +67,9 @@ function findChangedPackages {
done

# Make result unique and filter out non-Go "packages".
CHANGED_PKGS=($(printf "%s\n" "${CHANGED_PKGS[@]}" | sort -u | xargs ${GO_CMD} list 2> /dev/null | tr '\n' ' '))
if [ ${#CHANGED_PKGS[@]} -gt 0 ]; then
CHANGED_PKGS=($(printf "%s\n" "${CHANGED_PKGS[@]}" | sort -u | xargs ${GO_CMD} list 2> /dev/null | tr '\n' ' '))
fi
}

function filterExcludedPackages {
Expand All @@ -81,8 +83,6 @@ function filterExcludedPackages {
fi
done
done

FILTERED_PKGS=("${FILTERED_PKGS[@]}")
}

function calcDepPackages {
Expand All @@ -102,21 +102,27 @@ function calcDepPackages {
printf "Calculating package dependencies ... (${progress}%%)${progressNewline}"
fi

declare testImports=$(${GO_CMD} list -f '{{.TestImports}}' ${pkg} | tr -d '[]' | tr ' ' '\n' | \
declare -a testImports=($(${GO_CMD} list -f '{{.TestImports}}' ${pkg} | tr -d '[]' | tr ' ' '\n' | \
grep "^${REPO}" | \
grep -v "^${REPO}/vendor/" | \
grep -v "^${REPO}/internal/github.com/" | \
grep -v "^${REPO}/third_party/github.com/" | \
sort -u | \
tr '\n' ' ')
tr '\n' ' '))

declare pkgDeps=$(${GO_CMD} list -f '{{.Deps}}' ${pkg} ${testImports} | tr -d '[]' | tr ' ' '\n' | \
declare -a pkgDeps=($(${GO_CMD} list -f '{{.Deps}}' ${pkg} ${testImports[@]} | tr -d '[]' | tr ' ' '\n' | \
grep "^${REPO}" | \
grep -v "^${REPO}/vendor/" | \
sort -u | \
tr '\n' ' ')
tr '\n' ' '))

declare val=$(${GO_CMD} list ${testImports} ${pkgDeps} | sort -u | tr '\n' ' ')
declare -a depsAndImports=(${testImports[@]})
depsAndImports+=(${pkgDeps[@]})

declare val=""
if [ ${#depsAndImports[@]} -gt 0 ]; then
val=$(${GO_CMD} list ${depsAndImports[@]} | sort -u | tr '\n' ' ')
fi
eval "PKGDEPS__${pkg//[-\.\/]/_}=\"${val}\""
done
printf "Calculating package dependencies ... (100%%)\n"
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/lib/linter.sh
Expand Up @@ -20,7 +20,7 @@ function runLinter {
function findChangedLinterPkgs {
findChangedFiles

if [[ "${CHANGED_FILES[@]}" =~ ( |^)(test/fixtures/|test/metadata/|test/scripts/|Makefile( |$)) ]]; then
if [[ "${CHANGED_FILES[@]}" =~ ( |^)(test/fixtures/|test/metadata/|test/scripts/|Makefile( |$)|Gopkg.lock( |$)) ]]; then
echo "Test scripts, fixtures or metadata changed - running all tests"
else
findChangedPackages
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/revoked.sh
Expand Up @@ -58,7 +58,7 @@ if [ "$TEST_CHANGED_ONLY" = true ]; then
findChangedFiles
cd ${PWD}

if [[ "${CHANGED_FILES[@]}" =~ ( |^)(test/fixtures/|test/metadata/|test/scripts/|Makefile( |$)) ]]; then
if [[ "${CHANGED_FILES[@]}" =~ ( |^)(test/fixtures/|test/metadata/|test/scripts/|Makefile( |$)|Gopkg.lock( |$)) ]]; then
echo "Test scripts, fixtures or metadata changed - running all tests"
else
findChangedPackages
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/unit-pkcs11.sh
Expand Up @@ -44,7 +44,7 @@ if [ "$TEST_CHANGED_ONLY" = true ]; then
findChangedFiles
cd ${PWD}

if [[ "${CHANGED_FILES[@]}" =~ ( |^)(test/fixtures/|test/metadata/|test/scripts/|Makefile( |$)) ]]; then
if [[ "${CHANGED_FILES[@]}" =~ ( |^)(test/fixtures/|test/metadata/|test/scripts/|Makefile( |$)|Gopkg.lock( |$)) ]]; then
echo "Test scripts, fixtures or metadata changed - running all tests"
else
findChangedPackages
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/unit.sh
Expand Up @@ -42,7 +42,7 @@ findPackages
if [ "$TEST_CHANGED_ONLY" = true ]; then
findChangedFiles

if [[ "${CHANGED_FILES[@]}" =~ ( |^)(test/fixtures/|test/metadata/|test/scripts/|Makefile( |$)) ]]; then
if [[ "${CHANGED_FILES[@]}" =~ ( |^)(test/fixtures/|test/metadata/|test/scripts/|Makefile( |$)|Gopkg.lock( |$)) ]]; then
echo "Test scripts, fixtures or metadata changed - running all tests"
else
findChangedPackages
Expand Down

0 comments on commit 139bfdf

Please sign in to comment.