|
| 1 | +name: Auto-publish Development Versions |
| 2 | + |
| 3 | +# Trigger on pushes to develop or when PR is merged to develop |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - develop |
| 8 | + - "feature/**" |
| 9 | + pull_request: |
| 10 | + types: [closed] |
| 11 | + branches: |
| 12 | + - develop |
| 13 | + |
| 14 | +jobs: |
| 15 | + check-changes: |
| 16 | + name: Check if code changed |
| 17 | + runs-on: ubuntu-latest |
| 18 | + outputs: |
| 19 | + code-changed: ${{ steps.changes.outputs.code }} |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + fetch-depth: 2 |
| 24 | + |
| 25 | + - uses: dorny/paths-filter@v3 |
| 26 | + id: changes |
| 27 | + with: |
| 28 | + filters: | |
| 29 | + code: |
| 30 | + - 'src/**' |
| 31 | + - 'pyproject.toml' |
| 32 | + - 'tests/**' |
| 33 | +
|
| 34 | + publish-dev: |
| 35 | + name: Publish development version |
| 36 | + runs-on: ubuntu-latest |
| 37 | + needs: check-changes |
| 38 | + # Only run if code changed and on correct triggers |
| 39 | + if: | |
| 40 | + needs.check-changes.outputs.code-changed == 'true' && ( |
| 41 | + (github.event_name == 'push' && github.ref == 'refs/heads/develop') || |
| 42 | + (github.event_name == 'pull_request' && github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'develop') |
| 43 | + ) |
| 44 | + defaults: |
| 45 | + run: |
| 46 | + shell: bash |
| 47 | + permissions: |
| 48 | + contents: read |
| 49 | + |
| 50 | + steps: |
| 51 | + - name: Checkout repository |
| 52 | + uses: actions/checkout@v4 |
| 53 | + |
| 54 | + - name: Install uv |
| 55 | + uses: astral-sh/setup-uv@v4 |
| 56 | + with: |
| 57 | + version: "latest" |
| 58 | + |
| 59 | + - name: Set up Python |
| 60 | + uses: actions/setup-python@v5 |
| 61 | + with: |
| 62 | + python-version: "3.10" |
| 63 | + |
| 64 | + - name: Setup build environment |
| 65 | + run: | |
| 66 | + uv sync --group test --no-dev |
| 67 | + uv add --dev build twine |
| 68 | +
|
| 69 | + - name: Run tests before publishing |
| 70 | + run: | |
| 71 | + uv run coverage run -m pytest tests/ -x --tb=short |
| 72 | +
|
| 73 | + - name: Generate development version |
| 74 | + id: version |
| 75 | + run: | |
| 76 | + # Get base version |
| 77 | + BASE_VERSION=$(uv run python -c "import sys; sys.path.insert(0, 'src'); from laplaciannb import __version__; print(__version__)") |
| 78 | + echo "Base version: $BASE_VERSION" |
| 79 | +
|
| 80 | + # Generate dev version with short commit hash and timestamp |
| 81 | + SHORT_SHA=$(git rev-parse --short HEAD) |
| 82 | + TIMESTAMP=$(date +%Y%m%d%H%M) |
| 83 | + DEV_VERSION="${BASE_VERSION}.dev${TIMESTAMP}" |
| 84 | +
|
| 85 | + echo "Development version: $DEV_VERSION" |
| 86 | + echo "dev_version=$DEV_VERSION" >> $GITHUB_OUTPUT |
| 87 | +
|
| 88 | + # Update version in __init__.py |
| 89 | + sed -i "s/__version__ = \"$BASE_VERSION\"/__version__ = \"$DEV_VERSION\"/" src/laplaciannb/__init__.py |
| 90 | +
|
| 91 | + # Verify version was updated |
| 92 | + UPDATED_VERSION=$(uv run python -c "import sys; sys.path.insert(0, 'src'); from laplaciannb import __version__; print(__version__)") |
| 93 | + echo "Updated version: $UPDATED_VERSION" |
| 94 | +
|
| 95 | + - name: Build distribution |
| 96 | + run: | |
| 97 | + uv run python -m build |
| 98 | +
|
| 99 | + - name: Validate distribution |
| 100 | + run: | |
| 101 | + uv run twine check dist/* |
| 102 | +
|
| 103 | + # Test installation with uv |
| 104 | + uv run pip install dist/*.whl |
| 105 | + uv run python -c "import laplaciannb; print(f'Installed version: {laplaciannb.__version__}')" |
| 106 | +
|
| 107 | + - name: Publish to PyPI |
| 108 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 109 | + with: |
| 110 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 111 | + verbose: true |
| 112 | + print-hash: true |
| 113 | + |
| 114 | + - name: Create GitHub summary |
| 115 | + run: | |
| 116 | + echo "## 🚀 Development Version Published" >> $GITHUB_STEP_SUMMARY |
| 117 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 118 | + echo "**Version:** \`${{ steps.version.outputs.dev_version }}\`" >> $GITHUB_STEP_SUMMARY |
| 119 | + echo "**Commit:** \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY |
| 120 | + echo "**Branch:** \`${{ github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY |
| 121 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 122 | + echo "### Installation" >> $GITHUB_STEP_SUMMARY |
| 123 | + echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY |
| 124 | + echo "pip install laplaciannb==${{ steps.version.outputs.dev_version }}" >> $GITHUB_STEP_SUMMARY |
| 125 | + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |
| 126 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 127 | + echo "Or install latest development version:" >> $GITHUB_STEP_SUMMARY |
| 128 | + echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY |
| 129 | + echo "pip install --pre laplaciannb" >> $GITHUB_STEP_SUMMARY |
| 130 | + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |
| 131 | +
|
| 132 | + - name: Comment on PR (if applicable) |
| 133 | + if: github.event_name == 'pull_request' |
| 134 | + uses: actions/github-script@v7 |
| 135 | + with: |
| 136 | + script: | |
| 137 | + github.rest.issues.createComment({ |
| 138 | + issue_number: context.issue.number, |
| 139 | + owner: context.repo.owner, |
| 140 | + repo: context.repo.repo, |
| 141 | + body: `🚀 **Development version published!**\n\n**Version:** \`${{ steps.version.outputs.dev_version }}\`\n\nInstall with:\n\`\`\`bash\npip install laplaciannb==${{ steps.version.outputs.dev_version }}\n\`\`\`` |
| 142 | + }) |
0 commit comments