Tox #2059
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions | |
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | |
name: Python package | |
on: | |
push: | |
branches: [ '**' ] | |
tags: [ '*' ] | |
pull_request: | |
branches: [ master, 'maint/*' ] | |
schedule: | |
- cron: '0 0 * * *' | |
concurrency: | |
group: python-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
job_metadata: | |
if: github.repository == 'nipreps/niworkflows' | |
runs-on: ubuntu-latest | |
outputs: | |
commit_message: ${{ steps.get_commit_message.outputs.commit_message }} | |
version: ${{ steps.show_version.outputs.version }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Print head git commit message | |
id: get_commit_message | |
run: | | |
if [[ -z "$COMMIT_MSG" ]]; then | |
COMMIT_MSG=$(git show -s --format=%s $REF) | |
fi | |
echo commit_message=$COMMIT_MSG | tee -a $GITHUB_OUTPUT | |
env: | |
COMMIT_MSG: ${{ github.event.head_commit.message }} | |
REF: ${{ github.event.pull_request.head.sha }} | |
- name: Detect version | |
id: show_version | |
run: | | |
if [[ "$GITHUB_REF" == refs/tags/* ]]; then | |
VERSION=${GITHUB_REF##*/} | |
else | |
pipx run hatch version # Once to avoid output of initial setup | |
VERSION=$( pipx run hatch version ) | |
fi | |
echo version=$VERSION | tee -a $GITHUB_OUTPUT | |
build: | |
if: github.repository == 'nipreps/niworkflows' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Python 3 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3 | |
- name: Display Python version | |
run: python -c "import sys; print(sys.version)" | |
- name: Build niworkflows | |
run: pipx run build | |
- name: Check distributions | |
run: pipx run twine check dist/* | |
- uses: actions/upload-artifact@v3 | |
with: | |
name: dist | |
path: dist/ | |
get_data: | |
if: github.repository == 'nipreps/niworkflows' | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
shell: bash -l {0} | |
steps: | |
- name: Create test data directory | |
run: mkdir -p $HOME/.cache/stanford-crn | |
- name: Load test data cache | |
uses: actions/cache@v4 | |
id: stanford-crn | |
with: | |
path: ~/.cache/stanford-crn/ | |
key: data-v0-${{ github.ref_name }}-${{ github.sha }} | |
restore-keys: | | |
data-v0-${{ github.ref_name }}- | |
data-v0- | |
- name: Setup conda | |
uses: conda-incubator/setup-miniconda@v3 | |
with: | |
auto-activate-base: true | |
activate-environment: "" | |
- name: Verify environment | |
run: | | |
conda info | |
which python | |
- name: Install datalad | |
run: | | |
python -m pip install datalad-installer | |
datalad-installer --sudo ok git-annex | |
python -m pip install datalad datalad-osf | |
datalad wtf | |
- name: Pacify git | |
run: | | |
git config --global user.email "github@niworkflows.ci" | |
git config --global user.name "Niworkflows Action" | |
- name: Fetch test data | |
run: | | |
DS=$HOME/.cache/stanford-crn | |
datalad install -r -s https://github.com/nipreps-data/niworkflows-data.git $DS | |
cd $DS | |
git -C BIDS-examples-1-enh-ds054 checkout enh/ds054 | |
datalad update -r --merge -d . | |
datalad get -J 2 -r ds000003 ds000030/sub-10228/func | |
test: | |
needs: [build, get_data, job_metadata] | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ["3.9", "3.10", "3.11", "3.12"] | |
install: [repo] | |
include: | |
- python-version: "3.12" | |
install: sdist | |
- python-version: "3.12" | |
install: wheel | |
- python-version: "3.12" | |
install: editable | |
env: | |
INSTALL_TYPE: ${{ matrix.install }} | |
steps: | |
- uses: actions/checkout@v4 | |
if: matrix.install == 'repo' || matrix.install == 'editable' | |
with: | |
fetch-depth: 0 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Load test data cache | |
uses: actions/cache@v4 | |
id: stanford-crn | |
with: | |
path: ~/.cache/stanford-crn/ | |
key: data-v0-${{ github.ref_name }}-${{ github.sha }} | |
- name: Load TemplateFlow cache | |
uses: actions/cache@v4 | |
id: templateflow | |
with: | |
path: ~/.cache/templateflow | |
key: templateflow-v0-${{ github.ref_name }}-${{ strategy.job-index }}-${{ github.sha }} | |
restore-keys: | | |
templateflow-v0-${{ github.ref_name }}- | |
templateflow-v0- | |
- name: Fetch packages | |
if: matrix.install == 'sdist' || matrix.install == 'wheel' | |
uses: actions/download-artifact@v3 | |
with: | |
name: dist | |
path: dist/ | |
- name: Select archive | |
run: | | |
if [ "$INSTALL_TYPE" = "sdist" ]; then | |
ARCHIVE=$( ls dist/*.tar.gz ) | |
elif [ "$INSTALL_TYPE" = "wheel" ]; then | |
ARCHIVE=$( ls dist/*.whl ) | |
elif [ "$INSTALL_TYPE" = "repo" ]; then | |
ARCHIVE="." | |
elif [ "$INSTALL_TYPE" = "editable" ]; then | |
ARCHIVE="-e ." | |
fi | |
echo "ARCHIVE=$ARCHIVE" | tee -a $GITHUB_ENV | |
- name: Install package | |
run: python -m pip install $ARCHIVE | |
- name: Check version | |
run: | | |
INSTALLED_VERSION=$(python -c 'import niworkflows; print(niworkflows.__version__, end="")') | |
echo "INSTALLED: \"${INSTALLED_VERSION}\"" | |
test "${INSTALLED_VERSION}" = "${VERSION}" | |
env: | |
VERSION: ${{ needs.job_metadata.outputs.version }} | |
- name: Install test dependencies | |
run: python -m pip install "niworkflows[tests]" | |
- name: Run tests | |
run: pytest -sv --doctest-modules --cov niworkflows --pyargs niworkflows | |
- uses: codecov/codecov-action@v4 | |
name: Submit to CodeCov | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
test-pre: | |
needs: [get_data, job_metadata] | |
if: ${{ !contains(needs.job_metadata.outputs.commit_message, '[skip pre]') }} | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
# Only run --pre tests on Python versions within SPEC0 support | |
python-version: ["3.11", "3.12"] | |
install: [repo] | |
pip-flags: ['--pre'] | |
env: | |
INSTALL_TYPE: ${{ matrix.install }} | |
PIP_FLAGS: ${{ matrix.pip-flags }} | |
steps: | |
- name: Debug commit message | |
run: echo "${{ needs.job_metadata.outputs.commit_message }}" | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Load test data cache | |
uses: actions/cache@v4 | |
id: stanford-crn | |
with: | |
path: ~/.cache/stanford-crn/ | |
key: data-v0-${{ github.ref_name }}-${{ github.sha }} | |
- name: Load TemplateFlow cache | |
uses: actions/cache@v4 | |
id: templateflow | |
with: | |
path: ~/.cache/templateflow | |
key: templateflow-v0-${{ github.ref_name }}-${{ strategy.job-index }}-${{ github.sha }} | |
restore-keys: | | |
templateflow-v0-${{ github.ref_name }}- | |
templateflow-v0- | |
- name: Install package | |
run: python -m pip install $PIP_FLAGS . | |
- name: Check version | |
run: | | |
INSTALLED_VERSION=$(python -c 'import niworkflows; print(niworkflows.__version__, end="")') | |
echo "INSTALLED: \"${INSTALLED_VERSION}\"" | |
test "${INSTALLED_VERSION}" = "${VERSION}" | |
env: | |
VERSION: ${{ needs.job_metadata.outputs.version }} | |
- name: Install test dependencies | |
run: python -m pip install $PIP_FLAGS "niworkflows[tests]" | |
- name: Run tests | |
run: pytest -sv --doctest-modules --cov niworkflows --pyargs niworkflows | |
- uses: codecov/codecov-action@v4 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
name: Submit to CodeCov | |
flake8: | |
if: github.event_name != 'schedule' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python 3 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3 | |
- run: pipx run flake8 niworkflows/ |