-
Notifications
You must be signed in to change notification settings - Fork 0
160 lines (141 loc) · 4.63 KB
/
publish.yml
File metadata and controls
160 lines (141 loc) · 4.63 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
name: Publish to PyPI
on:
push:
branches: [main]
workflow_dispatch:
concurrency:
group: publish-${{ github.ref }}
cancel-in-progress: false
jobs:
build:
name: Build distribution
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
permissions:
contents: read
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Generate date-based version
id: version
env:
PACKAGE_NAME: acedatacloud-scaffold
run: |
python - <<'PY'
import json
import os
import urllib.request
from datetime import datetime, timezone
package_name = os.environ['PACKAGE_NAME']
date_prefix = datetime.now(timezone.utc).strftime('%Y.%-m.%-d')
next_build = 0
try:
with urllib.request.urlopen(f'https://pypi.org/pypi/{package_name}/json', timeout=10) as response:
releases = json.load(response).get('releases', {})
builds = []
for release in releases:
if not release.startswith(f'{date_prefix}.'):
continue
parts = release.split('.')
if len(parts) != 4:
continue
try:
builds.append(int(parts[3]))
except ValueError:
continue
if builds:
next_build = max(builds) + 1
except Exception:
next_build = 0
version = f'{date_prefix}.{next_build}'
with open(os.environ['GITHUB_OUTPUT'], 'a', encoding='utf-8') as fh:
fh.write(f'version={version}\n')
print(f'Generated version: {version}')
PY
- name: Update package version
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
python - <<'PY'
import os
import pathlib
import re
version = os.environ['VERSION']
version_file = pathlib.Path('acedatacloud_scaffold/__version__.py')
content = version_file.read_text(encoding='utf-8')
updated = re.sub(
r'^VERSION = \([^\n]+\)$',
f'VERSION = ({", ".join(version.split("."))})',
content,
count=1,
flags=re.MULTILINE,
)
if updated == content:
raise SystemExit('Failed to update VERSION tuple in acedatacloud_scaffold/__version__.py')
version_file.write_text(updated, encoding='utf-8')
print(version_file.read_text(encoding='utf-8'))
PY
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build "twine>=6.1.0,<7.0.0"
- name: Build package
run: python -m build
- name: Check package metadata
run: twine check dist/*
- name: Upload distribution artifacts
uses: actions/upload-artifact@v7
with:
name: python-package-distributions
path: dist/
publish-pypi:
name: Publish to PyPI
needs: build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/acedatacloud-scaffold/${{ needs.build.outputs.version }}
permissions:
contents: read
steps:
- name: Download distribution artifacts
uses: actions/download-artifact@v8
with:
name: python-package-distributions
path: dist/
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
python -m pip install --upgrade pip
pip install "twine>=6.1.0,<7.0.0"
twine upload dist/*
create-release:
name: Create GitHub Release
if: github.event_name == 'push'
needs: [build, publish-pypi]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v6
- name: Download distribution artifacts
uses: actions/download-artifact@v8
with:
name: python-package-distributions
path: dist/
- name: Create Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
gh release create "v${{ needs.build.outputs.version }}" dist/* \
--title "v${{ needs.build.outputs.version }}" \
--generate-notes \
--repo '${{ github.repository }}' || echo "Release already exists, skipping"