diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 000000000..d6d514ec6 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,13 @@ + + +- BIDS Specification PR: NONE +- BIDS Validator PR: NONE +- TODOs: + - [ ] ... + + + +See the [CONTRIBUTING](https://github.com/bids-standard/bids-examples/blob/master/CONTRIBUTING.md) guide. Specifically: + +- Please keep the title of your Pull Request (PR) short but informative - it will appear in the changelog. + diff --git a/.github/workflows/validate_datasets.yml b/.github/workflows/validate_datasets.yml index d92b67f0c..12f45900a 100644 --- a/.github/workflows/validate_datasets.yml +++ b/.github/workflows/validate_datasets.yml @@ -4,6 +4,7 @@ on: push: branches: ['**'] pull_request: + types: [opened, synchronize, reopened, edited] branches: ['**'] create: branches: [master] @@ -21,16 +22,54 @@ defaults: 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 }} + spec_pr: ${{ steps.find-pr.outputs.spec_pr }} + val_pr: ${{ steps.find-pr.outputs.val_pr }} + 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 + SPEC_PR=$(grep -oP 'BIDS Specification PR:\s*(https://github\.com/bids-standard/bids-specification/pulls?/|bids-standard/bids-specification#)*\K[0-9]+' /tmp/pr_body.txt | head -1 || true) + [ -n "$SPEC_PR" ] && echo "spec_pr=$SPEC_PR" >> $GITHUB_OUTPUT || : + VAL_PR=$(grep -oP 'BIDS Validator PR:\s*(https://github\.com/bids-standard/bids-validator/pulls?/|bids-standard/bids-validator#)*\K[0-9]+' /tmp/pr_body.txt | head -1 || true) + [ -n "$VAL_PR" ] && echo "val_pr=$VAL_PR" >> $GITHUB_OUTPUT || : + fi + + - name: Set matrix + id: set-matrix + run: | + EXTRA_ITEM='' + if [ -n "${{ steps.find-pr.outputs.spec_pr }}${{ steps.find-pr.outputs.val_pr }}" ]; then + EXTRA_ITEM=', "dev-prs"' + 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: [stable, main, dev, legacy] + bids-validator: ${{ fromJson(needs.prepare-matrix.outputs.matrix) }} runs-on: ${{ matrix.platform }} env: + SPEC_PR: ${{ needs.prepare-matrix.outputs.spec_pr }} + VAL_PR: ${{ needs.prepare-matrix.outputs.val_pr }} TZ: Europe/Berlin FORCE_COLOR: 1 @@ -73,7 +112,7 @@ jobs: 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' + if: ( matrix.bids-validator == 'dev' ) || ( matrix.bids-validator == 'dev-prs' && env.VAL_PR == '' ) run: | git clone -b dev https://github.com/bids-standard/bids-validator/ ../bids-validator cd ../bids-validator @@ -84,6 +123,25 @@ jobs: run: | npm install -g bids-validator + - name: Install BIDS validator (dev-prs with VAL_PR) + if: matrix.bids-validator == 'dev-prs' && env.VAL_PR != '' + shell: bash + env: + GH_TOKEN: ${{ github.token }} + run: | + # Fetch PR info using gh cli (handles auth automatically) + fork_url=$(gh api repos/bids-standard/bids-validator/pulls/${{ env.VAL_PR }} --jq '.head.repo.html_url') + branch=$(gh api repos/bids-standard/bids-validator/pulls/${{ env.VAL_PR }} --jq '.head.ref') + echo "I: Received fork_url=$fork_url branch=$branch" + if [ "$fork_url" = "null" ] || [ -z "$fork_url" ]; then + echo "E: Failed to get PR info for VAL_PR=${{ env.VAL_PR }}" + exit 1 + fi + # Perform the same installation as in "dev" + git clone -b "$branch" "$fork_url" ../bids-validator + cd ../bids-validator + deno compile -A -o $HOME/.deno/bin/bids-validator src/bids-validator.ts + - name: Display versions and environment information run: | echo $TZ @@ -131,6 +189,13 @@ jobs: # 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 dev-prs version + if: matrix.bids-validator == 'dev-prs' && env.SPEC_PR != '' + # Use the readthedocs PR preview build for the schema + run: | + echo "Using schema from bids-specification PR #${{ env.SPEC_PR }}" + echo BIDS_SCHEMA=https://bids-specification--${{ env.SPEC_PR }}.org.readthedocs.build/en/${{ env.SPEC_PR }}/schema.json >> $GITHUB_ENV + - name: Validate all BIDS datasets using bids-validator run: | cat ./run_tests.sh