Skip to content

Commit 9e2a023

Browse files
committed
update github workflow
1 parent 59eff15 commit 9e2a023

File tree

1 file changed

+77
-20
lines changed

1 file changed

+77
-20
lines changed
Lines changed: 77 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
1+
# Workflow summary:
2+
# 1. Run
33

44
name: Python workflow
55

6-
on: [push, pull_request]
6+
on: push
77

8-
jobs:
8+
env:
9+
PRIMARY_PYTHON_VERSION: '3.12'
10+
PYPI_PACKAGE_NAME: 'ti-plm'
911

10-
test:
12+
jobs:
1113

14+
local-test:
1215
runs-on: ubuntu-latest
1316
strategy:
1417
fail-fast: false
1518
matrix:
1619
python-version: ["3.10", "3.11", "3.12", "3.13"]
17-
1820
steps:
1921
- name: Checkout
2022
uses: actions/checkout@v4
@@ -25,8 +27,7 @@ jobs:
2527
- name: Install dependencies
2628
run: |
2729
python -m pip install --upgrade pip
28-
python -m pip install flake8 pytest
29-
python -m pip install .
30+
python -m pip install ".[dev]"
3031
- name: Lint with flake8
3132
run: |
3233
# stop the build if there are Python syntax errors or undefined names
@@ -36,28 +37,84 @@ jobs:
3637
- name: Test with pytest
3738
run: |
3839
pytest
40+
- name: Build
41+
run: |
42+
python -m build
43+
- name: Save artifacts
44+
if: (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) && matrix.python-version == env.PRIMARY_PYTHON_VERSION
45+
uses: actions/upload-artifact@v4
46+
with:
47+
name: python-package-distributions
48+
path: dist/
49+
50+
upload-test-pypi:
51+
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
52+
runs-on: ubuntu-latest
53+
needs: local-test
54+
environment:
55+
name: testpypi
56+
url: https://test.pypi.org/p/${{ env.PYPI_PACKAGE_NAME }}
57+
permissions:
58+
id-token: write
59+
steps:
60+
- name: Download artifacts
61+
uses: actions/download-artifact@v4
62+
with:
63+
name: python-package-distributions
64+
path: dist/
65+
- name: Publish to TestPyPI
66+
uses: pypa/gh-action-pypi-publish@release/v1
67+
with:
68+
repository-url: https://test.pypi.org/legacy/
3969

40-
build:
41-
42-
if: startsWith(github.ref, 'refs/tags/v')
70+
test-from-test-pypi:
71+
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
4372
runs-on: ubuntu-latest
44-
needs: test
73+
needs: upload-test-pypi
4574
steps:
46-
- name: Checkout
47-
uses: actions/checkout@v4
48-
- name: Set up Python 3.12
75+
- name: Set up Python ${{ env.PRIMARY_PYTHON_VERSION }}
4976
uses: actions/setup-python@v3
5077
with:
51-
python-version: '3.12'
78+
python-version: ${{ env.PRIMARY_PYTHON_VERSION }}
5279
- name: Install dependencies
5380
run: |
5481
python -m pip install --upgrade pip
55-
pip install build
56-
- name: Build
82+
pip install pytest ${{ env.PYPI_PACKAGE_NAME }} --extra-index-url https://test.pypi.org/simple/
83+
- name: Test with pytest
5784
run: |
58-
python -m build
85+
pytest
86+
87+
final-release:
88+
if: startsWith(github.ref, 'refs/tags/v')
89+
runs-on: ubuntu-latest
90+
needs: test-from-test-pypi
91+
environment:
92+
name: testpypi
93+
url: https://pypi.org/p/${{ env.PYPI_PACKAGE_NAME }}
94+
permissions:
95+
id-token: write
96+
steps:
97+
- name: Download artifacts
98+
uses: actions/download-artifact@v4
99+
with:
100+
name: python-package-distributions
101+
path: dist/
102+
- name: Validate version
103+
run: |
104+
TAG_VERSION=${{ github.ref_name }}
105+
TAG_VERSION=${TAG_VERSION#v}
106+
WHL_VERSION=$(unzip -p dist/*.whl '*/METADATA' | grep '^Version:' | awk '{print $2}')
107+
WHL_VERSION=${WHL_VERSION#v}
108+
if [ "$TAG_VERSION" != "$WHL_VERSION" ]; then
109+
echo "Version mismatch: Git tag version ($TAG_VERSION) does not match wheel version ($WHL_VERSION)"
110+
exit 1
111+
fi
59112
- name: Create GitHub Release
60113
env:
61114
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62115
run: |
63-
gh release create "${{ github.ref_name }}" dist/* --title "${{ github.ref_name }}" --notes "Release ${GITHUB_REF_NAME}"
116+
gh release create "${{ github.ref_name }}" dist/* --title "${{ github.ref_name }}" --notes "Release ${GITHUB_REF_NAME}"
117+
- name: Publish to PyPI
118+
uses: pypa/gh-action-pypi-publish@release/v1
119+
with:
120+
repository-url: https://pypi.org/legacy/

0 commit comments

Comments
 (0)