refactor(api): Refactor to monorepo #90
Workflow file for this run
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: Tag, Release, and Publish | |
| on: | |
| pull_request: | |
| types: [closed] | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| packages: write | |
| jobs: | |
| release-and-publish: | |
| # Only run this job on merged PRs with specific labels or manual dispatch | |
| if: > | |
| github.event_name == 'workflow_dispatch' || | |
| (github.event_name == 'pull_request' && github.event.pull_request.merged == true && | |
| (contains(github.event.pull_request.labels.*.name, 'beta') || | |
| contains(github.event.pull_request.labels.*.name, 'rc') || | |
| contains(github.event.pull_request.labels.*.name, 'patch') || | |
| contains(github.event.pull_request.labels.*.name, 'minor') || | |
| contains(github.event.pull_request.labels.*.name, 'major'))) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Set up Git | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| - name: Get current version from pyproject.toml/Cargo.toml | |
| id: get-version | |
| run: | | |
| # Try to find version in pyproject.toml first | |
| if [ -f "pyproject.toml" ]; then | |
| VERSION=$(cat pyproject.toml | grep '^version = ".*"' | cut -d'"' -f2) | |
| # Then try Cargo.toml | |
| elif [ -f "ptolemy-py/Cargo.toml" ]; then | |
| VERSION=$(cat ptolemy-py/Cargo.toml | grep '^version = ".*"' | cut -d'"' -f2 | head -1 | sed 's/+.*//') | |
| else | |
| echo "Could not find version in pyproject.toml or Cargo.toml" | |
| exit 1 | |
| fi | |
| echo "VERSION=${VERSION}" >> $GITHUB_ENV | |
| echo "Current version: ${VERSION}" | |
| - name: Determine release type | |
| id: determine-release-type | |
| # Only run this for PR merge events | |
| if: ${{ github.event_name == 'pull_request' }} | |
| run: | | |
| # Determine release type based on PR labels | |
| if [[ "${{ contains(github.event.pull_request.labels.*.name, 'beta') }}" == "true" ]]; then | |
| echo "RELEASE_TYPE=beta" >> $GITHUB_ENV | |
| echo "PRERELEASE=true" >> $GITHUB_ENV | |
| elif [[ "${{ contains(github.event.pull_request.labels.*.name, 'rc') }}" == "true" ]]; then | |
| echo "RELEASE_TYPE=release candidate" >> $GITHUB_ENV | |
| echo "PRERELEASE=true" >> $GITHUB_ENV | |
| else | |
| echo "RELEASE_TYPE=release" >> $GITHUB_ENV | |
| echo "PRERELEASE=false" >> $GITHUB_ENV | |
| fi | |
| # Determine version type based on PR labels | |
| if [[ "${{ contains(github.event.pull_request.labels.*.name, 'major') }}" == "true" ]]; then | |
| echo "VERSION_TYPE=major" >> $GITHUB_ENV | |
| elif [[ "${{ contains(github.event.pull_request.labels.*.name, 'minor') }}" == "true" ]]; then | |
| echo "VERSION_TYPE=minor" >> $GITHUB_ENV | |
| elif [[ "${{ contains(github.event.pull_request.labels.*.name, 'patch') }}" == "true" ]]; then | |
| echo "VERSION_TYPE=patch" >> $GITHUB_ENV | |
| else | |
| echo "VERSION_TYPE=patch" >> $GITHUB_ENV | |
| fi | |
| - name: Create tag | |
| # Only create tag if this is a PR close, not if we're manually triggered | |
| if: ${{ github.event_name == 'pull_request' }} | |
| run: | | |
| # Check if tag already exists | |
| if git rev-parse "v${VERSION}" >/dev/null 2>&1; then | |
| echo "Tag v${VERSION} already exists, skipping tag creation" | |
| else | |
| git tag -a "v${VERSION}" -m "Version ${VERSION}" | |
| git push origin "v${VERSION}" | |
| fi | |
| # Build Docker image | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| push: true | |
| tags: ghcr.io/ptolemylovesyou/ptolemy:latest,ghcr.io/ptolemylovesyou/ptolemy:${{ env.VERSION }} | |
| file: ptolemy/Dockerfile | |
| # Build wheels for different platforms | |
| build-linux: | |
| needs: release-and-publish | |
| runs-on: ${{ matrix.platform.runner }} | |
| strategy: | |
| matrix: | |
| platform: | |
| - runner: ubuntu-22.04 | |
| target: x86_64 | |
| - runner: ubuntu-22.04 | |
| target: aarch64 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: 3.12 | |
| - name: Build wheels | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| target: ${{ matrix.platform.target }} | |
| args: --release --out dist --manifest-path ptolemy-py/Cargo.toml --features vendored | |
| sccache: false | |
| manylinux: 2_28 | |
| container: ghcr.io/rust-cross/manylinux_2_28-cross:${{ matrix.platform.target }} | |
| before-script-linux: sudo apt-get update && sudo apt-get install -y protobuf-compiler | |
| - name: Build free-threaded wheels | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| target: ${{ matrix.platform.target }} | |
| args: --release --out dist --manifest-path ptolemy-py/Cargo.toml -i python3.13t --features vendored | |
| sccache: false | |
| manylinux: 2_28 | |
| container: ghcr.io/rust-cross/manylinux_2_28-cross:${{ matrix.platform.target }} | |
| before-script-linux: sudo apt-get update && sudo apt-get install -y protobuf-compiler | |
| - name: Upload wheels | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheels-linux-${{ matrix.platform.target }} | |
| path: dist | |
| build-musllinux: | |
| needs: release-and-publish | |
| runs-on: ${{ matrix.platform.runner }} | |
| strategy: | |
| matrix: | |
| platform: | |
| - runner: ubuntu-22.04 | |
| target: x86_64 | |
| - runner: ubuntu-22.04 | |
| target: aarch64 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: 3.12 | |
| - name: Build wheels | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| target: ${{ matrix.platform.target }} | |
| args: --release --out dist --manifest-path ptolemy-py/Cargo.toml --features vendored | |
| sccache: false | |
| manylinux: musllinux_1_2 | |
| before-script-linux: sudo apt-get update && sudo apt-get install -y protobuf-compiler | |
| - name: Build free-threaded wheels | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| target: ${{ matrix.platform.target }} | |
| args: --release --out dist --manifest-path ptolemy-py/Cargo.toml -i python3.13t --features vendored | |
| sccache: false | |
| manylinux: musllinux_1_2 | |
| before-script-linux: sudo apt-get update && sudo apt-get install -y protobuf-compiler | |
| - name: Upload wheels | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheels-musllinux-${{ matrix.platform.target }} | |
| path: dist | |
| build-macos: | |
| needs: release-and-publish | |
| runs-on: ${{ matrix.platform.runner }} | |
| strategy: | |
| matrix: | |
| platform: | |
| - runner: macos-13 | |
| target: x86_64 | |
| - runner: macos-14 | |
| target: aarch64 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: 3.12 | |
| - name: Install macOS dependencies | |
| run: | | |
| brew install openssl@3 protobuf pkg-config | |
| echo "OPENSSL_DIR=$(brew --prefix openssl@3)" >> $GITHUB_ENV | |
| echo "PKG_CONFIG_PATH=$(brew --prefix openssl@3)/lib/pkgconfig" >> $GITHUB_ENV | |
| - name: Build wheels | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| target: ${{ matrix.platform.target }} | |
| args: --release --out dist --manifest-path ptolemy-py/Cargo.toml | |
| sccache: false | |
| - name: Build free-threaded wheels | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| target: ${{ matrix.platform.target }} | |
| args: --release --out dist --manifest-path ptolemy-py/Cargo.toml -i python3.13t | |
| sccache: false | |
| - name: Upload wheels | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheels-macos-${{ matrix.platform.target }} | |
| path: dist | |
| build-sdist: | |
| needs: release-and-publish | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Build sdist | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| command: sdist | |
| args: --out dist --manifest-path ptolemy-py/Cargo.toml | |
| - name: Upload sdist | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: wheels-sdist | |
| path: dist | |
| publish: | |
| name: Publish to PyPI and GitHub Release | |
| runs-on: ubuntu-latest | |
| needs: [build-linux, build-musllinux, build-macos, build-sdist] | |
| permissions: | |
| # Use to sign the release artifacts | |
| id-token: write | |
| # Used to upload release artifacts | |
| contents: write | |
| # Used to generate artifact attestation | |
| attestations: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: wheels-* | |
| path: artifacts | |
| - name: Generate artifact attestation | |
| uses: actions/attest-build-provenance@v1 | |
| with: | |
| subject-path: 'artifacts/wheels-*/*' | |
| # Determine tag name for release | |
| - name: Get version for release | |
| id: get-version | |
| run: | | |
| # Try to find version in pyproject.toml first | |
| if [ -f "pyproject.toml" ]; then | |
| VERSION=$(cat pyproject.toml | grep '^version = ".*"' | cut -d'"' -f2) | |
| # Then try Cargo.toml | |
| elif [ -f "ptolemy-py/Cargo.toml" ]; then | |
| VERSION=$(cat ptolemy-py/Cargo.toml | grep '^version = ".*"' | cut -d'"' -f2 | head -1 | sed 's/+.*//') | |
| else | |
| echo "Could not find version in pyproject.toml or Cargo.toml" | |
| exit 1 | |
| fi | |
| echo "VERSION=${VERSION}" >> $GITHUB_ENV | |
| # Determine if this is a prerelease based on version | |
| if [[ "$VERSION" == *"beta"* || "$VERSION" == *"rc"* ]]; then | |
| echo "PRERELEASE=true" >> $GITHUB_ENV | |
| else | |
| echo "PRERELEASE=false" >> $GITHUB_ENV | |
| fi | |
| # Create GitHub Release with artifacts | |
| - name: Create GitHub Release with artifacts | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: artifacts/**/* | |
| tag_name: v${{ env.VERSION }} | |
| name: Version ${{ env.VERSION }} | |
| body: | | |
| ✨ This release was automatically generated ✨ | |
| Ptolemy loves you! <3 | |
|  | |
| generate_release_notes: true | |
| # Determine if this is a prerelease | |
| prerelease: ${{ env.PRERELEASE }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Publish to PyPI | |
| uses: PyO3/maturin-action@v1 | |
| env: | |
| MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} | |
| with: | |
| command: upload | |
| args: --non-interactive --skip-existing artifacts/wheels-*/* |