Skip to content

ENH: add ability to test examples PR against PR in bids-specification #1415

ENH: add ability to test examples PR against PR in bids-specification

ENH: add ability to test examples PR against PR in bids-specification #1415

name: validate_datasets
on:
push:
branches: ['**']
pull_request:
types: [opened, synchronize, reopened, edited]
branches: ['**']
create:
branches: [master]
tags: ['**']
schedule:
- cron: "0 4 * * 1"
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
defaults:
run:
shell: bash
jobs:
# Prepare the matrix dynamically based on whether a bids-specification PR is referenced
prepare-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
bids_pr: ${{ steps.find-pr.outputs.pr_number }}
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0 # Get full history for commit message scanning
- name: Check for bids-specification PR reference
id: find-pr
run: |
# Check PR description if this is a PR
if [ "${{ github.event_name }}" == "pull_request" ]; then
cat << 'EOF' > /tmp/pr_body.txt
${{ github.event.pull_request.body }}
EOF
PR_NUM=$(grep -oP 'bids-specification-pr:\s*(https://github\.com/bids-standard/bids-specification/pulls?/)*\K[0-9]+' /tmp/pr_body.txt | head -1 || true)
[ -n "$PR_NUM" ] && echo "pr_number=$PR_NUM" >> $GITHUB_OUTPUT || :
fi
- name: Set matrix
id: set-matrix
run: |
EXTRA_ITEM=''
if [ -n "${{ steps.find-pr.outputs.pr_number }}" ]; then
EXTRA_ITEM=', "bids-pr"'
fi
echo "matrix=[\"stable\", \"main\", \"dev\", \"legacy\"${EXTRA_ITEM}]" >> $GITHUB_OUTPUT
build:
needs: prepare-matrix
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
bids-validator: ${{ fromJson(needs.prepare-matrix.outputs.matrix) }}
runs-on: ${{ matrix.platform }}
env:
BIDS_PR: ${{ needs.prepare-matrix.outputs.bids_pr }}
TZ: Europe/Berlin
FORCE_COLOR: 1
steps:
- uses: actions/checkout@v5
- name: Set up Node.js
if: matrix.bids-validator == 'legacy'
uses: actions/setup-node@v4
with:
node-version: 22
- name: Set cache name
if: matrix.bids-validator == 'legacy'
run:
echo "MONTH=$( date +%Y%m )" >> $GITHUB_ENV
- name: Load npm cache
if: matrix.bids-validator == 'legacy'
uses: actions/cache@v4
with:
path: ~/.npm
key: npm-${{ runner.os }}-${{ env.MONTH }}
- uses: denoland/setup-deno@v2
if: matrix.bids-validator != 'legacy'
with:
deno-version: v2.x
- name: Install BIDS validator (stable)
if: matrix.bids-validator == 'stable'
run: |
deno install -Agf -n bids-validator jsr:@bids/validator
- name: Install BIDS validator (main)
if: matrix.bids-validator == 'main' || matrix.bids-validator == 'bids-pr'
run: |
# If unmerged validator PRs are needed for testing, you can use
# https://github.com/<FORK>/bids-validator/raw/<BRANCH>/bids-validator/src/bids-validator.ts
deno install -Agf https://github.com/bids-standard/bids-validator/raw/deno-build/bids-validator.js
- name: Install BIDS validator (dev)
if: matrix.bids-validator == 'dev'
run: |
git clone -b dev https://github.com/bids-standard/bids-validator/ ../bids-validator
cd ../bids-validator
deno compile -A -o $HOME/.deno/bin/bids-validator src/bids-validator.ts
- name: Install BIDS validator (legacy)
if: "matrix.bids-validator == 'legacy'"
run: |
npm install -g bids-validator
- name: Display versions and environment information
run: |
echo $TZ
date
which deno && echo "deno\n----" && deno --version || true
echo "node\n----"; node --version
echo "npm\n----"; npm --version
echo "bids-validator"; bids-validator --version
- name: Check that no large files are present
if: "matrix.bids-validator == 'stable'"
run: |
echo "Checking for big files ..."
found=`find . -not -path "./.git*" -type f -size +500k`
if [ "$found" == "" ]
then
echo "No big files present, great!"
else
echo "Found big files:"
echo "$found"
exit 1;
fi
- name: Skip legacy validation for post-legacy datasets
run: for DS in mrs_* dwi_deriv pet006 pheno004 volume_timing; do touch $DS/.SKIP_VALIDATION; done
if: matrix.bids-validator == 'legacy'
- name: Skip stable validation for datasets with unreleased validator features
# Replace ${EMPTY} with dataset patterns, when this is needed
# Reset to "for DS in ${EMPTY}; ..." after a validator release
run: for DS in ${EMPTY}; do touch $DS/.SKIP_VALIDATION; done
if: matrix.bids-validator == 'stable'
- name: Skip main validation for datasets with unreleased spec features
# Replace ${EMPTY} with dataset patterns, when this is needed
# Reset to "for DS in ${EMPTY}; ..." after a spec release
run: for DS in dwi_deriv pheno004; do touch $DS/.SKIP_VALIDATION; done
if: matrix.bids-validator != 'dev'
- name: Set BIDS_SCHEMA variable for dev version
if: matrix.bids-validator == 'dev'
# When proposing new features, schema changes may be necessary.
# Update this URL to the schema.json from PRs to the spec, when needed.
# If this variable is unset, dev will generally track the latest development
# release of https://jsr.io/@bids/schema
run: echo BIDS_SCHEMA=https://bids-specification.readthedocs.io/en/latest/schema.json >> $GITHUB_ENV
- name: Set BIDS_SCHEMA variable for bids-pr version
if: matrix.bids-validator == 'bids-pr'
# Use the readthedocs PR preview build for the schema
run: |
echo "Using schema from bids-specification PR #${{ env.BIDS_PR }}"
echo BIDS_SCHEMA=https://bids-specification--${{ env.BIDS_PR }}.org.readthedocs.build/en/${{ env.BIDS_PR }}/schema.json >> $GITHUB_ENV
- name: Validate all BIDS datasets using bids-validator
run: |
cat ./run_tests.sh
./run_tests.sh