diff --git a/.github/workflows/validate_datasets.yml b/.github/workflows/validate_datasets.yml index d90ee7635..0bc1f3df9 100644 --- a/.github/workflows/validate_datasets.yml +++ b/.github/workflows/validate_datasets.yml @@ -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 }} @@ -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 @@ -60,6 +61,24 @@ 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 @@ -67,6 +86,7 @@ jobs: 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'" @@ -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 diff --git a/run_tests.sh b/run_tests.sh index 3e12d0df9..00ba3a2bd 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -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 @@ -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