diff --git a/.github/workflows/collect_data.yml b/.github/workflows/collect_data.yml new file mode 100644 index 00000000..b2169bd0 --- /dev/null +++ b/.github/workflows/collect_data.yml @@ -0,0 +1,67 @@ +name: Collect Data + +on: + workflow_dispatch: + workflow_call: + inputs: + data_directory: + type: string + required: false + default: /tmp/data/petprep_test_data + derivatives: + type: string + required: false + default: "petprep freesurfer smriprep" + outputs: + data_directory: + description: 'Path to "cached" data collected with `collect_test_data.py`' + value: ${{ inputs.data_directory }} +env: + DATA_DIR: ${{ inputs.data_directory }} + DERIVATIVES: ${{ inputs.derivatives }} + +jobs: + collect-data: + outputs: + data_directory: ${{ env.DATA_DIR }} + runs-on: local + steps: + - name: Checkout repository + uses: actions/checkout@v5 + with: + fetch-depth: 200 + fetch-tags: true + + - name: Check if data directory exists and has data + id: check-data + run: | + if [ -d "$DATA_DIR" ] && [ -n "$(ls -A $DATA_DIR 2>/dev/null)" ]; then + echo "Data directory exists and contains data, skipping collection" + echo "skip_collection=true" >> $GITHUB_OUTPUT + else + echo "Data directory is empty or does not exist, re-downloading data" + echo "skip_collection=false" >> $GITHUB_OUTPUT + # Clean up empty directory if it exists + if [ -d "$DATA_DIR" ]; then + echo "Removing empty data directory" + rm -rf "$DATA_DIR" + fi + fi + + - name: Install uv + run: | + curl -LsSf https://astral.sh/uv/install.sh | sh + echo "$HOME/.cargo/bin" >> $GITHUB_PATH + + - name: Setup Git for DataLad + if: steps.check-data.outputs.skip_collection != 'true' + run: | + # Configure Git for DataLad + git config --global user.name "GitHub Actions" + git config --global user.email "actions@github.com" + + - name: Collect data + if: steps.check-data.outputs.skip_collection != 'true' + run: | + # Collect the data + uv run scripts/collect_test_data.py -o "$DATA_DIR" -d $DERIVATIVES diff --git a/.github/workflows/run_petprep.yml b/.github/workflows/run_petprep.yml new file mode 100644 index 00000000..b79672a5 --- /dev/null +++ b/.github/workflows/run_petprep.yml @@ -0,0 +1,77 @@ +name: Run PETPREP + +on: + workflow_dispatch: + push: + branches: [ "main" ] + tags: "*" + pull_request: + +env: + # for local/self hosted runners one can assume that the + FREESURFER_HOME: /usr/local/freesurfer/7.4.1 + FSLDIR: /opt/conda/envs/petprep + FSL_OUTPUT_TYPE: NIFTI_GZ + AFNI_PATH: /opt/afni-latest + FSL_PATH: /opt/conda/envs/petprep/share/fsl/bin + ANTS_PATH: /opt/ants-2.6.2/bin + WORKBENCH_PATH: /opt/workbench/exe_linux64 + +jobs: + collect-data: + uses: ./.github/workflows/collect_data.yml + + run-tests: + needs: collect-data + runs-on: local + env: + DATA_DIR: ${{ needs.collect-data.outputs.data_directory }} + steps: + - name: Checkout repository + uses: actions/checkout@v5 + with: + fetch-depth: 200 + fetch-tags: true + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install uv + run: | + curl -LsSf https://astral.sh/uv/install.sh | sh + echo "$HOME/.cargo/bin" >> $GITHUB_PATH + + - name: Build and Install PETPREP + run: | + uv build + pip install dist/*.whl --force-reinstall + + - name: Check petprep is installed + run: | + which petprep + petprep --version + + - name: Verify test data exists + run: | + if [ ! -d "$DATA_DIR" ] || [ -z "$(ls -A $DATA_DIR 2>/dev/null)" ]; then + echo "Error: Test data directory is empty or missing" + exit 1 + fi + echo "Test data verified at $DATA_DIR" + ls -la "$DATA_DIR" + + - name: Run petprep + run: | + source "${FREESURFER_HOME}/SetUpFreeSurfer.sh" + export PATH="${AFNI_PATH}:${PATH}" + export PATH="${FSL_PATH}:${PATH}" + export PATH="${ANTS_PATH}:${PATH}" + export PATH="${WORKBENCH_PATH}:${PATH}" + export FSLDIR="${FSLDIR}" + export FSL_OUTPUT_TYPE="${FSL_OUTPUT_TYPE}" + petprep "${DATA_DIR}" "${DATA_DIR}/derivatives/petprep" participant \ + --fs-license-file "${FREESURFER_HOME}/license.txt" \ + --fs-subjects-dir ${DATA_DIR}/derivatives/freesurfer --fs-no-resume \ + --sloppy -vv --derivatives anat=${DATA_DIR}/derivatives/smriprep