Publish to TestPyPI #10
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: Publish to TestPyPI | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: 'Git Tag (Release) to validate and upload' | |
| required: true | |
| type: string | |
| jobs: | |
| validate-release: | |
| name: Validate Release Across Python Versions | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: ["3.9", "3.10", "3.11", "3.12"] | |
| fail-fast: false | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.inputs.tag }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Update pip | |
| run: python -m pip install --upgrade pip | |
| - name: Install wheel | |
| run: python -m pip install --upgrade wheel | |
| - name: Install dependencies | |
| run: | | |
| pip install -r ci/requirements.txt | |
| pip install . | |
| - name: Run tests | |
| run: pytest tests --cov solt --cov-report term-missing -v | |
| - name: Run black | |
| run: black --config=black.toml --check . | |
| - name: Run flake8 | |
| run: flake8 | |
| build-and-publish: | |
| name: Build and Publish to TestPyPI | |
| runs-on: ubuntu-latest | |
| needs: validate-release | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.inputs.tag }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Update pip | |
| run: python -m pip install --upgrade pip | |
| - name: Install wheel and build | |
| run: | | |
| python -m pip install --upgrade wheel | |
| python -m pip install build | |
| - name: Build package | |
| run: python -m build | |
| - name: Rename package for TestPyPI | |
| run: | | |
| set -e | |
| OLD_NAME="solt" | |
| NEW_NAME="solt-test" | |
| echo "Renaming built package from $OLD_NAME to $NEW_NAME..." | |
| echo "Dist contents before rename:" | |
| ls dist/ | |
| # Find sdist and wheel | |
| SDIST_FILE=$(ls dist/*.tar.gz | head -n 1) | |
| WHEEL_FILE=$(ls dist/*.whl | head -n 1) | |
| echo "Found sdist: $SDIST_FILE" | |
| echo "Found wheel: $WHEEL_FILE" | |
| # --- Handle sdist --- | |
| mkdir -p extracted-sdist | |
| tar -xzf "$SDIST_FILE" -C extracted-sdist | |
| sed -i "s/^Name: $OLD_NAME$/Name: $NEW_NAME/" extracted-sdist/*/PKG-INFO | |
| NEW_SDIST_FILE=$(echo "$SDIST_FILE" | sed "s/$OLD_NAME/$NEW_NAME/") | |
| BASE_DIR=$(basename "$SDIST_FILE" .tar.gz) | |
| tar -czf "$NEW_SDIST_FILE" -C extracted-sdist "$BASE_DIR" | |
| # --- Handle wheel --- | |
| mkdir -p extracted-wheel | |
| unzip "$WHEEL_FILE" -d extracted-wheel | |
| # Only patch the METADATA content, **not** the folder name | |
| sed -i "s/^Name: $OLD_NAME$/Name: $NEW_NAME/" extracted-wheel/*.dist-info/METADATA | |
| NEW_WHEEL_FILE=$(echo "$WHEEL_FILE" | sed "s/$OLD_NAME/$NEW_NAME/") | |
| # Carefully rebuild wheel preserving original folder names | |
| (cd extracted-wheel && zip -r "../$NEW_WHEEL_FILE" .) | |
| # --- Cleanup --- | |
| rm "$SDIST_FILE" | |
| rm "$WHEEL_FILE" | |
| rm -rf extracted-sdist extracted-wheel | |
| echo "Final dist contents after rename:" | |
| ls -lh dist/ | |
| - name: Validate packages with twine | |
| run: | | |
| python -m pip install --upgrade twine | |
| twine check dist/* | |
| - name: Publish to TestPyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| repository-url: https://test.pypi.org/legacy/ | |
| password: ${{ secrets.TEST_PYPI_API }} | |
| packages-dir: dist/ | |
| verbose: true | |