Skip to content

Commit

Permalink
Merge pull request #16 from schuhmaj/main
Browse files Browse the repository at this point in the history
Create pypi publish workflow
  • Loading branch information
schuhmaj authored Aug 29, 2023
2 parents 93e4845 + 0ef103c commit 25869d8
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 2 deletions.
144 changes: 144 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
name: Build & Publish Python Package

on:
release:
types: [created]
# Only trigger for regular releases, not pre-releases
# See https://docs.github.com/en/actions/reference/events-that-trigger-workflows#release
# for more information on the release event
prerelease: false

jobs:
# 1.a Buidl the wheels on a matrix of Windows, MacOS, and Linux plattforms usinbg cibuildwheel
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v3
# In case of Linux we need to install compiler and build tools before building the wheels
# We further only build the manylinux wheels, but not the musllinux wheels
- name: Build wheels (Linux)
uses: pypa/[email protected]
env:
CIBW_BEFORE_BUILD: yum makecache && yum install -y gcc-c++ cmake && pip install ninja
CIBW_BUILD: "*manylinux*"
CIBW_ARCHS_LINUX: "auto64"
CIBW_TEST_COMMAND: 'python -c "import polyhedral_gravity"'
with:
package-dir: .
output-dir: dist
if: matrix.os == 'ubuntu-latest'
# Building on macOS requires an installation of gcc since the default clang compiler
# lacks certain features required for building the package
- name: Build wheels (macOS)
uses: pypa/[email protected]
env:
CIBW_BEFORE_BUILD: brew install ninja gcc@12
CIBW_ENVIRONMENT: "CC=gcc-12 CXX=g++-12"
CIBW_TEST_COMMAND: 'python -c "import polyhedral_gravity"'
with:
package-dir: .
output-dir: dist
if: matrix.os == 'macos-latest'
# Set up the Visual Studio environment on Windows (required, so that CNaje finds the compiler)
- uses: ilammy/msvc-dev-cmd@v1
if: matrix.os == 'windows-latest'
- name: Build wheels (Windows)
uses: pypa/[email protected]
env:
CIBW_BEFORE_BUILD: choco install -y ninja cmake
CIBW_ARCHS_WINDOWS: "auto64"
CIBW_TEST_COMMAND: 'python -c "import polyhedral_gravity"'
with:
package-dir: .
output-dir: dist
if: matrix.os == 'windows-latest'
- uses: actions/upload-artifact@v3
with:
path: dist/*.whl

# 1.b Build the source distribution by simply running the build command
make_sdist:
name: Make SDist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build SDist
run: pipx run build --sdist
- uses: actions/upload-artifact@v3
with:
path: dist/*.tar.gz

# 2. Upload the wheels and the source distribution to testpypi
# using trusted publishing
upload_testpypi:
needs: [build_wheels, make_sdist]
environment:
name: testpypi
url: https://test.pypi.org/p/polyhedral-gravity
permissions:
id-token: write
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist
- uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/

# 3. Check if the package can be installed from testpypi
# Notice, that this is more of an install test since the
# import check has already been done in the build_wheels job
check_testpypi:
needs: [upload_testpypi]
name: Test import on ${{ matrix.os }} with ${{ matrix.py }}
runs-on: ${{ matrix.os }}
if: always()
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
py:
[
3.7.x,
3.8.x,
3.9.x,
3.10.x,
3.11.x,
pypy3.7,
pypy3.8,
pypy3.9,
pypy3.10,
]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.py }}
- name: Install package from testpypi
run: pip install --index-url https://test.pypi.org/simple/ polyhedral-gravity
- name: Check import
run: python -c "import polyhedral_gravity"

# 4. Upload the wheels to the actualy Python Package Index
# using trusted publishing
upload_pypi:
needs: [build_wheels, make_sdist, check_testpypi]
environment:
name: pypi
url: https://pypi.org/p/polyhedral-gravity
permissions:
id-token: write
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist
- uses: pypa/gh-action-pypi-publish@release/v1
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
![GitHub](https://img.shields.io/github/license/esa/polyhedral-gravity-model)

![PyPI](https://img.shields.io/pypi/v/polyhedral-gravity)
![Static Badge](https://img.shields.io/badge/platform-linux--64_%7C_windows--64_%7C_osx--64_%7C_linux--arm64_%7C_osx--arm64-lightgrey)
![Static Badge](https://img.shields.io/badge/platform-linux--64_%7C_win--64_%7C_osx--64_%7C_linux--arm64_%7C_osx--arm64-lightgrey)
![PyPI - Downloads](https://img.shields.io/pypi/dm/polyhedral-gravity)

![Conda](https://img.shields.io/conda/v/conda-forge/polyhedral-gravity-model)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def build_extension(self, ext):
# --------------------------------------------------------------------------------
setup(
name="polyhedral_gravity",
version="2.0",
version="2.0.3",
author="Jonas Schuhmacher",
author_email="[email protected]",
description="Package to compute full gravity tensor of a given constant density polyhedron for arbitrary points",
Expand Down

0 comments on commit 25869d8

Please sign in to comment.