-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fdc03af
commit 8db7e09
Showing
2 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,67 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Checking the results of running the docker commands | ||
|
||
# Define expected results | ||
EXPECTED_FILES=("result.json") | ||
EXPECTED_CANOPYCOVER_VALUES=(99.8 20.9) | ||
|
||
# What folder are we looking in for outputs | ||
if [[ ! "${1}" == "" ]]; then | ||
TARGET_FOLDER="${1}" | ||
else | ||
TARGET_FOLDER="./outputs" | ||
fi | ||
|
||
# What our target file to read is | ||
if [[ ! "${2}" == "" ]]; then | ||
CHECK_FILE="${2}" | ||
else | ||
CHECK_FILE="canopycover.csv" | ||
fi | ||
EXPECTED_FILES+=("${CHECK_FILE}") | ||
|
||
# Check if expected files are found | ||
for i in $(seq 0 $(( ${#EXPECTED_FILES[@]} - 1 ))) | ||
do | ||
if [[ ! -f "${TARGET_FOLDER}/${EXPECTED_FILES[$i]}" ]]; then | ||
echo "Expected file ${EXPECTED_FILES[$i]} is missing" | ||
exit 10 | ||
fi | ||
done | ||
|
||
# Check the results of the canopy cover calculation | ||
RESULT_VALUES=(`gawk ' | ||
BEGIN { | ||
FPAT = "([^,]+)|(\"[^\"]+\")" | ||
} | ||
{ | ||
if ($1 != "local_datetime") { # Skipping the header line | ||
printf("%s\n", $2) | ||
} | ||
} | ||
END { | ||
} | ||
' "${TARGET_FOLDER}/${CHECK_FILE}"`) | ||
|
||
echo "Result counts: ${#EXPECTED_CANOPYCOVER_VALUES[@]} vs ${#RESULT_VALUES[@]}" | ||
if [[ ${#EXPECTED_CANOPYCOVER_VALUES[@]} != ${#RESULT_VALUES[@]} ]]; then | ||
echo "Number of results found in file (${#RESULT_VALUES[@]}) don't match expected count (${#EXPECTED_CANOPYCOVER_VALUES[@]})" | ||
if [[ ${#RESULT_VALUES[@]} > 0 ]]; then | ||
for i in $(seq 0 $(( ${#RESULT_VALUES[@]} - 1 ))) | ||
do | ||
echo "${i}: ${RESULT_VALUES[$i]}" | ||
done | ||
fi | ||
exit 20 | ||
fi | ||
|
||
for i in $(seq 0 $(( ${#EXPECTED_CANOPYCOVER_VALUES[@]} - 1 ))) | ||
do | ||
if [[ "${EXPECTED_CANOPYCOVER_VALUES[$i]}" == "${RESULT_VALUES[$i]}" ]]; then | ||
echo "Values for index ${i} match: '${RESULT_VALUES[$i]}' '${EXPECTED_CANOPYCOVER_VALUES[$i]}'" | ||
else | ||
echo "Result value for index ${i}: '${RESULT_VALUES[$i]}' doesn't match expected: '${EXPECTED_CANOPYCOVER_VALUES[$i]}'" | ||
exit 30 | ||
fi | ||
done |
This file contains 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,69 @@ | ||
name: Testing Docker image | ||
on: | ||
push: | ||
branches: | ||
- master | ||
- develop | ||
pull_request: | ||
branches: | ||
- master | ||
- develop | ||
tags: | ||
- v* | ||
schedule: | ||
# Every 01:00 Sunday re-run the test on the main branch | ||
- cron: '0 1 * * 0' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
docker_testing: | ||
runs-on: ubuntu-latest | ||
name: Running Docker testing | ||
steps: | ||
- name: Fetch source code | ||
uses: actions/checkout@v2 | ||
- name: Create folders | ||
run: | | ||
mkdir ./inputs && chmod 777 ./inputs | ||
mkdir ./outputs && chmod 777 ./outputs | ||
- name: List folder contents | ||
run: | | ||
echo "Current folder" && ls -la | ||
echo "test_data" && ls -l ./test_data | ||
- name: Copy testing data files | ||
run: | | ||
cp "${PWD}/test_data"/* "${PWD}/inputs/" | ||
echo "inputs" && ls -l ./inputs | ||
- name: Folder contents | ||
run: | | ||
echo "Current folder" && ls -l | ||
echo "Inputs folder" && ls -l ./inputs | ||
echo "Outputs folder" && ls -l ./outputs | ||
- name: Build docker image | ||
run: docker build -t canopycover_test:latest ./ | ||
- name: Compress docker image | ||
run: docker save canopycover_test:latest | gzip -7 -c - > canopycover_test_image.tar.gz | ||
- name: Upload docker image | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: canopycover_test_image | ||
path: canopycover_test_image.tar.gz | ||
- name: Run docker test | ||
run: docker run --rm -v "${PWD}/inputs:/inputs" -v "${PWD}/outputs:/outputs" canopycover_test:latest --working_space /outputs --metadata /inputs/meta.yaml /inputs/rgb_17_7_W.tif /inputs/mask_1.tif | ||
- name: Output folder contents | ||
run: echo "Outputs folder" && ls -l ./outputs | ||
- name: Check outputs | ||
run: | | ||
cat outputs/canopycover.csv | ||
chmod +x "./.github/workflows/docker_test_check_rgb.sh" | ||
"./.github/workflows/docker_test_check_rgb.sh" | ||
artifact_cleanup: | ||
runs-on: ubuntu-latest | ||
needs: [docker_testing] | ||
name: Cleanup artifacts upon success | ||
steps: | ||
- name: Remove docker artifact | ||
uses: geekyeggo/delete-artifact@v1 | ||
with: | ||
name: canopycover_test_image |