-
Notifications
You must be signed in to change notification settings - Fork 1
78 lines (66 loc) · 2.57 KB
/
Copy pathpublish.yml
File metadata and controls
78 lines (66 loc) · 2.57 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
name: CI & Publish to TestPyPI
run-name: Publish Package to TestPyPI
on:
push:
branches:
- main
env:
REPO_ALIAS: rz-sample
TEST_PYPI_URL: https://test.pypi.org/legacy/
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install Ruff
run: pip install ruff
- name: Run Ruff
run: ruff check . && ruff format --check .
build-and-publish:
needs: lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Check if version exists
id: check_version
run: |
# 1. Get metadata from pyproject.toml
PACKAGE_NAME=$(poetry version | awk '{print $1}')
PACKAGE_VERSION=$(poetry version --short)
echo "pkg_name=$PACKAGE_NAME" >> $GITHUB_OUTPUT
echo "pkg_ver=$PACKAGE_VERSION" >> $GITHUB_OUTPUT
# 2. Check the SPECIFIC version JSON endpoint
# We use the JSON API because it's reliable for bots
URL="https://test.pypi.org/pypi/$PACKAGE_NAME/$PACKAGE_VERSION/json"
STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$URL")
if [ "$STATUS" == "200" ]; then
echo "should_publish=false" >> $GITHUB_OUTPUT
echo "### ⏭️ Skip: Version $PACKAGE_VERSION already exists" >> $GITHUB_STEP_SUMMARY
else
echo "should_publish=true" >> $GITHUB_OUTPUT
echo "### 🚀 New version $PACKAGE_VERSION detected" >> $GITHUB_STEP_SUMMARY
fi
- name: Configure and Publish
if: steps.check_version.outputs.should_publish == 'true'
run: |
poetry config repositories.${{ env.REPO_ALIAS }} ${{ env.TEST_PYPI_URL }}
poetry config pypi-token.${{ env.REPO_ALIAS }} ${{ secrets.TEST_PYPI_TOKEN }}
poetry publish -r ${{ env.REPO_ALIAS }} --build
# Add Success Summary
NAME=${{ steps.check_version.outputs.pkg_name }}
VER=${{ steps.check_version.outputs.pkg_ver }}
echo "### ✅ Success: Published $NAME v$VER" >> $GITHUB_STEP_SUMMARY
echo "View your package on TestPyPI: [rz-sample](https://test.pypi.org/project/rz-sample/)" >> $GITHUB_STEP_SUMMARY