Skip to content

Commit 49f5fc0

Browse files
committed
Polish workflows.
1 parent e75042a commit 49f5fc0

File tree

2 files changed

+138
-33
lines changed

2 files changed

+138
-33
lines changed

.github/workflows/release.yml

Lines changed: 81 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,95 @@ on:
44
# Trigger this workflow when a new tag is pushed
55
push:
66
tags:
7-
- '*'
7+
- 'v*'
88

99
jobs:
10-
build-and-publish:
10+
build:
11+
name: Build distribution 📦
1112
runs-on: ubuntu-latest
1213

13-
strategy:
14-
matrix:
15-
python-version: ["3.9", "3.10", "3.11", "3.12"]
16-
1714
steps:
18-
# Step 1: Check out the repository
19-
- name: Check out code
20-
uses: actions/checkout@v3
15+
- uses: actions/checkout@v4
16+
- name: Set up Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: "3.x"
20+
- name: Install pypa/build
21+
run: >-
22+
python3 -m
23+
pip install
24+
build
25+
--user
26+
- name: Build a binary wheel and a source tarball
27+
run: python3 -m build
28+
- name: Store the distribution packages
29+
uses: actions/upload-artifact@v4
30+
with:
31+
name: python-package-distributions
32+
path: dist/
2133

22-
# Step 2: Set up Python environment with matrix
23-
- name: Set up Python ${{ matrix.python-version }}
24-
uses: actions/setup-python@v4
34+
publish-to-pypi:
35+
name: >-
36+
Publish Python 🐍 distribution 📦 to PyPI
37+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
38+
needs:
39+
- build
40+
runs-on: ubuntu-latest
41+
environment:
42+
name: pypi
43+
url: https://pypi.org/p/GenerativeRL # Replace <package-name> with your PyPI project name
44+
permissions:
45+
id-token: write # IMPORTANT: mandatory for trusted publishing
46+
steps:
47+
- name: Download all the dists
48+
uses: actions/download-artifact@v4
49+
with:
50+
name: python-package-distributions
51+
path: dist/
52+
- name: Publish distribution 📦 to PyPI
53+
uses: pypa/gh-action-pypi-publish@release/v1
2554
with:
26-
python-version: ${{ matrix.python-version }}
55+
password: ${{ secrets.PYPI_API_TOKEN }}
2756

28-
# Step 3: Install build dependencies
29-
- name: Install build dependencies
30-
run: |
31-
python -m pip install --upgrade pip
32-
pip install setuptools wheel twine
57+
github-release:
58+
name: >-
59+
Sign the Python 🐍 distribution 📦 with Sigstore
60+
and upload them to GitHub Release
61+
needs:
62+
- publish-to-pypi
63+
runs-on: ubuntu-latest
3364

34-
# Step 4: Build the package (wheel and source distribution)
35-
- name: Build the package
36-
run: |
37-
python setup.py sdist bdist_wheel
65+
permissions:
66+
contents: write # IMPORTANT: mandatory for making GitHub Releases
67+
id-token: write # IMPORTANT: mandatory for sigstore
3868

39-
# Step 5: Publish the package to PyPI (only run once for one version)
40-
- name: Publish to PyPI
41-
if: matrix.python-version == '3.9' # Publish only once, on Python 3.9
69+
steps:
70+
- name: Download all the dists
71+
uses: actions/download-artifact@v4
72+
with:
73+
name: python-package-distributions
74+
path: dist/
75+
- name: Sign the dists with Sigstore
76+
uses: sigstore/gh-action-sigstore-python@v3.0.0
77+
with:
78+
inputs: >-
79+
./dist/*.tar.gz
80+
./dist/*.whl
81+
- name: Create GitHub Release
4282
env:
43-
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }} # Use the PyPI token stored in GitHub Secrets
44-
run: |
45-
python -m twine upload dist/*
46-
47-
# Step 6: Clean up the build artifacts
48-
- name: Remove build artifacts
49-
if: matrix.python-version == '3.9' # Clean up once after publishing
50-
run: rm -rf dist build *.egg-info
83+
GITHUB_TOKEN: ${{ github.token }}
84+
run: >-
85+
gh release create
86+
'${{ github.ref_name }}'
87+
--repo '${{ github.repository }}'
88+
--notes ""
89+
- name: Upload artifact signatures to GitHub Release
90+
env:
91+
GITHUB_TOKEN: ${{ github.token }}
92+
# Upload to GitHub Release using the `gh` CLI.
93+
# `dist/` contains the built packages, and the
94+
# sigstore-produced signatures and certificates.
95+
run: >-
96+
gh release upload
97+
'${{ github.ref_name }}' dist/**
98+
--repo '${{ github.repository }}'

.github/workflows/test_release.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Publish to TestPyPI
2+
3+
on:
4+
# Trigger this workflow when a new tag is pushed
5+
push:
6+
tags:
7+
- 'test*'
8+
9+
jobs:
10+
build:
11+
name: Build distribution 📦
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Set up Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: "3.x"
20+
- name: Install pypa/build
21+
run: >-
22+
python3 -m
23+
pip install
24+
build
25+
--user
26+
- name: Build a binary wheel and a source tarball
27+
run: python3 -m build
28+
- name: Store the distribution packages
29+
uses: actions/upload-artifact@v4
30+
with:
31+
name: python-package-distributions
32+
path: dist/
33+
34+
publish-to-testpypi:
35+
name: Publish Python 🐍 distribution 📦 to TestPyPI
36+
needs:
37+
- build
38+
runs-on: ubuntu-latest
39+
40+
environment:
41+
name: testpypi
42+
url: https://test.pypi.org/p/GenerativeRL
43+
44+
# permissions:
45+
# id-token: write # IMPORTANT: mandatory for trusted publishing
46+
47+
steps:
48+
- name: Download all the dists
49+
uses: actions/download-artifact@v4
50+
with:
51+
name: python-package-distributions
52+
path: dist/
53+
- name: Publish distribution 📦 to TestPyPI
54+
uses: pypa/gh-action-pypi-publish@release/v1
55+
with:
56+
repository-url: https://test.pypi.org/legacy/
57+
password: ${{ secrets.PYPI_API_TOKEN }}

0 commit comments

Comments
 (0)