|
| 1 | +# Copyright (c) 2025 Vantage Compute Corporation. |
| 2 | +name: Build and Release |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + tags: |
| 7 | + - "[0-9]+.[0-9]+.[0-9]+" |
| 8 | + - "[0-9]+.[0-9]+.[0-9]+-alpha.[0-9]+" |
| 9 | + - "[0-9]+.[0-9]+.[0-9]+-beta.[0-9]+" |
| 10 | + - "[0-9]+.[0-9]+.[0-9]+a[0-9]+" |
| 11 | + - "[0-9]+.[0-9]+.[0-9]+b[0-9]+" |
| 12 | + - "[0-9]+.[0-9]+.[0-9]+rc[0-9]+" |
| 13 | + workflow_dispatch: # Allow manual triggering |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: write # Required for creating releases |
| 17 | + id-token: write # Required for PyPI trusted publishing |
| 18 | + |
| 19 | +jobs: |
| 20 | + build: |
| 21 | + name: Build Distribution |
| 22 | + runs-on: ubuntu-latest |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Checkout code |
| 26 | + uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + fetch-depth: 0 # Fetch full history for proper version detection |
| 29 | + |
| 30 | + - name: Set up Python |
| 31 | + uses: actions/setup-python@v5 |
| 32 | + with: |
| 33 | + python-version: '3.12' |
| 34 | + |
| 35 | + - name: Install system dependencies |
| 36 | + run: | |
| 37 | + sudo apt-get update |
| 38 | + sudo apt-get install -y build-essential |
| 39 | + sudo snap install astral-uv --classic |
| 40 | +
|
| 41 | + |
| 42 | + - name: Install git-cliff |
| 43 | + run: | |
| 44 | + curl -L https://github.com/orhun/git-cliff/releases/download/v2.10.0/git-cliff-2.10.0-x86_64-unknown-linux-gnu.tar.gz | tar xz |
| 45 | + sudo mv git-cliff-*/git-cliff /usr/local/bin/ |
| 46 | + git-cliff --version |
| 47 | + |
| 48 | + - name: Build Python package |
| 49 | + run: | |
| 50 | + uv build |
| 51 | + |
| 52 | + - name: Check build artifacts |
| 53 | + run: | |
| 54 | + ls -la dist/ |
| 55 | + # Basic validation - ensure files exist |
| 56 | + test -n "$(find dist -name '*.whl')" || (echo "No wheel files found" && exit 1) |
| 57 | + test -n "$(find dist -name '*.tar.gz')" || (echo "No source distribution found" && exit 1) |
| 58 | +
|
| 59 | + - name: Upload build artifacts |
| 60 | + uses: actions/upload-artifact@v4 |
| 61 | + with: |
| 62 | + name: distribution-files |
| 63 | + path: dist/ |
| 64 | + retention-days: 7 |
| 65 | + |
| 66 | + test-install: |
| 67 | + name: Test Installation |
| 68 | + needs: build |
| 69 | + runs-on: ubuntu-latest |
| 70 | + strategy: |
| 71 | + matrix: |
| 72 | + python-version: ['3.12', '3.13'] |
| 73 | + |
| 74 | + steps: |
| 75 | + - name: Set up Python ${{ matrix.python-version }} |
| 76 | + uses: actions/setup-python@v5 |
| 77 | + with: |
| 78 | + python-version: ${{ matrix.python-version }} |
| 79 | + |
| 80 | + - name: Download build artifacts |
| 81 | + uses: actions/download-artifact@v4 |
| 82 | + with: |
| 83 | + name: distribution-files |
| 84 | + path: dist/ |
| 85 | + |
| 86 | + - name: Test wheel installation |
| 87 | + run: | |
| 88 | + sudo snap install astral-uv --classic |
| 89 | + uv venv |
| 90 | + uv pip install dist/*.whl |
| 91 | + uv run python3 -c "import helmpy; print('Package imported successfully')" |
| 92 | +
|
| 93 | + publish-pypi: |
| 94 | + name: Publish to PyPI |
| 95 | + needs: [build, test-install] |
| 96 | + runs-on: ubuntu-latest |
| 97 | + if: startsWith(github.ref, 'refs/tags/') |
| 98 | + environment: |
| 99 | + name: pypi |
| 100 | + url: https://pypi.org/p/helmpy |
| 101 | + |
| 102 | + steps: |
| 103 | + - name: Download build artifacts |
| 104 | + uses: actions/download-artifact@v4 |
| 105 | + with: |
| 106 | + name: distribution-files |
| 107 | + path: dist/ |
| 108 | + |
| 109 | + - name: Publish to PyPI |
| 110 | + run: | |
| 111 | + sudo snap install astral-uv --classic |
| 112 | + uv publish |
| 113 | +
|
| 114 | + create-release: |
| 115 | + name: Create GitHub Release |
| 116 | + needs: [build, test-install] |
| 117 | + runs-on: ubuntu-latest |
| 118 | + if: startsWith(github.ref, 'refs/tags/') |
| 119 | + |
| 120 | + steps: |
| 121 | + - name: Checkout code |
| 122 | + uses: actions/checkout@v4 |
| 123 | + with: |
| 124 | + fetch-depth: 0 |
| 125 | + |
| 126 | + - name: Download build artifacts |
| 127 | + uses: actions/download-artifact@v4 |
| 128 | + with: |
| 129 | + name: distribution-files |
| 130 | + path: dist/ |
| 131 | + |
| 132 | + - name: Extract version from tag |
| 133 | + id: get_version |
| 134 | + run: | |
| 135 | + VERSION=${GITHUB_REF#refs/tags/} |
| 136 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 137 | + echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 138 | + |
| 139 | + - name: Generate release notes |
| 140 | + id: release_notes |
| 141 | + run: | |
| 142 | + # Extract release notes from CHANGELOG.md if it exists |
| 143 | + if [ -f "CHANGELOG.md" ]; then |
| 144 | + # Try to extract notes for this version using git-cliff for consistency |
| 145 | + VERSION="${{ steps.get_version.outputs.version }}" |
| 146 | + |
| 147 | + # Use git-cliff to generate notes for this specific version |
| 148 | + git-cliff --latest --strip header --strip footer > release_notes.txt || true |
| 149 | + |
| 150 | + # If that fails, fall back to grep method |
| 151 | + if [ ! -s release_notes.txt ]; then |
| 152 | + grep -A 1000 "^## .*${VERSION}" CHANGELOG.md | grep -B 1000 -m 2 "^## " | head -n -1 | tail -n +2 > release_notes.txt || true |
| 153 | + fi |
| 154 | + |
| 155 | + # If no specific version notes found, create generic notes |
| 156 | + if [ ! -s release_notes.txt ]; then |
| 157 | + echo "Release ${{ steps.get_version.outputs.tag }}" > release_notes.txt |
| 158 | + echo "" >> release_notes.txt |
| 159 | + echo "### Changes" >> release_notes.txt |
| 160 | + echo "- See CHANGELOG.md for detailed changes" >> release_notes.txt |
| 161 | + fi |
| 162 | + else |
| 163 | + echo "Release ${{ steps.get_version.outputs.tag }}" > release_notes.txt |
| 164 | + echo "" >> release_notes.txt |
| 165 | + echo "### Files" >> release_notes.txt |
| 166 | + echo "- Source distribution (tar.gz)" >> release_notes.txt |
| 167 | + echo "- Wheel distribution (.whl)" >> release_notes.txt |
| 168 | + fi |
| 169 | + |
| 170 | + echo "Release notes:" |
| 171 | + cat release_notes.txt |
| 172 | + |
| 173 | + - name: Create Release |
| 174 | + uses: softprops/action-gh-release@v1 |
| 175 | + with: |
| 176 | + name: Release ${{ steps.get_version.outputs.tag }} |
| 177 | + body_path: release_notes.txt |
| 178 | + files: | |
| 179 | + dist/*.tar.gz |
| 180 | + dist/*.whl |
| 181 | + draft: false |
| 182 | + prerelease: ${{ contains(steps.get_version.outputs.version, 'rc') || contains(steps.get_version.outputs.version, 'beta') || contains(steps.get_version.outputs.version, 'alpha') }} |
| 183 | + generate_release_notes: true |
| 184 | + env: |
| 185 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 186 | + |
| 187 | + notify-success: |
| 188 | + name: Notify Success |
| 189 | + needs: [publish-pypi, create-release] |
| 190 | + runs-on: ubuntu-latest |
| 191 | + if: success() && startsWith(github.ref, 'refs/tags/') |
| 192 | + |
| 193 | + steps: |
| 194 | + - name: Extract version from tag |
| 195 | + id: get_version |
| 196 | + run: | |
| 197 | + VERSION=${GITHUB_REF#refs/tags/} |
| 198 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 199 | + echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 200 | + |
| 201 | + - name: Success notification |
| 202 | + run: | |
| 203 | + echo "🎉 Successfully released helmpy ${{ steps.get_version.outputs.tag }}" |
| 204 | + echo "📦 Published to PyPI: https://pypi.org/project/helmpy/${{ steps.get_version.outputs.version }}/" |
| 205 | + echo "🚀 GitHub Release: ${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ steps.get_version.outputs.tag }}" |
0 commit comments