forked from huggingface/OpenEnv
-
Notifications
You must be signed in to change notification settings - Fork 0
169 lines (143 loc) · 5.04 KB
/
Copy pathpublish-testpypi.yml
File metadata and controls
169 lines (143 loc) · 5.04 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
name: Publish OpenEnv to TestPyPI
# Requires a TestPyPI Trusted Publisher for:
# - repository: huggingface/OpenEnv
# - workflow: publish-testpypi.yml
# - environment: testpypi
on:
workflow_dispatch:
inputs:
version_suffix:
description: "PEP 440 suffix for the TestPyPI build, for example .dev123 or rc1. Defaults to .dev<run_number><run_attempt>."
required: false
type: string
permissions:
contents: read
env:
PACKAGE_NAME: openenv
jobs:
build:
name: Build TestPyPI distribution
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.11"
- name: Prepare TestPyPI version
id: version
env:
VERSION_SUFFIX: ${{ inputs.version_suffix }}
run: |
python - <<'PY'
import os
import pathlib
import re
import tomllib
pyproject = pathlib.Path("pyproject.toml")
data = tomllib.loads(pyproject.read_text())
current = data["project"]["version"]
base = current.split("+", 1)[0]
base = re.sub(r"(a|b|rc)\d+$", "", base)
base = re.sub(r"\.dev\d+$", "", base)
suffix = os.environ["VERSION_SUFFIX"].strip()
if not suffix:
suffix = f".dev{os.environ['GITHUB_RUN_NUMBER']}{os.environ['GITHUB_RUN_ATTEMPT']}"
if not re.fullmatch(r"(a|b|rc|\.dev)\d+", suffix):
raise SystemExit(
"version_suffix must be a PEP 440 pre/dev suffix like "
".dev123, rc1, a1, or b1"
)
version = f"{base}{suffix}"
text = pyproject.read_text()
text = re.sub(
r'^version\s*=\s*"[^"]+"',
f'version = "{version}"',
text,
count=1,
flags=re.MULTILINE,
)
pyproject.write_text(text)
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as output:
print(f"version={version}", file=output)
print(f"Prepared TestPyPI version: {version}")
PY
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build twine
- name: Build package
run: python -m build
- name: Check package metadata
run: python -m twine check dist/*
- name: Smoke-test built wheel
run: |
python -m venv .pkg-smoke
. .pkg-smoke/bin/activate
python -m pip install --upgrade pip
python -m pip install dist/*.whl
python - <<'PY'
import importlib.metadata
import openenv
installed = importlib.metadata.version("openenv")
assert openenv.__version__ == installed, (openenv.__version__, installed)
print(f"openenv {installed}")
PY
openenv --help
- name: Upload TestPyPI distribution artifact
uses: actions/upload-artifact@v7
with:
name: openenv-${{ steps.version.outputs.version }}-testpypi-dist
path: dist/
if-no-files-found: error
publish-to-testpypi:
name: Publish to TestPyPI
needs: build
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/project/openenv/${{ needs.build.outputs.version }}/
permissions:
contents: read
id-token: write
steps:
- name: Download TestPyPI distribution artifact
uses: actions/download-artifact@v8
with:
name: openenv-${{ needs.build.outputs.version }}-testpypi-dist
path: dist/
- name: Publish package distributions to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
- name: Verify install from TestPyPI
run: |
python -m venv .testpypi-verify
. .testpypi-verify/bin/activate
python -m pip install --upgrade pip
python -m pip install --index-url https://pypi.org/simple/ dist/*.whl
python -m pip uninstall -y openenv
for attempt in 1 2 3 4 5; do
if python -m pip install \
--no-deps \
--index-url https://test.pypi.org/simple/ \
"openenv==${{ needs.build.outputs.version }}"; then
break
fi
echo "Package is not visible on TestPyPI yet; retrying..."
sleep 30
done
python - <<'PY'
import importlib.metadata
import openenv
expected = "${{ needs.build.outputs.version }}"
installed = importlib.metadata.version("openenv")
assert installed == expected, (installed, expected)
assert openenv.__version__ == expected, (openenv.__version__, expected)
print(f"openenv {installed}")
PY