|
1 | | -# Workflow to upload a Python Package using Twine when a release is created |
2 | | -name: Release to PyPI |
| 1 | +# Workflow to upload a Python Package when a release is created |
| 2 | +name: Publish to PyPI |
3 | 3 |
|
4 | 4 | on: |
5 | 5 | release: |
6 | 6 | types: [released] |
7 | 7 |
|
8 | 8 | permissions: |
| 9 | + id-token: write |
9 | 10 | contents: read |
10 | 11 |
|
11 | 12 | jobs: |
12 | 13 | deploy: |
13 | 14 | runs-on: ubuntu-latest |
| 15 | + environment: |
| 16 | + name: pypi |
14 | 17 | steps: |
15 | | - - uses: actions/checkout@v4 |
16 | | - |
17 | | - - name: Set up Python |
18 | | - uses: actions/setup-python@v5 |
19 | | - with: |
20 | | - python-version: '3.x' |
21 | | - |
22 | | - - name: Install build dependencies |
23 | | - run: | |
24 | | - python -m pip install --upgrade pip |
25 | | - pip install build |
26 | | -
|
27 | | - - name: Build package |
28 | | - run: python -m build |
29 | | - |
30 | | - - name: Publish to Test PyPI |
31 | | - uses: pypa/gh-action-pypi-publish@release/v1 |
32 | | - with: |
33 | | - user: __token__ |
34 | | - password: ${{ secrets.PYPI_TEST_API_TOKEN }} |
35 | | - repository-url: https://test.pypi.org/legacy/ |
36 | | - |
37 | | - - name: Install from testpypi and import |
38 | | - shell: bash |
39 | | - run: | |
40 | | - sleep 5 |
41 | | - while [ "${{ github.ref_name }}" != $(pip index versions -i https://test.pypi.org/simple --pre market-analy | cut -d'(' -f2 | cut -d')' -f1 | sed 1q) ];\ |
42 | | - do echo "waiting for package to appear in test index, sleeping 5s"; sleep 5s; echo "woken up"; done |
43 | | - pip install --index-url https://test.pypi.org/simple market-analy==${{ github.ref_name }} --no-deps |
44 | | - pip install -r etc/requirements.txt |
45 | | - python -c 'import market_analy;print(market_analy.__version__)' |
46 | | -
|
47 | | - - name: Clean pip |
48 | | - run: | |
49 | | - pip uninstall -y market_analy |
50 | | - pip cache purge |
51 | | -
|
52 | | - - name: Publish to PyPI |
53 | | - uses: pypa/gh-action-pypi-publish@release/v1 |
54 | | - with: |
55 | | - user: __token__ |
56 | | - password: ${{ secrets.PYPI_API_TOKEN }} |
57 | | - |
58 | | - - name: Install and import |
59 | | - shell: bash |
60 | | - run: | |
61 | | - sleep 5 |
62 | | - while [ "${{ github.ref_name }}" != $(pip index versions -i https://pypi.org/simple --pre market-analy | cut -d'(' -f2 | cut -d')' -f1 | sed 1q) ];\ |
63 | | - do echo "waiting for package to appear in index, sleeping 5s"; sleep 5s; echo "woken up"; done |
64 | | - pip install --index-url https://pypi.org/simple market-analy==${{ github.ref_name }} |
65 | | - python -c 'import market_analy;print(market_analy.__version__)' |
| 18 | + - uses: actions/checkout@v5 |
| 19 | + - name: Install uv |
| 20 | + uses: astral-sh/setup-uv@v6 |
| 21 | + - name: Install Python |
| 22 | + run: uv python install |
| 23 | + - name: Build |
| 24 | + run: uv build |
| 25 | + |
| 26 | + - name: Publish to Test PyPI |
| 27 | + run: uv publish --index testpypi |
| 28 | + - name: Check test install and import |
| 29 | + run: | |
| 30 | + sleep 5 # Wait for Test Pypi to publish |
| 31 | + # Include pypi index for deps not available from test pypi... |
| 32 | + uv run \ |
| 33 | + --with market-analy \ |
| 34 | + --refresh-package market-analy \ |
| 35 | + --index https://test.pypi.org/simple \ |
| 36 | + --index https://pypi.org/simple \ |
| 37 | + --index-strategy unsafe-best-match \ |
| 38 | + --no-project \ |
| 39 | + --isolated \ |
| 40 | + -- \ |
| 41 | + python -c 'import market_analy; print(f"{market_analy.__version__=}")' |
| 42 | +
|
| 43 | + - name: Publish to PyPI |
| 44 | + run: uv publish |
| 45 | + - name: Check install and import |
| 46 | + run: | |
| 47 | + sleep 5 # Wait for Pypi to publish |
| 48 | + uv run \ |
| 49 | + --with market-analy \ |
| 50 | + --refresh-package market-analy \ |
| 51 | + --no-project \ |
| 52 | + --isolated \ |
| 53 | + -- \ |
| 54 | + python -c 'import market_analy;print(f"{market_analy.__version__=}")' |
0 commit comments