Skip to content

Commit 4ba436e

Browse files
authored
#744 Group integration tests in an external script (#747)
* Pulled the integration tests from github actions to local script 1. github action machines are tiny (2GB mem) and tests desire a bit more with opensearch running in a container. 2. the deep archive checks require the opensearch be up and running with the registry-api. * fixed starting point 1. remove all of the existing docker images that are used for testing 2 reload the docker images to make sure they are the latest that have been published 3. if the branch name in registry-api is something like issue-1234 then the script will use the branch api-1234 in the registry repository. It will use develop if the more specific branch does not exist.
1 parent 5396c8f commit 4ba436e

4 files changed

Lines changed: 217 additions & 28 deletions

File tree

.github/workflows/branch-cicd.yaml

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -89,39 +89,15 @@ jobs:
8989
push: false
9090
load: true
9191
tags: nasapds/registry-api-service:develop
92-
-
93-
name: ∫ Integration tests … hold onto your hats, pardners
94-
run: |
95-
git clone --quiet https://github.com/NASA-PDS/registry.git
96-
cd registry/docker/certs
97-
./generate-certs.sh
98-
cd ..
99-
docker image inspect nasapds/registry-api-service:develop >/dev/null
100-
101-
export COMPOSE_PROJECT_NAME=registry
102-
export REG_API_IMAGE=nasapds/registry-api-service:develop
103-
docker compose \
104-
--ansi never --profile int-registry-batch-loader --project-name ${COMPOSE_PROJECT_NAME} \
105-
up --quiet-pull --detach
106-
echo "===== Docker logs ====="
107-
docker compose logs --no-color
108-
docker compose \
109-
--ansi never --profile int-registry-batch-loader --project-name ${COMPOSE_PROJECT_NAME} \
110-
run --rm --no-TTY reg-api-integration-test-with-wait
11192

11293
-
113-
name: Set up Python 3
114-
uses: actions/setup-python@v6
115-
with:
116-
python-version: '3.13'
94+
name: Install jq
95+
uses: dcarbone/install-jq-action@v3
11796

11897
-
119-
name: ∫ Test PDS Deep Archive compatibility
98+
name: ∫ Integration and deep archive tests … hold onto your hats, pardners
12099
run: |
121-
git clone --quiet https://github.com/NASA-PDS/deep-archive.git
122-
cd deep-archive
123-
pip install .
124-
pds-deep-registry-archive -u http://localhost:8080 -s PDS_ENG urn:nasa:pds:insight_rad::2.1 --debug
100+
.github/workflows/integration_tests.sh --verify
125101
126102
...
127103

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
#! /usr/bin/env bash
2+
#
3+
# requires: docker, git, mvn, and shellcheck
4+
#
5+
# docker - builds the registry api image, uses compose to run a host of services
6+
# git clones registry repo
7+
# jq - bash JSON tool
8+
# mvn - to build the jar file for the current source registry api source code
9+
# "shellcheck" - linter to keep this script clean
10+
#
11+
12+
build() {
13+
mvn --quiet clean package
14+
jar_file="$(find ./service/target/ -maxdepth 1 -regextype posix-extended -regex '.*/registry-api-service-[0-9]+\.[0-9]+\.[0-9]+(-SNAPSHOT)?\.jar')"
15+
docker build --build-arg api_jar="$jar_file" -t nasapds/registry-api-service:latest -f docker/Dockerfile .
16+
}
17+
18+
clean() {
19+
# shellcheck disable=SC2086 # for correct docker interpretation
20+
docker compose \
21+
--ansi never \
22+
--profile int-registry-batch-loader \
23+
--project-name registry \
24+
down ${IT_CLEANSE:---rmi all}
25+
}
26+
27+
deep_archive() {
28+
cd "$tdir" || return 1
29+
python3 -m venv "$tdir"/da
30+
# shellcheck disable=SC1091 # cannot find dynamically created script
31+
source "$tdir"/da/bin/activate
32+
git clone --quiet https://github.com/NASA-PDS/deep-archive.git
33+
cd deep-archive || return 1
34+
pip install .
35+
pds-deep-registry-archive -u http://localhost:8080 -s PDS_ENG urn:nasa:pds:insight_rad::2.1 --debug
36+
}
37+
38+
double_check_logfile() {
39+
echo "everything looked ok, so double check postman logs"
40+
[ -s "$1" ] || { echo "$1 is an empty file"; return 1; }
41+
grep -Eq "[[:space:]]*#[[:space:]]+failure[[:space:]]+detail" "$1" \
42+
&& { echo "postman log file reported failures" ; return 2; }
43+
return 0
44+
}
45+
46+
record() {
47+
cat > last_integration_test.json <<EOF
48+
{
49+
"api_gitrev": "$1",
50+
"reg_gitrev": "$2",
51+
"status": "$3"
52+
}
53+
EOF
54+
}
55+
56+
run() {
57+
cd docker || exit 1
58+
( cd certs || exit 1 ; ./generate-certs.sh )
59+
export REG_API_IMAGE=nasapds/registry-api-service:latest
60+
docker image inspect nasapds/registry-api-service:latest >/dev/null
61+
echo "launch services"
62+
docker compose \
63+
--ansi never \
64+
--profile int-registry-batch-loader \
65+
--project-name registry \
66+
up --detach --quiet-pull || return 5
67+
echo "launch tests"
68+
if docker compose \
69+
--ansi never \
70+
--profile int-registry-batch-loader \
71+
--project-name registry \
72+
run --rm --no-TTY reg-api-integration-test-with-wait
73+
then
74+
deep_archive
75+
status=$?
76+
else
77+
status=1
78+
fi
79+
echo "run status: ${status}"
80+
clean
81+
# shellcheck disable=SC2086 # because we need to return an int
82+
return $status
83+
}
84+
85+
if [ $# -gt 1 ]
86+
then
87+
echo "Usage: $0 [--verify]"
88+
exit 1
89+
fi
90+
91+
if [ $# -eq 1 ] && [ "$1" != "--verify" ]
92+
then
93+
echo "Error: Invalid argument '$1'"
94+
echo "Usage: $0 [--verify]"
95+
exit 1
96+
fi
97+
98+
bdir=$(dirname "$(realpath "$0")")
99+
rdir=$(realpath "$bdir/../..")
100+
cd "$rdir" || exit 1
101+
api_gitrev=$(git describe --always --abbrev=40 --dirty='+' --exclude '*')
102+
branchname=$(git branch --show-current)
103+
branchname=${branchname/issue/api}
104+
branchname=${branchname/_/-}
105+
tdir=$(mktemp -d)
106+
# The EXIT pseudo-signal covers normal exits, errors, and interruptions (Ctrl+C)
107+
trap 'rm -rf "$tdir"' EXIT
108+
export tdir
109+
cd "$tdir" || exit 1
110+
git clone --quiet https://github.com/NASA-PDS/registry.git
111+
cd registry || exit 1
112+
if git show-ref --verify --quiet refs/remotes/origin/"$branchname"
113+
then
114+
git switch "$branchname"
115+
fi
116+
echo "registry being used"
117+
git status
118+
reg_gitrev=$(git describe --always --abbrev=40 --dirty='+' --exclude '*')
119+
if [ "$1" == "--verify" ]; then
120+
echo "Running in VERIFY mode..."
121+
status=failure
122+
cd "$tdir" || exit 1
123+
record "$api_gitrev" "$reg_gitrev" "$status"
124+
cd "$rdir" || exit 1
125+
test_key=$(jq -r '.api_gitrev' "$bdir"/last_integration_test.json | sed 's/+$//')
126+
files=$(git diff --name-only -r "$test_key")
127+
# shellcheck disable=SC2046 # because comparing integers
128+
if [ $(echo "$files" | wc -l) -eq 1 ]
129+
then
130+
if [ "$files" == ".github/workflows/last_integration_test.json" ]
131+
then
132+
if [ -s "$files" ]
133+
then
134+
# do a one line diff from last test run
135+
# look at additions or subtractions
136+
# ignore --- and +++ because those are the filenames
137+
# ignore the api_gitrev because that must be different
138+
# count all other changes
139+
# if there are none, then status is meaningful
140+
# shellcheck disable=SC2126 # because simpler to understand
141+
if [ $(git diff -U0 -r "$test_key" | \
142+
grep "^[+-]" | \
143+
grep -v "^---" | \
144+
grep -v "^+++" | \
145+
grep -v "api_gitrev" | \
146+
wc -l) == 0 ]
147+
then
148+
status=$(jq -r '.status' "$bdir"/last_integration_test.json)
149+
echo "Found the I&T test to be: ${status}"
150+
else
151+
git diff -r "$test_key"
152+
fi
153+
else
154+
echo "Reporting file is empty"
155+
fi
156+
else
157+
echo "the file changed was not for I&T: $files"
158+
fi
159+
else
160+
echo "commit contains edits beyond those of last_integration_test.json"
161+
echo "files changed: $files"
162+
fi
163+
if [ "$status" == "failure" ]
164+
then
165+
echo
166+
echo "If you are reading this in the github actions log, then it seems"
167+
echo "this test cannot verify that this registry-api repository branch"
168+
echo "has been successfully tested. The first step at resolving this"
169+
echo "message is to run the script .github/workflows/integration_tests.sh"
170+
echo "locally. If it is successful, then commit all changes and push."
171+
echo "Otherwise, fix any problems demonstrated from running the tests,"
172+
echo "then commit and push all changes when the script is successful."
173+
echo "Once commited, run this script again to generate the single file"
174+
echo "last_integration_test.json, commit it, and push it."
175+
echo
176+
echo "Note: there are timing tests that can cause temporary failures."
177+
echo " If those failures occur, just run the script again until"
178+
echo " a success is achived."
179+
echo
180+
echo "Note: to determine if the latest commit will pass, run the script"
181+
echo " with 'integration_tests.sh --verify'"
182+
else
183+
echo "Verified tests completed and successful"
184+
fi
185+
else
186+
cd "$rdir" || exit 1
187+
clean || exit 2
188+
build || exit 3
189+
cd "$tdir"/registry || exit 1
190+
( set -o pipefail ; run 2>&1 | tee "$rdir"/integration_tests.rpt.txt ) \
191+
&& status=success || status=failure
192+
if [ "$status" == "success" ]
193+
then
194+
double_check_logfile "$rdir"/integration_tests.rpt.txt \
195+
|| status=failure
196+
else
197+
echo "docker run or deep archive did not return success"
198+
fi
199+
cd "$bdir" || exit 1
200+
record "$api_gitrev" "$reg_gitrev" "$status"
201+
[ "$status" == "success" ] && rm "$rdir"/integration_tests.rpt.txt
202+
fi
203+
204+
echo "Status: $status"
205+
[ "$status" == "success" ] && exit 0 || exit 1
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"api_gitrev": "0563642e7c8e6ff153176adebc188f615db93a0e",
3+
"reg_gitrev": "4faf4ff0ccafac6b9d4b77acdc395dfe074ef332",
4+
"status": "success"
5+
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,6 @@ application-*.properties
8787

8888
# macOS specific stuff
8989
.DS_Store
90+
91+
# reports to help separate testing from actions due to limited resources
92+
*.rpt.txt

0 commit comments

Comments
 (0)