Skip to content

Build-Test-Deploy

Build-Test-Deploy #3

name: Build-Test-Deploy
on:
push:
branches:
- main
- maint/*
tags:
- '*'
pull_request:
branches:
- main
- maint/*
schedule:
# 8am EST / 9am EDT Mondays
- cron: '0 13 * * 1'
workflow_dispatch:
defaults:
run:
shell: bash
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
if: |
github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
|| ! contains(github.event.head_commit.message, '[skip ci]')
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install build dependencies
run: pip install --upgrade pip build twine
- name: Build sdist and wheel
run: python -m build -s -w
- name: Check distributions
run: twine check dist/*
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
test:
needs: [build]
runs-on: ${{ matrix.os }}
strategy:
matrix:
#os: ['ubuntu-latest', 'windows-latest', 'macos-latest']
os: ['ubuntu-latest']
python-version: [3.8, 3.9, '3.10', '3.11', '3.12']
architecture: ['x64', 'x86']
package: ['.', 'dist/*.whl', 'dist/*.tar.gz']
exclude:
# 32-bit is a Windows-only consideration
- os: ubuntu-latest
architecture: x86
- os: macos-latest
architecture: x86
# Only run newest on Windows/Mac
- os: windows-latest
python-version: 3.8
- os: windows-latest
python-version: 3.9
- os: macos-latest
python-version: 3.8
- os: macos-latest
python-version: 3.9
# Skip 32-bit Windows with Python 3.10 (see #42)
- os: windows-latest
architecture: x86
python-version: 3.10
env:
PACKAGE: ${{ matrix.package }}
TEMPLATEFLOW_HOME: /tmp/templateflow
steps:
- uses: actions/checkout@v4
- name: Fetch packages
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: ${{ matrix.architecture }}
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- uses: actions/cache@v4
with:
path: /var/lib/apt
key: apt-cache-v0
restore-keys: |
apt-cache-v0
- name: Install tex
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends dvipng texlive texlive-latex-extra cm-super
- name: Install package
run: pip install $PACKAGE
- name: Verify installation
run: python -c "import nireports; print(nireports.__version__)"
- name: Install test dependencies
run: pip install .[test]
- name: Restore cached templateflow
id: tf-cache-restore
uses: actions/cache/restore@v4
with:
path: /tmp/templateflow
key: templateflow-v1
- name: Fetch templates
run: |
python -c "from templateflow.api import get; get('Fischer344', desc=None, suffix='T2w')"
python -c "from templateflow.api import get; get('MNI152NLin6Asym', resolution=2, desc='LR', suffix='T1w')"
- name: Save templateflow cache
id: tf-cache-save
uses: actions/cache/save@v4
with:
path: /tmp/templateflow
key: ${{ steps.tf-cache-restore.outputs.cache-primary-key }}
- name: Run tests
run: pytest --cov nireports nireports
- uses: codecov/codecov-action@v4
if: ${{ always() }}
with:
token: ${{ secrets.CODECOV_TOKEN }}
deploy:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
needs: [test]
runs-on: ubuntu-latest
steps:
- name: Fetch packages
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Upload to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}