[main]: update workflow #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI & Publish to TestPyPI | |
| on: | |
| push: | |
| branches: | |
| - main | |
| env: | |
| REPO_ALIAS: rz-sample | |
| TEST_PYPI_URL: https://test.pypi.org | |
| jobs: | |
| # JOB 1: Quality Check | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Install Linting Tools | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install ruff | |
| - name: Run Ruff Check | |
| run: ruff check . | |
| - name: Run Ruff Format Check | |
| run: ruff format --check . | |
| # JOB 2: Build and Publish (Depends on Lint passing) | |
| build-and-publish: | |
| needs: lint # This ensures publishing ONLY happens if linting passes | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - 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: | | |
| PACKAGE_NAME=$(poetry version | awk '{print $1}') | |
| PACKAGE_VERSION=$(poetry version --short) | |
| STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://test.pypi.org) | |
| if [ "$STATUS" == "200" ]; then | |
| echo "Version $PACKAGE_VERSION already exists. Skipping." | |
| echo "should_publish=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "should_publish=true" >> $GITHUB_OUTPUT | |
| 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 |