Skip to content

Commit

Permalink
Merge pull request #435 from yarikoptic/deno-validator
Browse files Browse the repository at this point in the history
Add "master-deno" flavor of validator to use as well
  • Loading branch information
effigies committed Jun 6, 2024
2 parents 12ee355 + 4e04a68 commit 09df87f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 10 deletions.
28 changes: 27 additions & 1 deletion .github/workflows/validate_datasets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
fail-fast: false
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
bids-validator: [master, stable]
bids-validator: [master, stable, master-deno]

runs-on: ${{ matrix.platform }}

Expand All @@ -33,6 +33,7 @@ jobs:
- uses: actions/checkout@v4

- name: Set up Node.js
if: "matrix.bids-validator == 'stable' || matrix.bids-validator == 'master'"
uses: actions/setup-node@v4
with:
node-version: 18
Expand Down Expand Up @@ -60,13 +61,32 @@ jobs:
bash -c "npm install -g bids-validator-*.tgz"
popd
- uses: denoland/setup-deno@v1
if: "matrix.bids-validator == 'master-deno'"
with:
deno-version: v1.x

- name: Install BIDS validator (master deno build)
if: "matrix.bids-validator == 'master-deno'"
run: |
LOCAL_BIN=$HOME/.local/bin
VALIDATOR=$LOCAL_BIN/bids-validator
mkdir -p $LOCAL_BIN
export PATH="$LOCAL_BIN:$PATH"
echo PATH="$PATH" >> $GITHUB_ENV
echo -e '#!/usr/bin/env'" -S deno run --allow-read --allow-write --allow-env --allow-net --allow-run\nimport 'https://github.com/bids-standard/bids-validator/raw/master/bids-validator/src/bids-validator.ts'" > $VALIDATOR
chmod +x $VALIDATOR
bids-validator --version
shell: bash

- name: Display versions and environment information
run: |
echo $TZ
date
echo "npm"; npm --version
echo "node"; node --version
echo "bids-validator"; bids-validator --version
shell: bash

- name: Check that no large files are present
if: "matrix.bids-validator == 'stable'"
Expand All @@ -83,6 +103,12 @@ jobs:
fi
shell: bash

- name: Mark to be skipped some examples for a deno based
if: "matrix.bids-validator == 'master-deno'"
run: |
touch {ds000117,ds000246,ds000247,ds000248,eeg_ds003645s_hed_demo,ieeg_motorMiller2007,ieeg_visual,7t_trt,ds102,fnirs_automaticity,genetics_ukbb,ieeg_epilepsy,ieeg_epilepsyNWB}/.SKIP_VALIDATION
shell: bash

- name: Validate all BIDS datasets using bids-validator
run: |
cat ./run_tests.sh
Expand Down
48 changes: 39 additions & 9 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
#!/usr/bin/env bash

rc=0;
failed=

which bids-validator
if bids-validator --help | grep -q -e '--config'; then
VALIDATOR_SUPPORTS_CONFIG=yes
else
VALIDATOR_SUPPORTS_CONFIG=
fi

for i in $(ls -d */ | grep -v node_modules); do
echo "Validating dataset" $i
echo -n "Validating dataset $i: "

if [ -f ${i%%/}/.SKIP_VALIDATION ]; then
echo "Skipping validation for ${i%%/}"
echo "skipping validation"
continue
fi

Expand All @@ -14,18 +22,40 @@ for i in $(ls -d */ | grep -v node_modules); do
CMD="bids-validator ${i%%/} $VALIDATOR_ARGS"

# Use default configuration unless overridden
if [ ! -f ${i%%/}/.bids-validator-config.json ]; then
CMD="$CMD -c $PWD/bidsconfig.json"
if [ -n "$VALIDATOR_SUPPORTS_CONFIG" ]; then
if [ ! -f ${i%%/}/.bids-validator-config.json ]; then
CMD="$CMD -c $PWD/bidsconfig.json"
fi
else
# with new one we do not have config so let's get --json and exclude some using jq
CMD="$CMD --json"
fi

# Ignore NIfTI headers except for synthetic dataset
if [ $i != "synthetic/" ]; then
CMD="$CMD --ignoreNiftiHeaders"
else
echo "Validating NIfTI headers for dataset" $i
echo "validating NIfTI headers. "
fi

echo $CMD
$CMD || rc=$?
echo "Running " $CMD

if [ -n "$VALIDATOR_SUPPORTS_CONFIG" ]; then
$CMD || failed+=" $i"
else
# exit code is not returned correctly anyways and for the best since we need to ignore
# ref: https://github.com/bids-standard/bids-validator/issues/1909
# NOTE: limit to 1 file per error to not flood screen!
errors=$($CMD 2>/dev/null \
| jq '(.issues | map(select(.severity == "error" and .key != "EMPTY_FILE"))) | map(.files_1 = (.files | if length > 0 then .[0:1] else empty end) | del(.files)) | if length > 0 then . else empty end' \
)
if [ -n "$errors" ]; then
echo -e "$errors" | sed -e 's,^, ,g'
failed+=" $i"
fi
fi
done
exit $rc;
if [ -n "$failed" ]; then
echo "Datasets failed validation: $failed"
exit 1
fi

0 comments on commit 09df87f

Please sign in to comment.