|
| 1 | +--- |
| 2 | +name: Test Release to TestPyPI |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - release-dev |
| 8 | + paths: |
| 9 | + - "setup.py" |
| 10 | + - ".github/workflows/test-release.yml" |
| 11 | + |
| 12 | +jobs: |
| 13 | + test-release: |
| 14 | + name: Build and Publish to TestPyPI |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout source code |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Set up Python |
| 22 | + uses: actions/setup-python@v5 |
| 23 | + with: |
| 24 | + python-version: '3.11' |
| 25 | + |
| 26 | + - name: Read version from setup.py |
| 27 | + id: getversion |
| 28 | + run: | |
| 29 | + echo "version=$(python ./setup.py --version)" >> $GITHUB_OUTPUT |
| 30 | + echo "Version detected: $(python ./setup.py --version)" |
| 31 | +
|
| 32 | + # Fetch tags to check if version tag already exists |
| 33 | + - name: Fetch tags |
| 34 | + run: git fetch --tags origin |
| 35 | + |
| 36 | + - name: Check if tag already exists |
| 37 | + id: tagcheck |
| 38 | + run: | |
| 39 | + if git rev-parse "v${{ steps.getversion.outputs.version }}" >/dev/null 2>&1; then |
| 40 | + echo "Tag v${{ steps.getversion.outputs.version }} already exists" |
| 41 | + echo "should_release=false" >> $GITHUB_OUTPUT |
| 42 | + else |
| 43 | + echo "Tag v${{ steps.getversion.outputs.version }} does not exist - will proceed with release" |
| 44 | + echo "should_release=true" >> $GITHUB_OUTPUT |
| 45 | + fi |
| 46 | +
|
| 47 | + - name: Install build dependencies |
| 48 | + if: steps.tagcheck.outputs.should_release == 'true' |
| 49 | + run: | |
| 50 | + python -m pip install --upgrade pip |
| 51 | + pip install build twine |
| 52 | +
|
| 53 | + - name: Install package dependencies |
| 54 | + if: steps.tagcheck.outputs.should_release == 'true' |
| 55 | + run: | |
| 56 | + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi |
| 57 | +
|
| 58 | + - name: Build package |
| 59 | + if: steps.tagcheck.outputs.should_release == 'true' |
| 60 | + run: python -m build |
| 61 | + |
| 62 | + - name: Check package with twine |
| 63 | + if: steps.tagcheck.outputs.should_release == 'true' |
| 64 | + run: twine check dist/* |
| 65 | + |
| 66 | + - name: Publish to TestPyPI |
| 67 | + if: steps.tagcheck.outputs.should_release == 'true' |
| 68 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 69 | + with: |
| 70 | + repository-url: https://test.pypi.org/legacy/ |
| 71 | + password: ${{ secrets.TEST_PYPI_API_TOKEN }} |
| 72 | + skip-existing: true |
| 73 | + |
| 74 | + - name: Get wheel filename |
| 75 | + if: steps.tagcheck.outputs.should_release == 'true' |
| 76 | + id: getwheelfile |
| 77 | + run: | |
| 78 | + echo "wheelfile=$(find dist -type f -name '*.whl')" >> $GITHUB_OUTPUT |
| 79 | + echo "tarfile=$(find dist -type f -name '*.tar.gz')" >> $GITHUB_OUTPUT |
| 80 | +
|
| 81 | + - name: Create GitHub Release |
| 82 | + if: steps.tagcheck.outputs.should_release == 'true' |
| 83 | + uses: softprops/action-gh-release@v2 |
| 84 | + with: |
| 85 | + tag_name: v${{ steps.getversion.outputs.version }} |
| 86 | + name: Release v${{ steps.getversion.outputs.version }} (Test) |
| 87 | + draft: false |
| 88 | + prerelease: true |
| 89 | + generate_release_notes: true |
| 90 | + files: | |
| 91 | + ${{ steps.getwheelfile.outputs.wheelfile }} |
| 92 | + ${{ steps.getwheelfile.outputs.tarfile }} |
| 93 | + env: |
| 94 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments