@@ -2,11 +2,15 @@ name: CI/CD
22
33on :
44 push :
5+ branches :
6+ - main
7+ tags :
8+ - ' v*'
59 pull_request :
610 workflow_dispatch :
711
812env :
9- PYTHON_VERSION : ' 3.11'
13+ PYTHON_VERSION : ' 3.11.9 '
1014
1115jobs :
1216 dependencies :
@@ -16,28 +20,22 @@ jobs:
1620 - uses : actions/checkout@v4
1721 name : Checkout
1822
19- - name : Load Cached Poetry
20- id : cached-poetry
21- uses : actions/cache@v4
22- with :
23- path : |
24- ~/.cache
25- ~/.local
26- key : poetry-${{ hashFiles('poetry.lock') }}-${{ env.PYTHON_VERSION}}
27-
28- - uses : actions/setup-python@v5
29- name : Setup Python
23+ - name : Setup Python
24+ uses : actions/setup-python@v5
3025 with :
3126 python-version : ${{ env.PYTHON_VERSION }}
32- architecture : x64
3327
34- - name : Install Poetry
35- uses : snok/install-poetry@v1
28+ - name : Install uv
29+ uses : astral-sh/setup-uv@v3
3630 with :
37- virtualenvs-create : true
31+ enable-cache : true
32+
33+ - name : Create virtualenv
34+ run : |
35+ uv venv --system-site-packages
3836
3937 - name : Install dependencies
40- run : poetry install --with dev
38+ run : uv sync --frozen
4139
4240 type-check :
4341 name : Type Check
@@ -48,23 +46,18 @@ jobs:
4846 - uses : actions/checkout@v4
4947 name : Checkout
5048
51- - uses : actions/setup-python@v5
52- name : Setup Python
49+ - name : Install uv
50+ uses : astral-sh/setup-uv@v3
5351 with :
54- python-version : ${{ env.PYTHON_VERSION }}
55- architecture : x64
52+ enable-cache : true
5653
57- - name : Load Cached Poetry
58- id : cached-poetry
59- uses : actions/cache/restore@v4
60- with :
61- path : |
62- ~/.cache
63- ~/.local
64- key : poetry-${{ hashFiles('poetry.lock') }}-${{ env.PYTHON_VERSION}}
54+ - name : Create virtualenv
55+ run : |
56+ uv venv --system-site-packages
6557
6658 - name : Type Check
67- run : poetry run poe typecheck
59+ run : |
60+ uv run --frozen poe typecheck
6861
6962 lint :
7063 name : Lint
@@ -79,19 +72,14 @@ jobs:
7972 uses : actions/setup-python@v5
8073 with :
8174 python-version : ${{ env.PYTHON_VERSION }}
82- architecture : x64
8375
84- - name : Load Cached Poetry
85- id : cached-poetry
86- uses : actions/cache/restore@v4
76+ - name : Install uv
77+ uses : astral-sh/setup-uv@v3
8778 with :
88- path : |
89- ~/.cache
90- ~/.local
91- key : poetry-${{ hashFiles('poetry.lock') }}-${{ env.PYTHON_VERSION}}
79+ enable-cache : true
9280
9381 - name : Lint
94- run : poetry run poe lint
82+ run : uvx ruff check
9583
9684 test :
9785 name : Test
@@ -109,19 +97,19 @@ jobs:
10997 uses : actions/setup-python@v5
11098 with :
11199 python-version : ${{ env.PYTHON_VERSION }}
112- architecture : x64
113100
114- - name : Load Cached Poetry
115- uses : actions/cache/restore@v4
116- id : cached-poetry
101+ - name : Install uv
102+ uses : astral-sh/setup-uv@v3
117103 with :
118- path : |
119- ~/.cache
120- ~/.local
121- key : poetry-${{ hashFiles('poetry.lock') }}-${{ env.PYTHON_VERSION}}
104+ enable-cache : true
105+
106+ - name : Create virtualenv
107+ run : |
108+ uv venv --system-site-packages
122109
123110 - name : Run Tests
124- run : poetry run poe test
111+ run : |
112+ uv run --frozen poe test --verbosity=2 --cov-report=xml --cov-report=html --log-level=DEBUG --log-cli-level=5
125113
126114 - name : Collect Store Snapshots
127115 uses : actions/upload-artifact@v4
@@ -160,50 +148,47 @@ jobs:
160148 name : Setup Python
161149 with :
162150 python-version : ${{ env.PYTHON_VERSION }}
163- architecture : x64
164151
165- - name : Load Cached Poetry
166- id : cached-poetry
167- uses : actions/cache/restore@v4
152+ - name : Install uv
153+ uses : astral-sh/setup-uv@v3
168154 with :
169- path : |
170- ~/.cache
171- ~/.local
172- key : poetry-${{ hashFiles('poetry.lock') }}-${{ env.PYTHON_VERSION}}
155+ enable-cache : true
173156
174157 - name : Extract Version
175158 id : extract-version
176159 run : |
177- echo "VERSION=$(poetry version --short)" >> "$GITHUB_OUTPUT"
178- echo "VERSION=$(poetry version --short)"
179- echo "NAME=$(poetry version | cut -d' ' -f1)" >> "$GITHUB_OUTPUT"
180- echo "NAME=$(poetry version | cut -d' ' -f1)"
160+ git fetch --prune --unshallow
161+ git fetch --depth=1 origin +refs/tags/*:refs/tags/*
162+ echo "VERSION=$(uvx hatch version)" >> "$GITHUB_OUTPUT"
163+ echo "VERSION=$(uvx hatch version)"
164+ echo "NAME=$(uvx hatch project metadata | jq -r .name)" >> "$GITHUB_OUTPUT"
165+ echo "NAME=$(uvx hatch project metadata | jq -r .name)"
181166
182167 - name : Extract Version from CHANGELOG.md
183168 run : |
184- VERSION_CHANGELOG=$(sed -n '3 s/## Version //p' CHANGELOG.md)
185- echo "VERSION_CHANGELOG=$VERSION_CHANGELOG"
186- if [ "${{ steps.extract-version.outputs.VERSION }}" != "$VERSION_CHANGELOG" ]; then
187- echo "Error: Version extracted from CHANGELOG.md does not match the version in pyproject.toml"
188- exit 1
169+ FIRST_HEADER=$(sed -n '/## /s/## //p' CHANGELOG.md | head -n 1)
170+ if [ "$FIRST_HEADER" == "Upcoming" ]; then
171+ # Check the version coming from extract-version starts with of x.y.z.devn
172+ if [[ "${{ steps.extract-version.outputs.VERSION }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.dev[0-9]+ ]]; then
173+ VERSION_CHANGELOG="This is a development version."
174+ else
175+ echo "Error: First header in CHANGELOG.md is 'Upcoming' but the version in pyproject.toml is not a development version."
176+ exit 1
177+ fi
189178 else
190- echo "Versions are consistent."
191- fi
192-
193- - name : Extract Version from Tag
194- if : startsWith(github.ref, 'refs/tags/v')
195- run : |
196- VERSION_TAG=$(sed 's/^v//' <<< ${{ github.ref_name }})
197- echo "VERSION_TAG=$VERSION_TAG"
198- if [ "${{ steps.extract-version.outputs.VERSION }}" != "$VERSION_TAG" ]; then
199- echo "Error: Version extracted from tag does not match the version in pyproject.toml"
200- exit 1
201- else
202- echo "Versions are consistent."
179+ VERSION_CHANGELOG=$(echo $FIRST_HEADER | sed 's/Version //')
180+ if [ "${{ steps.extract-version.outputs.VERSION }}" != "$VERSION_CHANGELOG" ]; then
181+ echo "Error: Version extracted from CHANGELOG.md does not match the version in pyproject.toml"
182+ exit 1
183+ else
184+ echo "Versions are consistent."
185+ fi
203186 fi
204187
205188 - name : Build
206- run : poetry build
189+ run :
190+ SETUPTOOLS_SCM_PRETEND_VERSION=${{
191+ steps.extract-version.outputs.VERSION }} uv build
207192
208193 - name : Upload wheel
209194 uses : actions/upload-artifact@v4
@@ -219,10 +204,12 @@ jobs:
219204 path : dist/*.tar.gz
220205 if-no-files-found : error
221206
222- pypi- publish :
223- name : Publish to PyPI
207+ publish :
208+ name : Publish
224209 if : >-
225- github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
210+ github.event_name == 'push' && github.ref == 'refs/heads/main' ||
211+ github.event_name == 'pull_request' && github.event.pull_request.base.ref
212+ == 'main'
226213 needs :
227214 - type-check
228215 - lint
@@ -231,7 +218,9 @@ jobs:
231218 runs-on : ubuntu-latest
232219 environment :
233220 name : pypi
234- url : https://pypi.org/p/${{ needs.build.outputs.name }}
221+ url :
222+ https://pypi.org/project/${{ needs.build.outputs.name }}/${{
223+ needs.build.outputs.version }}
235224 permissions :
236225 id-token : write
237226 steps :
@@ -245,11 +234,10 @@ jobs:
245234 name : binary
246235 path : dist
247236
248- - name : Publish package distributions to PyPI
237+ - name : Publish to PyPI
249238 uses : pypa/gh-action-pypi-publish@release/v1
250239 with :
251240 packages-dir : dist
252- verbose : true
253241
254242 release :
255243 if : github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
@@ -259,7 +247,7 @@ jobs:
259247 - lint
260248 - test
261249 - build
262- - pypi- publish
250+ - publish
263251 runs-on : ubuntu-latest
264252 environment :
265253 name : release
@@ -269,6 +257,9 @@ jobs:
269257 permissions :
270258 contents : write
271259 steps :
260+ - uses : actions/checkout@v4
261+ name : Checkout
262+
272263 - name : Procure Wheel
273264 uses : actions/download-artifact@v4
274265 with :
@@ -281,9 +272,6 @@ jobs:
281272 name : binary
282273 path : artifacts
283274
284- - uses : actions/checkout@v4
285- name : Checkout
286-
287275 - name : Extract Changelog
288276 id : changelog
289277 run : |
0 commit comments