-
Notifications
You must be signed in to change notification settings - Fork 8
#744 Group integration tests in an external script #747
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
20f0a9b
workaround for postman
edaba65
failure detection better so can clean up report if successful
076050b
most important docs
e398a2b
always use latest
eb455ae
do a cleanup before running to make sure everything is refreshed.
7634fca
seems to be working now
ebf8689
improve the script some
7f5ba23
change verify to account for commits
5536373
some more tweaks
be725cd
another check for empty file
a021690
shellcheck corrections
16a3138
too many nots
9044f47
more help when things go awry
162682f
more script cleanup to prevent false positives
5cbed33
more cleanup
8ec6fd9
I&T
58955a8
should not be using echo to set status
c6ff807
cleanup json to standard
e4f35d7
I&T
5993f5d
some verify cleanup
12377f4
upgrade the help
dcdcc87
a lucky pass
8409a80
clean up cicd a bit
806db2f
I&T
e03e445
working branch again. lets try in github actions
cdf81ec
ran successfully
6ee7846
record the registry branch revision
1295d25
try again for success
231f097
Merge branch 'develop' into issue_745
al-niessner 0563642
works after merge with develop
415c6e6
second run with no changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,205 @@ | ||
| #! /usr/bin/env bash | ||
| # | ||
| # requires: docker, git, mvn, and shellcheck | ||
| # | ||
| # docker - builds the registry api image, uses compose to run a host of services | ||
| # git clones registry repo | ||
| # jq - bash JSON tool | ||
| # mvn - to build the jar file for the current source registry api source code | ||
| # "shellcheck" - linter to keep this script clean | ||
| # | ||
|
|
||
| build() { | ||
| mvn --quiet clean package | ||
| jar_file="$(find ./service/target/ -maxdepth 1 -regextype posix-extended -regex '.*/registry-api-service-[0-9]+\.[0-9]+\.[0-9]+(-SNAPSHOT)?\.jar')" | ||
| docker build --build-arg api_jar="$jar_file" -t nasapds/registry-api-service:latest -f docker/Dockerfile . | ||
| } | ||
|
|
||
| clean() { | ||
| # shellcheck disable=SC2086 # for correct docker interpretation | ||
| docker compose \ | ||
| --ansi never \ | ||
| --profile int-registry-batch-loader \ | ||
| --project-name registry \ | ||
| down ${IT_CLEANSE:---rmi all} | ||
| } | ||
|
|
||
| deep_archive() { | ||
| cd "$tdir" || return 1 | ||
| python3 -m venv "$tdir"/da | ||
| # shellcheck disable=SC1091 # cannot find dynamically created script | ||
| source "$tdir"/da/bin/activate | ||
| git clone --quiet https://github.com/NASA-PDS/deep-archive.git | ||
| cd deep-archive || return 1 | ||
| pip install . | ||
| pds-deep-registry-archive -u http://localhost:8080 -s PDS_ENG urn:nasa:pds:insight_rad::2.1 --debug | ||
| } | ||
|
|
||
| double_check_logfile() { | ||
| echo "everything looked ok, so double check postman logs" | ||
| [ -s "$1" ] || { echo "$1 is an empty file"; return 1; } | ||
| grep -Eq "[[:space:]]*#[[:space:]]+failure[[:space:]]+detail" "$1" \ | ||
|
nutjob4life marked this conversation as resolved.
|
||
| && { echo "postman log file reported failures" ; return 2; } | ||
| return 0 | ||
| } | ||
|
|
||
| record() { | ||
| cat > last_integration_test.json <<EOF | ||
| { | ||
| "api_gitrev": "$1", | ||
| "reg_gitrev": "$2", | ||
| "status": "$3" | ||
| } | ||
| EOF | ||
| } | ||
|
|
||
| run() { | ||
| cd docker || exit 1 | ||
| ( cd certs || exit 1 ; ./generate-certs.sh ) | ||
| export REG_API_IMAGE=nasapds/registry-api-service:latest | ||
| docker image inspect nasapds/registry-api-service:latest >/dev/null | ||
| echo "launch services" | ||
| docker compose \ | ||
| --ansi never \ | ||
| --profile int-registry-batch-loader \ | ||
| --project-name registry \ | ||
| up --detach --quiet-pull || return 5 | ||
| echo "launch tests" | ||
| if docker compose \ | ||
| --ansi never \ | ||
| --profile int-registry-batch-loader \ | ||
| --project-name registry \ | ||
| run --rm --no-TTY reg-api-integration-test-with-wait | ||
| then | ||
| deep_archive | ||
| status=$? | ||
| else | ||
| status=1 | ||
| fi | ||
| echo "run status: ${status}" | ||
| clean | ||
| # shellcheck disable=SC2086 # because we need to return an int | ||
| return $status | ||
| } | ||
|
|
||
| if [ $# -gt 1 ] | ||
| then | ||
| echo "Usage: $0 [--verify]" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ $# -eq 1 ] && [ "$1" != "--verify" ] | ||
| then | ||
| echo "Error: Invalid argument '$1'" | ||
| echo "Usage: $0 [--verify]" | ||
| exit 1 | ||
| fi | ||
|
|
||
| bdir=$(dirname "$(realpath "$0")") | ||
| rdir=$(realpath "$bdir/../..") | ||
| cd "$rdir" || exit 1 | ||
| api_gitrev=$(git describe --always --abbrev=40 --dirty='+' --exclude '*') | ||
| branchname=$(git branch --show-current) | ||
| branchname=${branchname/issue/api} | ||
| branchname=${branchname/_/-} | ||
| tdir=$(mktemp -d) | ||
| # The EXIT pseudo-signal covers normal exits, errors, and interruptions (Ctrl+C) | ||
| trap 'rm -rf "$tdir"' EXIT | ||
| export tdir | ||
| cd "$tdir" || exit 1 | ||
| git clone --quiet https://github.com/NASA-PDS/registry.git | ||
|
al-niessner marked this conversation as resolved.
|
||
| cd registry || exit 1 | ||
| if git show-ref --verify --quiet refs/remotes/origin/"$branchname" | ||
| then | ||
| git switch "$branchname" | ||
| fi | ||
| echo "registry being used" | ||
| git status | ||
| reg_gitrev=$(git describe --always --abbrev=40 --dirty='+' --exclude '*') | ||
| if [ "$1" == "--verify" ]; then | ||
| echo "Running in VERIFY mode..." | ||
| status=failure | ||
| cd "$tdir" || exit 1 | ||
| record "$api_gitrev" "$reg_gitrev" "$status" | ||
| cd "$rdir" || exit 1 | ||
| test_key=$(jq -r '.api_gitrev' "$bdir"/last_integration_test.json | sed 's/+$//') | ||
| files=$(git diff --name-only -r "$test_key") | ||
| # shellcheck disable=SC2046 # because comparing integers | ||
| if [ $(echo "$files" | wc -l) -eq 1 ] | ||
| then | ||
| if [ "$files" == ".github/workflows/last_integration_test.json" ] | ||
| then | ||
| if [ -s "$files" ] | ||
| then | ||
| # do a one line diff from last test run | ||
| # look at additions or subtractions | ||
| # ignore --- and +++ because those are the filenames | ||
| # ignore the api_gitrev because that must be different | ||
| # count all other changes | ||
| # if there are none, then status is meaningful | ||
| # shellcheck disable=SC2126 # because simpler to understand | ||
| if [ $(git diff -U0 -r "$test_key" | \ | ||
| grep "^[+-]" | \ | ||
| grep -v "^---" | \ | ||
| grep -v "^+++" | \ | ||
| grep -v "api_gitrev" | \ | ||
| wc -l) == 0 ] | ||
| then | ||
| status=$(jq -r '.status' "$bdir"/last_integration_test.json) | ||
| echo "Found the I&T test to be: ${status}" | ||
| else | ||
| git diff -r "$test_key" | ||
| fi | ||
| else | ||
| echo "Reporting file is empty" | ||
| fi | ||
| else | ||
| echo "the file changed was not for I&T: $files" | ||
| fi | ||
| else | ||
| echo "commit contains edits beyond those of last_integration_test.json" | ||
| echo "files changed: $files" | ||
| fi | ||
| if [ "$status" == "failure" ] | ||
| then | ||
| echo | ||
| echo "If you are reading this in the github actions log, then it seems" | ||
| echo "this test cannot verify that this registry-api repository branch" | ||
| echo "has been successfully tested. The first step at resolving this" | ||
| echo "message is to run the script .github/workflows/integration_tests.sh" | ||
| echo "locally. If it is successful, then commit all changes and push." | ||
| echo "Otherwise, fix any problems demonstrated from running the tests," | ||
| echo "then commit and push all changes when the script is successful." | ||
| echo "Once commited, run this script again to generate the single file" | ||
| echo "last_integration_test.json, commit it, and push it." | ||
| echo | ||
| echo "Note: there are timing tests that can cause temporary failures." | ||
| echo " If those failures occur, just run the script again until" | ||
| echo " a success is achived." | ||
| echo | ||
| echo "Note: to determine if the latest commit will pass, run the script" | ||
| echo " with 'integration_tests.sh --verify'" | ||
| else | ||
| echo "Verified tests completed and successful" | ||
| fi | ||
| else | ||
| cd "$rdir" || exit 1 | ||
| clean || exit 2 | ||
| build || exit 3 | ||
| cd "$tdir"/registry || exit 1 | ||
| ( set -o pipefail ; run 2>&1 | tee "$rdir"/integration_tests.rpt.txt ) \ | ||
| && status=success || status=failure | ||
| if [ "$status" == "success" ] | ||
| then | ||
| double_check_logfile "$rdir"/integration_tests.rpt.txt \ | ||
| || status=failure | ||
| else | ||
| echo "docker run or deep archive did not return success" | ||
| fi | ||
| cd "$bdir" || exit 1 | ||
| record "$api_gitrev" "$reg_gitrev" "$status" | ||
| [ "$status" == "success" ] && rm "$rdir"/integration_tests.rpt.txt | ||
| fi | ||
|
|
||
| echo "Status: $status" | ||
| [ "$status" == "success" ] && exit 0 || exit 1 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "api_gitrev": "0563642e7c8e6ff153176adebc188f615db93a0e", | ||
| "reg_gitrev": "4faf4ff0ccafac6b9d4b77acdc395dfe074ef332", | ||
| "status": "success" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.