|
1 | | -name: Publish to PyPI |
| 1 | +# Generated initially using github-actions-wizard (https://github.com/cmdr2/github-actions-wizard) |
2 | 2 |
|
| 3 | +name: Publish to PyPI |
| 4 | +run-name: Deployment |
3 | 5 | on: |
4 | 6 | release: |
5 | | - types: [created] |
| 7 | + types: |
| 8 | + - created |
6 | 9 | workflow_run: |
7 | 10 | workflows: |
8 | 11 | - Update PCI Database |
9 | 12 | types: |
10 | 13 | - completed |
11 | 14 | workflow_dispatch: |
12 | | - |
13 | 15 | jobs: |
14 | | - build-and-publish: |
| 16 | + deploy: |
15 | 17 | runs-on: ubuntu-latest |
16 | | - environment: |
17 | | - name: pypi-prod |
18 | | - url: https://pypi.org/p/torchruntime |
19 | | - permissions: |
20 | | - contents: read |
21 | | - id-token: write |
22 | 18 | steps: |
23 | | - - uses: actions/checkout@v4 |
24 | | - with: |
25 | | - ref: main |
| 19 | + - name: Checkout |
| 20 | + uses: actions/checkout@v4 |
26 | 21 |
|
27 | | - - name: Set up Python |
28 | | - uses: actions/setup-python@v4 |
29 | | - with: |
30 | | - python-version: '3.x' |
| 22 | + - name: Set up Python |
| 23 | + uses: actions/setup-python@v4 |
| 24 | + with: |
| 25 | + python-version: 3.x |
31 | 26 |
|
32 | | - - name: Install dependencies |
33 | | - run: | |
34 | | - python -m pip install --upgrade pip |
35 | | - pip install build wheel pytest toml requests |
| 27 | + - name: Install dependencies |
| 28 | + run: |- |
| 29 | + python -m pip install --upgrade pip |
| 30 | + pip install build wheel pytest toml requests |
36 | 31 |
|
37 | | - - name: Check PyPI version |
38 | | - id: check-version |
39 | | - run: | |
40 | | - # Read version from pyproject.toml |
41 | | - TOML_VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])") |
| 32 | + - name: Check PyPI version |
| 33 | + id: check-version |
| 34 | + run: |- |
| 35 | + TOML_VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])") |
| 36 | + PYPI_VERSION=$(python -c "import requests; r = requests.get('https://pypi.org/pypi/torchruntime/json'); print(None if r.status_code == 404 else r.json()['info']['version'])") |
| 37 | + echo "Local version: $TOML_VERSION" |
| 38 | + echo "PyPI version: $PYPI_VERSION" |
| 39 | + if [ "$TOML_VERSION" = "$PYPI_VERSION" ]; then |
| 40 | + echo "Versions match. Skipping publish." |
| 41 | + echo "publish=false" >> $GITHUB_OUTPUT |
| 42 | + else |
| 43 | + echo "Versions differ. Proceeding with publish." |
| 44 | + echo "publish=true" >> $GITHUB_OUTPUT |
| 45 | + fi |
42 | 46 |
|
43 | | - # Get latest PyPI version using PyPI JSON API |
44 | | - PYPI_VERSION=$(python -c "import requests; print(requests.get('https://pypi.org/pypi/torchruntime/json').json()['info']['version'])") |
| 47 | + - name: Copy tests |
| 48 | + if: steps.check-version.outputs.publish == 'true' |
| 49 | + run: | |
| 50 | + cp -R tests torchruntime/ |
45 | 51 |
|
46 | | - echo "Local version: $TOML_VERSION" |
47 | | - echo "PyPI version: $PYPI_VERSION" |
| 52 | + - name: Build package |
| 53 | + if: steps.check-version.outputs.publish == 'true' |
| 54 | + run: python -m build |
48 | 55 |
|
49 | | - if [ "$TOML_VERSION" = "$PYPI_VERSION" ]; then |
50 | | - echo "Versions match. Skipping publish." |
51 | | - echo "publish=false" >> $GITHUB_OUTPUT |
52 | | - else |
53 | | - echo "Versions differ. Proceeding with publish." |
54 | | - echo "publish=true" >> $GITHUB_OUTPUT |
55 | | - fi |
| 56 | + - name: Install and test the package |
| 57 | + if: steps.check-version.outputs.publish == 'true' |
| 58 | + run: | |
| 59 | + mkdir /tmp/install-test |
| 60 | + cp dist/*.whl /tmp/install-test |
| 61 | + cd /tmp/install-test |
| 62 | + pip install *.whl |
56 | 63 |
|
57 | | - - name: Copy tests |
58 | | - if: steps.check-version.outputs.publish == 'true' |
59 | | - run: | |
60 | | - cp -R tests torchruntime/ |
| 64 | + pip show torchruntime |
| 65 | + python -m torchruntime --help # test invocation |
| 66 | + pytest --pyargs torchruntime # run tests |
61 | 67 |
|
62 | | - - name: Build package |
63 | | - if: steps.check-version.outputs.publish == 'true' |
64 | | - run: python -m build |
65 | | - |
66 | | - - name: Install and test the package |
67 | | - if: steps.check-version.outputs.publish == 'true' |
68 | | - run: | |
69 | | - mkdir /tmp/install-test |
70 | | - cp dist/*.whl /tmp/install-test |
71 | | - cd /tmp/install-test |
72 | | - pip install *.whl |
73 | | -
|
74 | | - pip show torchruntime |
75 | | - python -m torchruntime --help # test invocation |
76 | | - pytest --pyargs torchruntime # run tests |
77 | | -
|
78 | | - - name: Publish to PyPI |
79 | | - if: steps.check-version.outputs.publish == 'true' |
80 | | - uses: pypa/gh-action-pypi-publish@release/v1 |
81 | | - with: |
82 | | - # repository-url: https://test.pypi.org/legacy/ |
83 | | - verbose: true |
| 68 | + - name: Publish to PyPI |
| 69 | + if: steps.check-version.outputs.publish == 'true' |
| 70 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 71 | + with: |
| 72 | + verbose: true |
| 73 | + permissions: |
| 74 | + contents: read |
| 75 | + id-token: write |
0 commit comments