-
Notifications
You must be signed in to change notification settings - Fork 91
134 lines (110 loc) · 3.82 KB
/
Copy pathpublish-moss-chunking.yml
File metadata and controls
134 lines (110 loc) · 3.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
name: Publish moss-chunking
permissions:
contents: read
on:
workflow_dispatch:
concurrency:
group: moss-chunking-release
cancel-in-progress: false
jobs:
determine-version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.compute.outputs.version }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Read version from pyproject
id: compute
shell: python
run: |
import os, pathlib, re, sys
text = pathlib.Path("packages/moss-chunking/pyproject.toml").read_text(encoding="utf-8")
match = re.search(r'(?m)^version\s*=\s*"([^"]+)"', text)
if not match:
print("Could not find version in pyproject", file=sys.stderr)
sys.exit(1)
version = match.group(1)
out = pathlib.Path(os.environ["GITHUB_OUTPUT"])
with out.open("a", encoding="utf-8") as fh:
fh.write(f"version={version}\n")
print(f"Publishing version: {version}")
# Build + smoke-test on every supported Python version. Publishing waits for
# the whole matrix (see the publish job's `needs`), so a failure on any
# version blocks the upload/tag instead of racing it.
build-test:
needs: determine-version
strategy:
fail-fast: false
matrix:
python: ["3.10", "3.11", "3.12", "3.13", "3.14"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Install build tooling
run: |
python -m pip install --upgrade pip
pip install build
- name: Build distributions
working-directory: packages/moss-chunking
run: |
rm -rf dist
python -m build
- name: Smoke test import
shell: python
run: |
import glob, subprocess, sys
wheels = glob.glob("packages/moss-chunking/dist/*.whl")
if not wheels:
raise SystemExit("No wheel found in dist/")
wheel = wheels[0]
subprocess.check_call([sys.executable, "-m", "pip", "install", "--force-reinstall", wheel])
import importlib
module = importlib.import_module("moss_chunking")
print("import ok; sample attrs:", dir(module)[:5])
# Only runs once every build-test matrix leg has passed.
publish:
needs: [determine-version, build-test]
runs-on: ubuntu-latest
permissions:
contents: write
env:
VERSION: ${{ needs.determine-version.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Fail if this version was already released
run: |
git fetch --tags --force
if git rev-parse "moss-chunking-v${VERSION}" >/dev/null 2>&1; then
echo "::error::moss-chunking v${VERSION} is already tagged/released; bump the version in pyproject.toml before releasing."
exit 1
fi
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install build tooling
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build distributions
working-directory: packages/moss-chunking
run: |
rm -rf dist
python -m build
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
twine upload packages/moss-chunking/dist/*
- name: Tag release
run: |
git config user.name "github-actions"
git config user.email "github-actions@users.noreply.github.com"
git tag "moss-chunking-v${VERSION}"
git push origin "moss-chunking-v${VERSION}"