Repository navigation
192 lines (159 loc) · 4.82 KB
/
Copy pathrelease.yaml
File metadata and controls
192 lines (159 loc) · 4.82 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
name: Release
on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+"
- "[0-9]+.[0-9]+.[0-9]+a[0-9]+"
- "[0-9]+.[0-9]+.[0-9]+b[0-9]+"
- "[0-9]+.[0-9]+.[0-9]+rc[0-9]+"
permissions:
contents: read
env:
PACKAGE_NAME: rinthdown
jobs:
details:
name: Extract release details
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.release.outputs.new_version }}
tag_name: ${{ steps.release.outputs.tag_name }}
steps:
- name: Extract tag
id: release
shell: bash
env:
TAG_NAME: ${{ github.ref_name }}
run: |
set -euo pipefail
if [[ ! "$TAG_NAME" =~ ^[0-9]+\.[0-9]+\.[0-9]+(a[0-9]+|b[0-9]+|rc[0-9]+)?$ ]]; then
echo "Invalid release tag: $TAG_NAME"
exit 1
fi
echo "new_version=$TAG_NAME" >> "$GITHUB_OUTPUT"
echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT"
echo "Release version: $TAG_NAME"
check_pypi:
name: Check PyPI version
needs: details
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: "3.12"
- name: Compare versions
env:
NEW_VERSION: ${{ needs.details.outputs.new_version }}
PACKAGE_NAME: ${{ env.PACKAGE_NAME }}
run: |
set -euo pipefail
python -m pip install packaging
python - <<'PY'
import json
import os
import urllib.error
import urllib.request
from packaging.version import InvalidVersion, Version
package = os.environ["PACKAGE_NAME"]
new_version = Version(os.environ["NEW_VERSION"])
url = f"https://pypi.org/pypi/{package}/json"
try:
with urllib.request.urlopen(url, timeout=20) as response:
data = json.load(response)
except urllib.error.HTTPError as error:
if error.code != 404:
raise
data = None
if data is None:
print(f"{package} does not exist on PyPI yet.")
raise SystemExit(0)
versions = []
for version in data.get("releases", {}):
try:
versions.append(Version(version))
except InvalidVersion:
continue
if not versions:
print("No valid previous versions found on PyPI.")
raise SystemExit(0)
latest = max(versions)
print(f"Latest version on PyPI: {latest}")
print(f"New release version: {new_version}")
if new_version <= latest:
raise SystemExit(
f"Release {new_version} must be newer than {latest}."
)
print("Version check passed.")
PY
setup_and_build:
name: Build distributions
needs: [details, check_pypi]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: "3.12"
- name: Install Poetry
run: |
python -m pip install poetry
- name: Set project version
env:
NEW_VERSION: ${{ needs.details.outputs.new_version }}
run: |
poetry version "$NEW_VERSION"
- name: Install dependencies
run: poetry install --sync --no-interaction
- name: Build distributions
run: poetry build
- name: Upload distributions
uses: actions/upload-artifact@v7
with:
name: dist
path: dist/
if-no-files-found: error
retention-days: 7
pypi_publish:
name: Publish to PyPI
needs: [details, setup_and_build]
runs-on: ubuntu-latest
environment:
name: release
url: https://pypi.org/project/rinthdown/
permissions:
id-token: write
steps:
- name: Download distributions
uses: actions/download-artifact@v7
with:
name: dist
path: dist/
- name: Publish distributions
uses: pypa/gh-action-pypi-publish@release/v1
github_release:
name: Create GitHub Release
needs: [details, setup_and_build, pypi_publish]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Download distributions
uses: actions/download-artifact@v7
with:
name: dist
path: dist/
- name: Create release
env:
GH_TOKEN: ${{ github.token }}
TAG_NAME: ${{ needs.details.outputs.tag_name }}
run: |
set -euo pipefail
gh release create "$TAG_NAME" dist/* \
--title "$TAG_NAME" \
--generate-notes