-
Notifications
You must be signed in to change notification settings - Fork 33
100 lines (85 loc) · 2.69 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: Publish Python 🐍 distribution 📦 to PyPI
on:
push:
# Only run this workflow when a tag with the pattern 'v*' is pushed
tags:
- 'v*'
jobs:
# Step 1: Build the Python package
build:
name: Build distribution 📦
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.7'
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build pytest
pip install -e .
- name: Run tests
run: pytest tests/
- name: Build package
run: python -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
# Step 2: Publish the distribution to PyPI
publish-to-pypi:
name: Publish to PyPI
needs: build
runs-on: ubuntu-latest
steps:
- name: Download distribution packages
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish to PyPI
uses: pypa/[email protected]
with:
# If using a secret-based token:
username: '__token__'
password: ${{ secrets.PYPI_API_TOKEN }}
# Step 3: Sign the distribution and create a GitHub release
github-release:
name: Sign the distribution 📦 with Sigstore and upload to GitHub Release
needs: publish-to-pypi
runs-on: ubuntu-latest
permissions:
contents: write # Required to create GitHub Releases
id-token: write # Required for sigstore
steps:
- name: Download distribution packages
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:
GITHUB_TOKEN: ${{ github.token }}
run: |
# $GITHUB_REF_NAME is the tag name, e.g. 'v1.0.0'
gh release create "$GITHUB_REF_NAME" \
--repo "$GITHUB_REPOSITORY" \
--title "Release $GITHUB_REF_NAME" \
--notes "See CHANGELOG for details."
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
gh release upload "$GITHUB_REF_NAME" dist/** \
--repo "$GITHUB_REPOSITORY"