Skip to content

Build-Test-Deploy

Build-Test-Deploy #274

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
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@v3
with:
submodules: recursive
fetch-depth: 0
- uses: actions/setup-python@v4
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@v3
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']
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@v3
- name: Fetch packages
uses: actions/download-artifact@v3
with:
name: dist
path: dist/
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: ${{ matrix.architecture }}
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Generate requirements file and install them
run: |
python -m pip install --upgrade pip-tools
python -m piptools compile --output-file=requirements.txt pyproject.toml
pip install -r requirements.txt
- 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@v3
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@v3
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@v3
if: ${{ always() }}
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@v3
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 }}