Skip to content

Adds Docker build and GHA test of container #58

Adds Docker build and GHA test of container

Adds Docker build and GHA test of container #58

# 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 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 TestPyPI
on:
pull_request:
push:
branches:
- main
permissions:
contents: read
actions: write
jobs:
testpypi-publish:
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:
- 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 bdist_wheel
twine check dist/*
- name: Publish package to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.TESTPYPI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/
verbose: true
- name: Wait to allow TestPyPI to update
uses: GuillaumeFalourd/wait-sleep-action@v1
with:
time: '150' # seconds
- name: Install latest TestPyPI version in fresh venv
id: attempt1
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 --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ nii2dcm==$NII2DCM_VERSION
nii2dcm -h
echo "nii2dcm version:"
nii2dcm -v
continue-on-error: true
- name: Wait longer
if: steps.attempt1.outcome != 'success'
uses: GuillaumeFalourd/wait-sleep-action@v1
with:
time: '150' # seconds
- name: Re-attempt TestPyPI install
if: steps.attempt1.outcome != 'success'
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 --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ nii2dcm==$NII2DCM_VERSION
nii2dcm -h
echo "nii2dcm version:"
nii2dcm -v
ghcr-publish:
needs: testpypi-publish
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: |
ghcr.io/tomaroberts/nii2dcm
- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}