-
Notifications
You must be signed in to change notification settings - Fork 3
127 lines (107 loc) · 3.83 KB
/
publish.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
name: Publish Python Distribution [PyPi & GH Release | TestPyPi]
on:
push:
branches:
- main
tags:
- '*'
workflow_dispatch:
jobs:
prepare-and-check:
runs-on: ubuntu-latest
outputs:
publish_to_pypi: ${{ steps.version_check.outputs.publish_to_pypi }}
publish_to_testpypi: ${{ steps.version_check.outputs.publish_to_testpypi }}
version: ${{ steps.version_check.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies for version check
run: |
python -m pip install --upgrade pip
pip install requests
- name: Check version on PyPI or TestPyPI
id: version_check
run: |
python3 check_version.py ${{ github.ref }}
env:
GITHUB_OUTPUT: ${{ github.output }}
build-and-publish:
needs: prepare-and-check
if: needs.prepare-and-check.outputs.publish_to_pypi == 'true' || needs.prepare-and-check.outputs.publish_to_testpypi == 'true'
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 build dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build package
run: |
python setup.py sdist bdist_wheel
- name: Upload distribution packages as artifacts
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/*
- name: Publish to PyPI
if: needs.prepare-and-check.outputs.publish_to_pypi == 'true'
run: twine upload dist/*
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
- name: Publish to TestPyPI
if: needs.prepare-and-check.outputs.publish_to_testpypi == 'true'
run: twine upload --repository-url https://test.pypi.org/legacy/ dist/*
env:
TWINE_USERNAME: ${{ secrets.TEST_PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_PASSWORD }}
create-release:
needs: [prepare-and-check, build-and-publish]
if: needs.prepare-and-check.outputs.publish_to_pypi == 'true'
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
steps:
- uses: actions/checkout@v4
- name: Download distribution packages for release
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Sign the distributions with Sigstore
uses: sigstore/gh-action-sigstore-python@v2.1.1
with:
inputs: ./dist/*.tar.gz ./dist/*.whl
- name: Set Release Version Env
run: echo "RELEASE_VERSION=${{ needs.prepare-and-check.outputs.version }}" >> $GITHUB_ENV
- name: Draft Release
id: draft_release
uses: release-drafter/release-drafter@v6
with:
commitish: main
tag: v${{ env.RELEASE_VERSION }}
name: Release ${{ env.RELEASE_VERSION }}
version: ${{ env.RELEASE_VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_VERSION: ${{ needs.prepare-and-check.outputs.version }}
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_VERSION: ${{ needs.prepare-and-check.outputs.version }}
with:
tag_name: v${{ env.RELEASE_VERSION }}
release_name: Release ${{ env.RELEASE_VERSION }}
body: ${{ steps.draft_release.outputs.body }}
draft: false
prerelease: false