Skip to content

Commit

Permalink
Polish workflows.
Browse files Browse the repository at this point in the history
  • Loading branch information
zjowowen committed Oct 31, 2024
1 parent e75042a commit 091e43a
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 33 deletions.
114 changes: 81 additions & 33 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,95 @@ on:
# Trigger this workflow when a new tag is pushed
push:
tags:
- '*'
- 'v*'

jobs:
build-and-publish:
build:
name: Build distribution 📦
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
# Step 1: Check out the repository
- name: Check out code
uses: actions/checkout@v3
- uses: actions/checkout@v4
- 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@v4
with:
name: python-package-distributions
path: dist/

# Step 2: Set up Python environment with matrix
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
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/GenerativeRL # Replace <package-name> with your PyPI project name
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
python-version: ${{ matrix.python-version }}
password: ${{ secrets.PYPI_API_TOKEN }}

# Step 3: Install build dependencies
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
github-release:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
and upload them to GitHub Release
needs:
- publish-to-pypi
runs-on: ubuntu-latest

# Step 4: Build the package (wheel and source distribution)
- name: Build the package
run: |
python setup.py sdist bdist_wheel
permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

# Step 5: Publish the package to PyPI (only run once for one version)
- name: Publish to PyPI
if: matrix.python-version == '3.9' # Publish only once, on Python 3.9
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
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:
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }} # Use the PyPI token stored in GitHub Secrets
run: |
python -m twine upload dist/*
# Step 6: Clean up the build artifacts
- name: Remove build artifacts
if: matrix.python-version == '3.9' # Clean up once after publishing
run: rm -rf dist build *.egg-info
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 }}'
57 changes: 57 additions & 0 deletions .github/workflows/test_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Publish to TestPyPI

on:
# Trigger this workflow when a new tag is pushed
push:
tags:
- 'test*'

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

steps:
- uses: actions/checkout@v4
- 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@v4
with:
name: python-package-distributions
path: dist/

publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs:
- build
runs-on: ubuntu-latest

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

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

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
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/
password: ${{ secrets.PYPI_API_TOKEN }}

0 comments on commit 091e43a

Please sign in to comment.