Skip to content

Commit

Permalink
Merge pull request #26 from tomaroberts/24-gha-pypi
Browse files Browse the repository at this point in the history
- Implements dunamai in publish to TestPyPI GitHub Action
- Adds publish to PyPI GitHub Action
  • Loading branch information
tomaroberts authored Aug 31, 2023
2 parents a24a553 + da523e3 commit b03b4aa
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 31 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/build_and_test_cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ jobs:
os: [ ubuntu-latest ]
python-version: [ '3.9' ]

defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v4
Expand All @@ -32,6 +30,7 @@ jobs:
- name: Install Python packages
run: |
python -m pip install --upgrade pip
pip install setuptools wheel
pip install flake8 pytest pytest-cov
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
Expand Down
99 changes: 99 additions & 0 deletions .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Publish to PyPI
#
# This workflow publishes nii2dcm on PyPI. The workflow triggers
# on release. The PyPI release is labelled according to the git tag
# specified in the GitHub Release user interface. For instance,
# if the TestPyPI release is v0.1.2.post16, then the GitHub Release
# tag should be entered as v0.1.3, which will propagate to PyPI.
# Subsequent developer commits will become v0.1.3.post1, v0.1.3.post2,
# and so on.
#
# This workflow will upload a Python Package using Twine when a release is created. For more information see:
# https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
#
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Publish package to PyPI

on:
release:
types: [published]

permissions:
contents: read
actions: write

jobs:
testpypi-publish:

name: Publish to PyPI
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/nii2dcm
permissions:
contents: read
actions: write
id-token: write # IMPORTANT: this permission is mandatory for PyPI trusted publishing

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel
pip install -r requirements.txt
- name: Build package
run: pip install .

- name: Display version via dunamai
run: |
echo "version via dunamai:"
dunamai from any
- name: Display version via nii2dcm CLI
run: |
echo "version via nii2dcm CLI:"
nii2dcm -v
- name: Create dist/
run: |
python setup.py sdist bdist_wheel
twine check dist/*
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
verbose: true

- name: Wait to allow PyPI to update
uses: GuillaumeFalourd/wait-sleep-action@v1
with:
time: '150' # seconds

- name: Install latest PyPI version in fresh venv
run: |
NII2DCM_VERSION=`echo "$(nii2dcm -v)"`
echo $NII2DCM_VERSION
python -m venv nii2dcm-temp
source nii2dcm-temp/bin/activate
pip install --upgrade pip
pip install setuptools wheel
pip install nii2dcm==$NII2DCM_VERSION
nii2dcm -h
echo "nii2dcm version:"
nii2dcm -v
35 changes: 25 additions & 10 deletions .github/workflows/publish_testpypi.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Publish to TestPyPI
#
# This workflow publishes nii2dcm on TestPyPI prior to production release onto PyPI. The workflow is intended to catch
# any issues arising during the release procedure to prevent unnecessary versioning issues on PyPI
# This workflow publishes nii2dcm on TestPyPI prior to
# production release onto PyPI. The workflow is intended to
# catch any issues arising during the release procedure to
# prevent unnecessary versioning issues on PyPI.
#
# This workflow will upload a Python Package using Twine when a release is created. For more information see:
# https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
Expand All @@ -14,20 +16,24 @@
name: Publish package to TestPyPI

on:
pull_request
push:
branches:
- main

permissions:
contents: read
actions: write

jobs:
testpypi-publish:

name: Publish release to TestPyPI
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/p/nii2dcm
permissions:
contents: read
actions: write
id-token: write # IMPORTANT: this permission is mandatory for PyPI trusted publishing

steps:
Expand All @@ -43,18 +49,27 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
pip install setuptools wheel
pip install -r requirements.txt
- name: Build package
run: python -m build --sdist --wheel --outdir dist/
run: pip install .

- name: Display nii2dcm version
id: nii2dcm-version
- name: Display version via dunamai
run: |
pip install -e .
echo "nii2dcm version:"
echo "version via dunamai:"
dunamai from any
- name: Display version via nii2dcm CLI
run: |
echo "version via nii2dcm CLI:"
nii2dcm -v
- name: Create dist/
run: |
python setup.py sdist bdist_wheel
twine check dist/*
- name: Publish package to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,5 @@ _im*
*.nii
*.nii.gz

# Omit _version.py as required by setuptools_scm
nii2dcm/_version.py

# Permit Test Data
!tests/data/DicomMRISVR/t2-svr-atlas-35wk.nii.gz
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ nii2dcm SVR-output.nii.gz path/to/output/dir/ -d SVR
<!-- ROADMAP -->
## Roadmap

This project is in its infancy! Expect :bug::ant::beetle:
This project is in its infancy! Expect bugs :bug::ant::beetle:

There are many things I would like to test and implement.
[Raise an Issue](https://github.com/tomaroberts/nii2dcm/issues) if you have ideas or suggestions.
Expand Down
2 changes: 2 additions & 0 deletions nii2dcm/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from dunamai import Version, Style
__version__ = Version.from_git().serialize(metadata=False, style=Style.SemVer)
11 changes: 0 additions & 11 deletions pyproject.toml

This file was deleted.

3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ numpy==1.23.2
matplotlib==3.6.2
nibabel==5.0.0
pydicom==2.3.0
twine==4.0.2
twine==4.0.2
dunamai==1.18.0
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = nii2dcm
version = attr: nii2dcm._version.__version__
version = attr: nii2dcm.__init__.__version__
description= nii2dcm: NIfTI to DICOM creation with Python
url = https://github.com/tomaroberts/nii2dcm
author = Tom Roberts
Expand All @@ -17,6 +17,7 @@ install_requires =
nibabel==5.0.0
pydicom==2.3.0
twine==4.0.2
dunamai==1.18.0
include_package_data=True

[options.entry_points]
Expand Down
7 changes: 7 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from setuptools import setup
from dunamai import Version, Style

setup(
name="nii2dcm",
version=Version.from_git().serialize(metadata=False, style=Style.SemVer),
)

0 comments on commit b03b4aa

Please sign in to comment.