-
Notifications
You must be signed in to change notification settings - Fork 1
85 lines (74 loc) · 2.02 KB
/
publish_python.yaml
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
name: Publish Python Package
on:
push:
branches: [ main, develop ]
pull_request:
types:
- opened
env:
PACKAGE_NAME: crawlab-sdk
jobs:
build:
name: Build package
runs-on: ubuntu-latest
outputs:
version: ${{ steps.build.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install
- name: Build package
id: build
run: |
poetry build
echo "version=$(poetry version -s)" >> $GITHUB_OUTPUT
- name: Run tests
run: |
python -m pytest tests/
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
check_version:
name: Check version
needs: build
runs-on: ubuntu-latest
outputs:
is_new_version: ${{ steps.check.outputs.is_new_version }}
steps:
- name: Check package version
id: check
run: |
version="${{ needs.build.outputs.version }}"
status_code=$(curl -o /dev/null -s -w "%{http_code}" https://pypi.org/project/${{ env.PACKAGE_NAME }}/${version}/)
echo "status_code=${status_code}"
if [ "$status_code" = "200" ]; then
is_new_version=false
else
is_new_version=true
fi
echo "is_new_version=${is_new_version}" >> $GITHUB_OUTPUT
publish:
name: Publish to PyPI
needs: [build, check_version]
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
if: needs.check_version.outputs.is_new_version == 'true'
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1