|
| 1 | +name: Publish to PyPI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*.*.*' # Trigger on version tags like v0.1.0, v1.0.0, etc. |
| 7 | + |
| 8 | +jobs: |
| 9 | + # Run full test suite before publishing |
| 10 | + test: |
| 11 | + name: Test Suite |
| 12 | + runs-on: ubuntu-latest |
| 13 | + strategy: |
| 14 | + matrix: |
| 15 | + python-version: ['3.10', '3.11', '3.12', '3.13'] |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout code |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Set up Python ${{ matrix.python-version }} |
| 22 | + uses: actions/setup-python@v5 |
| 23 | + with: |
| 24 | + python-version: ${{ matrix.python-version }} |
| 25 | + cache: 'pip' |
| 26 | + |
| 27 | + - name: Install dependencies |
| 28 | + run: | |
| 29 | + python -m pip install --upgrade pip |
| 30 | + pip install -e ".[dev]" |
| 31 | + |
| 32 | + - name: Run tests |
| 33 | + run: | |
| 34 | + pytest tests/ -v --tb=short |
| 35 | + |
| 36 | + build-and-publish: |
| 37 | + needs: test # Only publish if tests pass |
| 38 | + runs-on: ubuntu-latest |
| 39 | + |
| 40 | + permissions: |
| 41 | + contents: write # For creating release |
| 42 | + id-token: write # Required for trusted publishing |
| 43 | + |
| 44 | + steps: |
| 45 | + - name: Checkout code |
| 46 | + uses: actions/checkout@v4 |
| 47 | + with: |
| 48 | + fetch-depth: 0 # Full history for changelog |
| 49 | + |
| 50 | + - name: Set up Python |
| 51 | + uses: actions/setup-python@v5 |
| 52 | + with: |
| 53 | + python-version: '3.11' |
| 54 | + |
| 55 | + - name: Install build dependencies |
| 56 | + run: | |
| 57 | + python -m pip install --upgrade pip |
| 58 | + python -m pip install build twine |
| 59 | + |
| 60 | + - name: Extract version from tag |
| 61 | + id: get_version |
| 62 | + run: | |
| 63 | + VERSION=${GITHUB_REF#refs/tags/v} |
| 64 | + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT |
| 65 | + echo "Publishing version: $VERSION" |
| 66 | + |
| 67 | + - name: Build package |
| 68 | + run: python -m build |
| 69 | + |
| 70 | + - name: Check package |
| 71 | + run: python -m twine check dist/* |
| 72 | + |
| 73 | + - name: Publish to PyPI |
| 74 | + id: pypi-publish |
| 75 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 76 | + with: |
| 77 | + # Using trusted publishing - no password needed |
| 78 | + # Configure at https://pypi.org/manage/account/publishing/ |
| 79 | + skip-existing: true |
| 80 | + verbose: true |
| 81 | + |
| 82 | + - name: Create GitHub Release |
| 83 | + if: success() # Only create release if PyPI publish succeeded |
| 84 | + uses: softprops/action-gh-release@v2 |
| 85 | + with: |
| 86 | + files: dist/* |
| 87 | + generate_release_notes: true |
| 88 | + body: | |
| 89 | + # CapiscIO CLI ${{ steps.get_version.outputs.VERSION }} |
| 90 | + |
| 91 | + ## Installation |
| 92 | + |
| 93 | + ```bash |
| 94 | + pip install capiscio==${{ steps.get_version.outputs.VERSION }} |
| 95 | + ``` |
| 96 | + |
| 97 | + Or upgrade: |
| 98 | + |
| 99 | + ```bash |
| 100 | + pip install --upgrade capiscio |
| 101 | + ``` |
| 102 | + |
| 103 | + ## What's Changed |
| 104 | + |
| 105 | + See [CHANGELOG.md](https://github.com/capiscio/capiscio-python/blob/main/CHANGELOG.md) for detailed changes. |
| 106 | + |
| 107 | + ## Documentation |
| 108 | + |
| 109 | + - [CLI Documentation](https://docs.capisc.io/cli) |
| 110 | + |
| 111 | + --- |
| 112 | + |
| 113 | + **Full Changelog**: https://github.com/capiscio/capiscio-python/compare/${{ github.event.before }}...${{ github.ref_name }} |
| 114 | + env: |
| 115 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments