Skip to content

Commit

Permalink
Update GH publish workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
dofuuz committed Jun 12, 2024
1 parent 360848e commit cf73fba
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 53 deletions.
160 changes: 110 additions & 50 deletions .github/workflows/build-dist.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,121 @@
name: Build and upload to PyPI
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/

# Build on every branch push, tag push, and pull request change:
on: [push, pull_request, workflow_dispatch]
# Alternatively, to publish when a (published) GitHub Release is created, use the following:
# on:
# push:
# pull_request:
# release:
# types:
# - published

jobs:
build_sdist:
name: Build source distribution
runs-on: ubuntu-22.04
build:
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/

- name: Build SDist
run: pipx run build --sdist
# publish-to-pypi:
# name: >-
# Publish Python 🐍 distribution 📦 to PyPI
# if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
# needs:
# - build
# runs-on: ubuntu-latest
# environment:
# name: pypi
# url: https://pypi.org/p/roseus
# permissions:
# id-token: write # IMPORTANT: mandatory for trusted publishing
#
# steps:
# - name: Download all the dists
# uses: actions/download-artifact@v3
# with:
# name: python-package-distributions
# path: dist/
# - name: Publish distribution 📦 to PyPI
# uses: pypa/gh-action-pypi-publish@release/v1

github-release:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
and upload them to GitHub Release
# needs:
# - publish-to-pypi
runs-on: ubuntu-latest

- name: Check metadata
run: pipx run twine check dist/*
permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

- uses: actions/upload-artifact@v4
with:
name: sdist
path: dist/*.tar.gz
steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
upload_pypi:
needs: [build_sdist]
publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs:
- build
runs-on: ubuntu-latest
# upload to PyPI on every tag starting with 'v'
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
# alternatively, to publish when a GitHub Release is created, use the following rule:
# if: github.event_name == 'release' && github.event.action == 'published'

environment:
name: testpypi
url: https://test.pypi.org/p/roseus

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- uses: actions/download-artifact@v4
with:
path: dist
pattern: "*"
merge-multiple: true

- uses: softprops/action-gh-release@v2
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
with:
files: |
dist/*.tar.gz
dist/*.whl
- uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
# To test
# password: ${{ secrets.TEST_PYPI_API_TOKEN }}
# repository_url: https://test.pypi.org/legacy/
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ generate = ["colour-science", "matplotlib", "numpy", "colorspacious", "scipy"]
Homepage = "https://github.com/dofuuz/roseus"
Source = "https://github.com/dofuuz/roseus"

[tool.setuptools]
packages = ["roseus"]

[tool.cibuildwheel]
# Necessary to see build output from the actual compilation
build-verbosity = 1
Expand Down

0 comments on commit cf73fba

Please sign in to comment.