-
Notifications
You must be signed in to change notification settings - Fork 2
55 lines (46 loc) · 1.57 KB
/
python-ci.yml
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
name: Python Package CI and Publish
on:
push:
branches:
- main
pull_request:
branches:
- main
permissions:
contents: read # Allows the workflow to read repository contents
packages: write # Required to publish packages to PyPI
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.9"
- name: Install build tools
run: python -m pip install --upgrade pip setuptools wheel twine requests
- name: Build the package
run: |
python setup.py sdist bdist_wheel
- name: Check if version exists on PyPI
id: check-version
run: |
PACKAGE_NAME="auto-website-visitor"
VERSION=$(python setup.py --version)
STATUS_CODE=$(curl -o /dev/null -s -w "%{http_code}" https://pypi.org/project/$PACKAGE_NAME/$VERSION/)
if [ "$STATUS_CODE" -eq 200 ]; then
echo "The version $VERSION already exists on PyPI. Skipping upload."
echo "upload_required=false" >> $GITHUB_ENV
else
echo "Version $VERSION is not published on PyPI. Proceeding with upload."
echo "upload_required=true" >> $GITHUB_ENV
fi
- name: Publish to PyPI
if: env.upload_required == 'true'
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python -m twine upload dist/*