Skip to content

Commit

Permalink
update release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaehne committed May 3, 2024
1 parent 3162582 commit 4ae3db8
Show file tree
Hide file tree
Showing 2 changed files with 214 additions and 72 deletions.
178 changes: 178 additions & 0 deletions .github/workflows/package_and_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
# Reusable workflows are not supported with external organizations
# copy and paste
# https://github.com/hyperspy/.github/blob/main/.github/workflows/package_and_test.yml
# Remove 'pooch', 'fetch tags upstream'

name: Package & Test

on:
workflow_call:
inputs:
library_name:
description: 'The name of library, if different from repository name'
# if empty string, the current repository name is used
default: ''
type: string
module_name:
description: 'The name of the module to test, if different from repository name'
# if empty string, the current repository name is used
default: ''
type: string
use_xvfb:
description: 'Whether to install and setup xvfb and pyqt for testing'
# if empty string, the current repository name is used
default: false
type: boolean
EXTRAS:
description: 'Optional “variants” (also called extra) to be installed'
# if empty string, no argument is passed
default: '[tests]'
type: string
PYTEST_ARGS:
description: 'The argurment to pass to pytest call'
# if empty string, no argument is passed
default: ''
type: string
ADDITIONAL_TEST_DEPENDENCIES:
description: 'Additional dependencies to be installed when testing'
# if empty string, no argument is passed
default: ''
type: string


env:
PYTHON_VERSION: '3.11'

jobs:
package:
name: Package
runs-on: ubuntu-latest
outputs:
REPOSITORY_NAME: ${{ env.REPOSITORY_NAME }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: get repository name
run: echo "REPOSITORY_NAME=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV

- uses: actions/setup-python@v5
name: Install Python
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Display version
run: |
python --version
pip --version
- name: Install pypa/build pypa/twine
run: |
pip install build twine
- name: Build a wheel and sdist
run: |
python -m build
- name: Display content dist folder
run: |
ls -shR dist/
- name: Run twin check
run: |
twine check dist/*
- uses: actions/upload-artifact@v4
with:
path: ./dist/*
name: dist

test:
name: Test
needs: package
runs-on: ubuntu-latest
env:
REPOSITORY_NAME: ${{ needs.package.outputs.REPOSITORY_NAME }}
LIBRARY_NAME: ${{ inputs.library_name }}
MODULE_NAME: ${{ inputs.module_name }}
steps:
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install Ubuntu packages for Qt
if: ${{ inputs.use_xvfb }}
shell: bash
run: |
sudo apt-get update
sudo apt-get install qtbase5-dev
sudo apt-get install libxkbcommon-x11-0
sudo apt-get install libxcb-icccm4
sudo apt-get install libxcb-image0
sudo apt-get install libxcb-keysyms1
sudo apt-get install libxcb-randr0
sudo apt-get install libxcb-render-util0
sudo apt-get install libxcb-xinerama0
- name: Install pyqt
if: ${{ inputs.use_xvfb }}
run: |
pip install pyqt5 PyQtWebEngine
- uses: actions/download-artifact@v4

- name: Display content working folder
run: |
ls -shR
- shell: bash
name: Get library name
run: |
if [ '${{ env.LIBRARY_NAME }}' = '' ]; then
LIBRARY_NAME=${{ env.REPOSITORY_NAME }}
echo "LIBRARY_NAME=${LIBRARY_NAME}" >> $GITHUB_ENV
fi
- shell: bash
name: Get module name
run: |
if [ '${{ env.MODULE_NAME }}' = '' ]; then
MODULE_NAME=${{ env.REPOSITORY_NAME }}
echo "MODULE_NAME=${MODULE_NAME}" >> $GITHUB_ENV
fi
- name: Install distribution
env:
EXTRAS: ${{ inputs.EXTRAS }}
run: |
# pint release version doesn't support numpy 2.0
pip install numpy
pip install --pre --find-links dist ${{ env.LIBRARY_NAME }}${{ env.EXTRAS }}
- name: Install additional test dependencies
if: ${{ inputs.ADDITIONAL_TEST_DEPENDENCIES != ''}}
run: |
pip install ${{ inputs.ADDITIONAL_TEST_DEPENDENCIES }}
- name: Pip list
run: |
pip list
- name: Test distribution
if: ${{ inputs.use_xvfb != true }}
env:
POOCH_BASE_URL: ${{ inputs.POOCH_BASE_URL }}
PYTEST_ARGS: ${{ inputs.PYTEST_ARGS }}
run: |
pytest --pyargs ${{ env.MODULE_NAME }} ${{ env.PYTEST_ARGS }}
- name: Test distribution (with xvfb)
if: ${{ inputs.use_xvfb }}
env:
POOCH_BASE_URL: ${{ inputs.POOCH_BASE_URL }}
PYTEST_ARGS: ${{ inputs.PYTEST_ARGS }}
run: |
sudo apt-get install xvfb
xvfb-run pytest --pyargs ${{ env.MODULE_NAME }} ${{ env.PYTEST_ARGS }}
108 changes: 36 additions & 72 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
name: Release
# Reusable workflows are not supported with external organizations
# copy and paste "jobs" from
# https://github.com/hyperspy/.github/blob/main/.github/workflows/release_pure_python.yml

# This workflow builds the wheels "on tag".
# If run from the lumispy/lumispy repository, the wheels will be uploaded to pypi ;
# otherwise, the wheels will be available as a github artefact.
Expand All @@ -11,82 +15,42 @@ on:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

jobs:
create_release:
package_and_test:
name: Package and Test
# Use the "reusable workflow" from the hyperspy organisation
uses: package_and_test.yml@main

upload_to_pypi:
needs: [package_and_test]
runs-on: ubuntu-latest
name: Upload to pypi
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
steps:
- name: Download dist
uses: actions/download-artifact@v4

- name: Display downloaded files
run: |
ls -shR
working-directory: dist

- uses: pypa/gh-action-pypi-publish@release/v1
if: ${{ startsWith(github.ref, 'refs/tags/') && github.repository_owner == 'lumispy' }}
# See https://docs.pypi.org/trusted-publishers/using-a-publisher/

create_github_release:
# If zenodo is setup to create a DOI automatically on a GitHub release,
# this step will trigger the mining of the DOI
needs: upload_to_pypi
permissions:
contents: write
name: Create Release
name: Create GitHub Release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
VERSION: ${{ env.VERSION }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create Release
id: create_release
uses: softprops/action-gh-release@3198ee18f814cdf787321b4a32a26ddbf37acc52
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions
with:
draft: false
prerelease: false
- name: Get version (on tag)
id: get_version
if: startsWith(github.ref, 'refs/tags/')
run: |
echo "VERSION=${GITHUB_REF#refs/*/v}" >> $GITHUB_ENV
echo "SETUP_VERSION=$(python setup.py --version)" >> $GITHUB_ENV
- name: Check version
if: ${{env.VERSION != env.SETUP_VERSION}}
run: |
echo "Version mismatch between pushed tag ($VERSION) and `release_info.py` ($SETUP_VERSION)"
exit 1
build_wheels_linux:
name: Wheels on ubuntu-latest
needs: create_release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Install release dependencies
run: |
python -m pip install twine wheel
- name: Build source distribution
run: |
python setup.py sdist bdist_wheel
- name: Display content dist folder
run: |
ls dist/
- name: Install and test distribution
env:
MPLBACKEND: agg
run: |
pip install --pre --find-links dist lumispy[tests]
pytest --pyargs lumispy
- uses: actions/upload-artifact@v4
with:
path: |
./dist/*.whl
./sdist/*.tar.gz
- name: Publish wheels to PyPI
if: github.repository_owner == 'lumispy'
env:
# Github secret set in the lumispy/lumispy repository
# Not available from fork or pull request
# Secrets are not passed to workflows that are triggered by a pull request from a fork
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
twine upload dist/*.whl --verbose
twine upload dist/*.tar.gz --verbose
if: ${{ startsWith(github.ref, 'refs/tags/') && github.repository_owner == 'lumispy' }}
uses: softprops/action-gh-release@9d7c94cfd0a1f3ed45544c887983e9fa900f0564

0 comments on commit 4ae3db8

Please sign in to comment.