-
Notifications
You must be signed in to change notification settings - Fork 5
146 lines (122 loc) · 4.76 KB
/
Copy pathpypi-publish.yml
File metadata and controls
146 lines (122 loc) · 4.76 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
135
136
137
138
139
140
141
142
143
144
145
146
name: Publish Python SDK to PyPI
on:
release:
types: [created]
workflow_dispatch:
inputs:
environment:
description: 'Environment'
required: true
default: 'test'
type: choice
options:
- test
- prod
jobs:
publish-testpypi:
if: github.event.inputs.environment == 'test' || (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'test')
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/projects/a3m-router
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install build twine toml
- name: Get version
id: version
run: |
VERSION=$(python -c "import toml; print(toml.load('python/pyproject.toml')['project']['version'])")
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Check if version exists on Test PyPI
id: exists-testpypi
run: |
EXISTS=$(curl -s "https://test.pypi.org/pypi/a3m-router/${{ steps.version.outputs.version }}/json" | python3 -c "import sys,json; d=json.load(sys.stdin); print('yes' if d.get('info',{}).get('version') == '${{ steps.version.outputs.version }}' else 'no')" 2>/dev/null || echo "no")
echo "exists=$EXISTS" >> $GITHUB_OUTPUT
echo "Version ${{ steps.version.outputs.version }} on Test PyPI: $EXISTS"
if [ "$EXISTS" == "yes" ]; then
echo "SKIP_UPLOAD=true" >> $GITHUB_OUTPUT
fi
- name: Build package
if: steps.exists-testpypi.outputs.SKIP_UPLOAD != 'true'
run: |
cd python
python -m build
- name: Publish to Test PyPI
if: steps.exists-testpypi.outputs.SKIP_UPLOAD != 'true'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TEST_TOKEN }}
run: |
cd python
python -m twine upload --repository testpypi dist/*
- name: Already published notice
if: steps.exists-testpypi.outputs.SKIP_UPLOAD == 'true'
run: echo "Version ${{ steps.version.outputs.version }} already exists on Test PyPI — skipping upload"
publish-pypi:
if: github.event.inputs.environment == 'prod' || github.event_name == 'release'
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/projects/a3m-router
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install build twine toml
- name: Get version
id: version
run: |
VERSION=$(python -c "import toml; print(toml.load('python/pyproject.toml')['project']['version'])")
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Check if version exists on PyPI
id: exists-pypi
run: |
EXISTS=$(curl -s "https://pypi.org/pypi/a3m-router/${{ steps.version.outputs.version }}/json" | python3 -c "import sys,json; d=json.load(sys.stdin); print('yes' if d.get('info',{}).get('version') == '${{ steps.version.outputs.version }}' else 'no')" 2>/dev/null || echo "no")
echo "exists=$EXISTS" >> $GITHUB_OUTPUT
echo "Version ${{ steps.version.outputs.version }} on PyPI: $EXISTS"
if [ "$EXISTS" == "yes" ]; then
echo "SKIP_UPLOAD=true" >> $GITHUB_OUTPUT
fi
- name: Build package
if: steps.exists-pypi.outputs.SKIP_UPLOAD != 'true'
run: |
cd python
python -m build
- name: Publish to PyPI
if: steps.exists-pypi.outputs.SKIP_UPLOAD != 'true'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
cd python
python -m twine upload dist/*
- name: Already published notice
if: steps.exists-pypi.outputs.SKIP_UPLOAD == 'true'
run: echo "Version ${{ steps.version.outputs.version }} already exists on PyPI — skipping upload"
test-package:
runs-on: ubuntu-latest
needs: publish-testpypi
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install from Test PyPI
env:
TWINE_PASSWORD: ${{ secrets.PYPI_TEST_TOKEN }}
run: |
pip install --index-url https://test.pypi.org/simple/ a3m-router
- name: Test import
run: |
python -c "from a3m import A3MRouter, __version__; print(f'A3M Router SDK v{__version__} installed successfully!')"