-
Notifications
You must be signed in to change notification settings - Fork 9
153 lines (132 loc) Β· 4.4 KB
/
publish-to-pypi.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
name: Release
on:
push:
branches:
- main
- master
permissions:
id-token: write
contents: write
pull-requests: write
jobs:
check-repository:
name: Check if running in main repository
runs-on: ubuntu-latest
outputs:
is_main_repo: ${{ github.repository == 'funstory-ai/BabelDOC' }}
steps:
- run: echo "Running repository check"
build:
name: Build distribution π¦
needs: check-repository
if: needs.check-repository.outputs.is_main_repo == 'true'
runs-on: ubuntu-latest
outputs:
is_release: ${{ steps.check-version.outputs.tag }}
steps:
- uses: actions/checkout@v4
with:
persist-credentials: true
fetch-depth: 2
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup uv with Python 3.12
uses: astral-sh/setup-uv@4db96194c378173c656ce18a155ffc14a9fc4355 # v5.2.2
with:
python-version: "3.12"
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: Check if there is a parent commit
id: check-parent-commit
run: |
echo "sha=$(git rev-parse --verify --quiet HEAD^)" >> $GITHUB_OUTPUT
- name: Detect and tag new version
id: check-version
if: steps.check-parent-commit.outputs.sha
uses: salsify/action-detect-and-tag-new-version@b1778166f13188a9d478e2d1198f993011ba9864 # v2.0.3
with:
version-command: |
cat pyproject.toml | grep "version = " | head -n 1 | awk -F'"' '{print $2}'
- name: Install Dependencies
run: |
uv sync
- name: Bump version for developmental release
if: "! steps.check-version.outputs.tag"
run: |
version=$(bumpver update --patch --tag=final --dry 2>&1 | grep "New Version" | awk '{print $NF}') &&
bumpver update --set-version $version.dev$(date +%s)
- name: Build package
run: "uv build"
- name: Store the distribution packages
uses: actions/[email protected]
with:
name: python-package-distributions
path: dist/
publish-to-pypi:
name: Publish Python π distribution π¦ to PyPI
if: needs.build.outputs.is_release != ''
needs:
- check-repository
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/BabelDOC
permissions:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: python-package-distributions
path: dist/
- name: Publish distribution π¦ to PyPI
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4
publish-to-testpypi:
name: Publish Python π distribution π¦ to TestPyPI
if: needs.build.outputs.is_release == ''
needs:
- check-repository
- build
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/p/BabelDOC
permissions:
id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: python-package-distributions
path: dist/
- name: Publish distribution π¦ to TestPyPI
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4
with:
repository-url: https://test.pypi.org/legacy/
post-release:
name: Post Release Tasks
needs:
- check-repository
- build
- publish-to-pypi
- publish-to-testpypi
if: |
always() && needs.check-repository.outputs.is_main_repo == 'true' &&
(needs.publish-to-pypi.result == 'success' || needs.publish-to-testpypi.result == 'success')
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
persist-credentials: true
fetch-depth: 2
token: ${{ secrets.GITHUB_TOKEN }}
- name: Publish the release notes
uses: release-drafter/release-drafter@b1476f6e6eb133afa41ed8589daba6dc69b4d3f5 # v6.1.0
with:
publish: ${{ needs.build.outputs.is_release != '' }}
tag: ${{ needs.build.outputs.is_release }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}