1- name : Publish to TestPyPI
1+ name : CI & Publish to TestPyPI
22
33on :
44 push :
77
88env :
99 REPO_ALIAS : rz-sample
10- TEST_PYPI_URL : https://test.pypi.org/legacy/
10+ TEST_PYPI_URL : https://test.pypi.org
1111
1212jobs :
13- build-and-publish :
13+ # JOB 1: Quality Check
14+ lint :
1415 runs-on : ubuntu-latest
16+ steps :
17+ - uses : actions/checkout@v4
18+ - name : Set up Python
19+ uses : actions/setup-python@v5
20+ with :
21+ python-version : " 3.11"
22+
23+ - name : Install Linting Tools
24+ run : |
25+ python -m pip install --upgrade pip
26+ pip install ruff
27+
28+ - name : Run Ruff Check
29+ run : ruff check .
1530
31+ - name : Run Ruff Format Check
32+ run : ruff format --check .
33+
34+ # JOB 2: Build and Publish (Depends on Lint passing)
35+ build-and-publish :
36+ needs : lint # This ensures publishing ONLY happens if linting passes
37+ runs-on : ubuntu-latest
1638 steps :
1739 - name : Checkout code
1840 uses : actions/checkout@v4
@@ -27,13 +49,23 @@ jobs:
2749 curl -sSL https://install.python-poetry.org | python3 -
2850 echo "$HOME/.local/bin" >> $GITHUB_PATH
2951
30- - name : Configure Poetry for TestPyPI
52+ - name : Check if version exists
53+ id : check_version
3154 run : |
32- # Use the variables defined in the 'env' section
33- poetry config repositories.${{ env.REPO_ALIAS }} ${{ env.TEST_PYPI_URL }}
34- poetry config pypi-token.${{ env.REPO_ALIAS }} ${{ secrets.TEST_PYPI_TOKEN }}
55+ PACKAGE_NAME=$(poetry version | awk '{print $1}')
56+ PACKAGE_VERSION=$(poetry version --short)
57+ STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://test.pypi.org)
58+
59+ if [ "$STATUS" == "200" ]; then
60+ echo "Version $PACKAGE_VERSION already exists. Skipping."
61+ echo "should_publish=false" >> $GITHUB_OUTPUT
62+ else
63+ echo "should_publish=true" >> $GITHUB_OUTPUT
64+ fi
3565
36- - name : Build and Publish
66+ - name : Configure and Publish
67+ if : steps.check_version.outputs.should_publish == 'true'
3768 run : |
38- # Automatically uses the alias for the -r flag
69+ poetry config repositories.${{ env.REPO_ALIAS }} ${{ env.TEST_PYPI_URL }}
70+ poetry config pypi-token.${{ env.REPO_ALIAS }} ${{ secrets.TEST_PYPI_TOKEN }}
3971 poetry publish -r ${{ env.REPO_ALIAS }} --build
0 commit comments