aboutsummaryrefslogtreecommitdiffstats
path: root/.github/workflows/build-test-publish.yml
blob: b70f1f1d8aa554fc4a9961a4f17907a10453ef6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
name: Test, Build, and Publish

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - "**"

jobs:
  test-build-publish:
    runs-on: ubuntu-latest
    name: Test, Build and Publish

    steps:
      - name: Checkout repo
        uses: actions/checkout@v3

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: "3.11"

      - name: Install uv
        run: pip install uv

      - name: Run tests
        run: python test.py

      - name: Build package
        run: uv build

      - name: Publish to PyPI
        if: github.ref == 'refs/heads/main'
        run: |
          set +e

          # Run uv publish and capture output
          OUTPUT=$(uv publish 2>&1)
          STATUS=$?

          set -eo pipefail

          echo "$OUTPUT"

          if [ $STATUS -eq 0 ]; then
            echo "✅ Publish succeeded."
            exit 0
          elif echo "$OUTPUT" | grep -q "400 File already exists"; then
            echo "⚠️ Package version already exists on PyPI. Skipping publish."
            exit 0
          else
            echo "❌ Publish failed unexpectedly."
            exit $STATUS
          fi
        env:
          UV_PUBLISH_TOKEN: ${{ secrets.UV_PYPI_TOKEN }}