Skip to content

Commit c0243db

Browse files
committed
Add pypi release workflow
1 parent 08387fb commit c0243db

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed

.github/workflows/pypi_release.yaml

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# This workflow is adapted from:
2+
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
3+
# Changes made:
4+
# - Removed emoticons
5+
# - Updated some actions to more recent versions
6+
# - Customized for the qc-grid repository
7+
8+
name: PyPI Release
9+
on:
10+
push:
11+
tags:
12+
# Trigger on version tags (e.g., v1.0.0)
13+
- "v[0-9].[0-9].[0-9]*"
14+
- "[0-9].[0-9].[0-9]*"
15+
# Trigger on pre-release tags (e.g., v1.0.0-alpha.1)
16+
- "v[0-9].[0-9].[0-9]*-*"
17+
- "[0-9].[0-9].[0-9]*-*"
18+
19+
env:
20+
# The name of the package to be published to PyPI and TestPyPI.
21+
PYPI_NAME: qc-grid
22+
23+
jobs:
24+
build:
25+
name: Build distribution
26+
runs-on: ubuntu-latest
27+
28+
steps:
29+
- uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0
32+
- name: Set up Python
33+
uses: actions/setup-python@v5
34+
with:
35+
python-version: "3.11"
36+
- name: Install pypa/build
37+
run: >-
38+
python -m pip install build
39+
- name: Build package
40+
run: >-
41+
python -m build
42+
- name: Store the distribution packages
43+
uses: actions/upload-artifact@v4
44+
with:
45+
name: python-package-distributions
46+
path: dist/
47+
48+
publish-to-pypi:
49+
name: Publish Python distribution to PyPI
50+
# only publish to PyPI on tag pushes
51+
if: startsWith(github.ref, 'refs/tags/')
52+
needs:
53+
- build
54+
runs-on: ubuntu-latest
55+
environment:
56+
name: PyPI-Release
57+
url: https://pypi.org/project/${{ env.PYPI_NAME }}
58+
permissions:
59+
id-token: write
60+
61+
steps:
62+
- name: Download all the dists
63+
uses: actions/download-artifact@v4
64+
with:
65+
name: python-package-distributions
66+
path: dist/
67+
- name: Publish distribution to PyPI
68+
uses: pypa/gh-action-pypi-publish@release/v1
69+
env:
70+
TWINE_USERNAME: "__token__"
71+
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
72+
73+
github-release:
74+
name: Sign the Python distribution with Sigstore and upload them to GitHub Release
75+
needs:
76+
- publish-to-pypi
77+
runs-on: ubuntu-latest
78+
79+
permissions:
80+
contents: write
81+
id-token: write
82+
83+
steps:
84+
- name: Download all the dists
85+
uses: actions/download-artifact@v4
86+
with:
87+
name: python-package-distributions
88+
path: dist/
89+
- name: Sign the dists with Sigstore
90+
uses: sigstore/gh-action-sigstore-python@v3.0.0
91+
with:
92+
inputs: >-
93+
./dist/*.tar.gz
94+
./dist/*.whl
95+
- name: Create GitHub Release
96+
env:
97+
GITHUB_TOKEN: ${{ github.token }}
98+
run: >-
99+
gh release create
100+
'${{ github.ref_name }}'
101+
--repo '${{ github.repository }}'
102+
--notes ""
103+
- name: Upload artifact signatures to GitHub Release
104+
env:
105+
GITHUB_TOKEN: ${{ github.token }}
106+
run: >-
107+
gh release upload
108+
'${{ github.ref_name }}' dist/**
109+
--repo '${{ github.repository }}'
110+
111+
publish-to-testpypi:
112+
name: Publish Python distribution to TestPyPI
113+
# if: ${{ github.ref == 'refs/heads/master' && github.repository_owner == 'theochem' }}
114+
needs:
115+
- build
116+
runs-on: ubuntu-latest
117+
118+
environment:
119+
name: TestPyPI
120+
url: https://test.pypi.org/project/${{ env.PYPI_NAME }}
121+
122+
permissions:
123+
id-token: write
124+
125+
steps:
126+
- name: Download all the dists
127+
uses: actions/download-artifact@v4
128+
with:
129+
name: python-package-distributions
130+
path: dist/
131+
- name: Publish distribution to TestPyPI
132+
uses: pypa/gh-action-pypi-publish@release/v1
133+
with:
134+
repository-url: https://test.pypi.org/legacy/
135+
env:
136+
TWINE_USERNAME: "__token__"
137+
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }}

0 commit comments

Comments
 (0)