Skip to content

Commit 1f90a6a

Browse files
committed
[main]: update workflow for pypi
1 parent 010dc2f commit 1f90a6a

2 files changed

Lines changed: 94 additions & 12 deletions

File tree

.github/workflows/publish.yml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
name: CI & Publish to TestPyPI
2-
run-name: Publish Package to TestPyPI
1+
name: Build & Publish to PyPI
2+
run-name: Publish Package to PyPI
33

44
on:
55
push:
66
branches:
7-
- main
7+
- release
88

9-
env:
10-
REPO_ALIAS: rz-sample
11-
TEST_PYPI_URL: https://test.pypi.org/legacy/
9+
concurrency:
10+
group: pypi-publish
11+
cancel-in-progress: true
1212

1313
jobs:
1414
lint:
@@ -27,6 +27,9 @@ jobs:
2727
build-and-publish:
2828
needs: lint
2929
runs-on: ubuntu-latest
30+
permissions:
31+
id-token: write
32+
contents: read
3033
steps:
3134
- name: Checkout code
3235
uses: actions/checkout@v5
@@ -38,13 +41,14 @@ jobs:
3841

3942
- name: Install Poetry
4043
run: |
41-
curl -sSL https://install.python-poetry.org | python3 -
44+
curl -sSL https://install.python-poetry.org | python3 - --version 1.8.3
4245
echo "$HOME/.local/bin" >> $GITHUB_PATH
4346
4447
- name: Check if version exists
4548
id: check_version
4649
run: |
4750
# 1. Get metadata from pyproject.toml
51+
poetry install --no-interaction --no-root
4852
PACKAGE_NAME=$(poetry version | awk '{print $1}')
4953
PACKAGE_VERSION=$(poetry version --short)
5054
@@ -53,7 +57,7 @@ jobs:
5357
5458
# 2. Check the SPECIFIC version JSON endpoint
5559
# We use the JSON API because it's reliable for bots
56-
URL="https://test.pypi.org/pypi/$PACKAGE_NAME/$PACKAGE_VERSION/json"
60+
URL="https://pypi.org/pypi/$PACKAGE_NAME/$PACKAGE_VERSION/json"
5761
STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$URL")
5862
5963
if [ "$STATUS" == "200" ]; then
@@ -67,12 +71,12 @@ jobs:
6771
- name: Configure and Publish
6872
if: steps.check_version.outputs.should_publish == 'true'
6973
run: |
70-
poetry config repositories.${{ env.REPO_ALIAS }} ${{ env.TEST_PYPI_URL }}
71-
poetry config pypi-token.${{ env.REPO_ALIAS }} ${{ secrets.TEST_PYPI_TOKEN }}
72-
poetry publish -r ${{ env.REPO_ALIAS }} --build
74+
# poetry config repositories.${{ env.REPO_ALIAS }} ${{ env.PYPI_URL }}
75+
# poetry config pypi-token.${{ env.REPO_ALIAS }} ${{ secrets.PYPI_TOKEN }}
76+
poetry publish --build
7377
7478
# Add Success Summary
7579
NAME=${{ steps.check_version.outputs.pkg_name }}
7680
VER=${{ steps.check_version.outputs.pkg_ver }}
7781
echo "### ✅ Success: Published $NAME v$VER" >> $GITHUB_STEP_SUMMARY
78-
echo "View your package on TestPyPI: [rz-sample](https://test.pypi.org/project/rz-sample/)" >> $GITHUB_STEP_SUMMARY
82+
echo "View your package on PyPI: [rz-sample](https://pypi.org/project/$NAME/)" >> $GITHUB_STEP_SUMMARY
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: CI & Publish to TestPyPI
2+
run-name: Publish Package to TestPyPI
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
9+
env:
10+
REPO_ALIAS: rz-sample
11+
TEST_PYPI_URL: https://test.pypi.org/legacy/
12+
13+
jobs:
14+
lint:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v5
18+
- name: Set up Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: "3.11"
22+
- name: Install Ruff
23+
run: pip install ruff
24+
- name: Run Ruff
25+
run: ruff check . && ruff format --check .
26+
27+
build-and-publish:
28+
needs: lint
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Checkout code
32+
uses: actions/checkout@v5
33+
34+
- name: Set up Python
35+
uses: actions/setup-python@v5
36+
with:
37+
python-version: "3.11"
38+
39+
- name: Install Poetry
40+
run: |
41+
curl -sSL https://install.python-poetry.org | python3 -
42+
echo "$HOME/.local/bin" >> $GITHUB_PATH
43+
44+
- name: Check if version exists
45+
id: check_version
46+
run: |
47+
# 1. Get metadata from pyproject.toml
48+
PACKAGE_NAME=$(poetry version | awk '{print $1}')
49+
PACKAGE_VERSION=$(poetry version --short)
50+
51+
echo "pkg_name=$PACKAGE_NAME" >> $GITHUB_OUTPUT
52+
echo "pkg_ver=$PACKAGE_VERSION" >> $GITHUB_OUTPUT
53+
54+
# 2. Check the SPECIFIC version JSON endpoint
55+
# We use the JSON API because it's reliable for bots
56+
URL="https://test.pypi.org/pypi/$PACKAGE_NAME/$PACKAGE_VERSION/json"
57+
STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$URL")
58+
59+
if [ "$STATUS" == "200" ]; then
60+
echo "should_publish=false" >> $GITHUB_OUTPUT
61+
echo "### ⏭️ Skip: Version $PACKAGE_VERSION already exists" >> $GITHUB_STEP_SUMMARY
62+
else
63+
echo "should_publish=true" >> $GITHUB_OUTPUT
64+
echo "### 🚀 New version $PACKAGE_VERSION detected" >> $GITHUB_STEP_SUMMARY
65+
fi
66+
67+
- name: Configure and Publish
68+
if: steps.check_version.outputs.should_publish == 'true'
69+
run: |
70+
poetry config repositories.${{ env.REPO_ALIAS }} ${{ env.TEST_PYPI_URL }}
71+
poetry config pypi-token.${{ env.REPO_ALIAS }} ${{ secrets.TEST_PYPI_TOKEN }}
72+
poetry publish -r ${{ env.REPO_ALIAS }} --build
73+
74+
# Add Success Summary
75+
NAME=${{ steps.check_version.outputs.pkg_name }}
76+
VER=${{ steps.check_version.outputs.pkg_ver }}
77+
echo "### ✅ Success: Published $NAME v$VER" >> $GITHUB_STEP_SUMMARY
78+
echo "View your package on TestPyPI: [rz-sample](https://test.pypi.org/project/rz-sample/)" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)