Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 4 additions & 28 deletions .github/workflows/branch-cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,39 +89,15 @@ jobs:
push: false
load: true
tags: nasapds/registry-api-service:develop
-
name: ∫ Integration tests … hold onto your hats, pardners
run: |
git clone --quiet https://github.com/NASA-PDS/registry.git
cd registry/docker/certs
./generate-certs.sh
cd ..
docker image inspect nasapds/registry-api-service:develop >/dev/null

export COMPOSE_PROJECT_NAME=registry
export REG_API_IMAGE=nasapds/registry-api-service:develop
docker compose \
--ansi never --profile int-registry-batch-loader --project-name ${COMPOSE_PROJECT_NAME} \
up --quiet-pull --detach
echo "===== Docker logs ====="
docker compose logs --no-color
docker compose \
--ansi never --profile int-registry-batch-loader --project-name ${COMPOSE_PROJECT_NAME} \
run --rm --no-TTY reg-api-integration-test-with-wait

-
name: Set up Python 3
uses: actions/setup-python@v6
with:
python-version: '3.13'
name: Install jq
uses: dcarbone/install-jq-action@v3

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

...

Expand Down
205 changes: 205 additions & 0 deletions .github/workflows/integration_tests.sh
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() {
Comment thread
al-niessner marked this conversation as resolved.
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" \
Comment thread
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
Comment thread
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
5 changes: 5 additions & 0 deletions .github/workflows/last_integration_test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"api_gitrev": "0563642e7c8e6ff153176adebc188f615db93a0e",
"reg_gitrev": "4faf4ff0ccafac6b9d4b77acdc395dfe074ef332",
"status": "success"
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,6 @@ application-*.properties

# macOS specific stuff
.DS_Store

# reports to help separate testing from actions due to limited resources
*.rpt.txt
Loading