feat: implement automated version bumping and PyPI publishing #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: Test PR | |
| on: | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pull-requests: write # Allow commenting on PRs | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Needed for semantic-release | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| - name: Cache dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/pip | |
| key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml', '**/Pipfile.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip- | |
| ${{ runner.os }}- | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -e .[dev] | |
| pip install build twine python-semantic-release toml | |
| - name: Run tests | |
| run: pytest idtap/tests/ -m "not integration" | |
| - name: Validate version consistency | |
| run: | | |
| echo "Checking version consistency across files..." | |
| INIT_VERSION=$(python -c "import idtap; print(idtap.__version__)") | |
| TOML_VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])") | |
| echo "__init__.py version: $INIT_VERSION" | |
| echo "pyproject.toml version: $TOML_VERSION" | |
| if [ "$INIT_VERSION" != "$TOML_VERSION" ]; then | |
| echo "❌ Version mismatch detected!" | |
| echo "__init__.py: $INIT_VERSION" | |
| echo "pyproject.toml: $TOML_VERSION" | |
| exit 1 | |
| fi | |
| echo "✅ Versions are consistent" | |
| - name: Build package | |
| run: python -m build | |
| - name: Test semantic-release dry run | |
| run: | | |
| semantic-release version --print --no-commit --no-tag --no-push --no-vcs-release || echo "No version bump needed" | |
| - name: Test upload to TestPyPI | |
| if: github.event.pull_request.head.repo.full_name == github.repository | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| repository-url: https://test.pypi.org/legacy/ | |
| skip-existing: true | |
| password: ${{ secrets.TESTPYPI_API_TOKEN }} | |
| - name: Comment PR with TestPyPI link | |
| if: github.event.pull_request.head.repo.full_name == github.repository | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const prNumber = context.issue.number; | |
| const testPypiUrl = `https://test.pypi.org/project/idtap/`; | |
| github.rest.issues.createComment({ | |
| issue_number: prNumber, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: `📦 **Test Package Built Successfully!** | |
| This PR has been automatically built and uploaded to TestPyPI for testing. | |
| 🔗 **TestPyPI Link**: ${testPypiUrl} | |
| To test this version: | |
| \`\`\`bash | |
| pip install --index-url https://test.pypi.org/simple/ idtap | |
| \`\`\` | |
| ✅ All tests passed and package builds successfully.` | |
| }); |