|
1 | 1 | name: Publish to PyPI |
2 | 2 |
|
3 | 3 | on: |
4 | | - release: |
5 | | - types: [published] |
6 | | - workflow_dispatch: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 10 | + cancel-in-progress: false |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
7 | 14 |
|
8 | 15 | jobs: |
| 16 | + test: |
| 17 | + name: Run Tests Before Publishing |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Checkout code |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Install uv |
| 24 | + uses: astral-sh/setup-uv@v3 |
| 25 | + |
| 26 | + - name: Set up Python |
| 27 | + uses: actions/setup-python@v5 |
| 28 | + with: |
| 29 | + python-version: '3.12' |
| 30 | + |
| 31 | + - name: Install dependencies |
| 32 | + run: uv pip install --system -e ".[dev]" |
| 33 | + |
| 34 | + - name: Run ruff |
| 35 | + run: ruff check . |
| 36 | + |
| 37 | + - name: Run mypy |
| 38 | + run: mypy contractions/ tests/ |
| 39 | + |
| 40 | + - name: Run tests with coverage |
| 41 | + run: pytest tests/ --cov=contractions --cov-report=term |
| 42 | + |
9 | 43 | deploy: |
| 44 | + name: Build and Publish to PyPI |
10 | 45 | runs-on: ubuntu-latest |
| 46 | + needs: test |
11 | 47 | permissions: |
| 48 | + contents: read |
12 | 49 | id-token: write |
13 | 50 |
|
14 | 51 | steps: |
15 | 52 | - name: Checkout code |
16 | 53 | uses: actions/checkout@v4 |
17 | | - with: |
18 | | - fetch-depth: 0 |
| 54 | + |
| 55 | + - name: Extract version from tag |
| 56 | + id: get_version |
| 57 | + run: | |
| 58 | + VERSION=${GITHUB_REF#refs/tags/v} |
| 59 | + echo "version=${VERSION}" >> $GITHUB_OUTPUT |
| 60 | + echo "Publishing version: ${VERSION}" |
| 61 | + |
| 62 | + - name: Update version in _version.py |
| 63 | + run: | |
| 64 | + echo "__version__ = \"${{ steps.get_version.outputs.version }}\"" > contractions/_version.py |
| 65 | + cat contractions/_version.py |
| 66 | + |
| 67 | + - name: Install uv |
| 68 | + uses: astral-sh/setup-uv@v3 |
19 | 69 |
|
20 | 70 | - name: Set up Python |
21 | 71 | uses: actions/setup-python@v5 |
22 | 72 | with: |
23 | 73 | python-version: '3.12' |
24 | 74 |
|
25 | 75 | - name: Install build dependencies |
26 | | - run: | |
27 | | - python -m pip install --upgrade pip |
28 | | - pip install build twine |
29 | | - |
30 | | - - name: Update version from git commits |
31 | | - run: | |
32 | | - COMMIT_COUNT=$(git rev-list --all --count) |
33 | | - MAJOR=$(grep 'MAJOR_VERSION = ' setup.py | sed 's/.*"\([0-9]*\)".*/\1/') |
34 | | - MINOR=$(grep 'MINOR_VERSION = ' setup.py | sed 's/.*"\([0-9]*\)".*/\1/') |
35 | | - VERSION="${MAJOR}.${MINOR}.${COMMIT_COUNT}" |
36 | | - |
37 | | - sed -i "s/MICRO_VERSION = \"[0-9]*\"/MICRO_VERSION = \"${COMMIT_COUNT}\"/" setup.py |
38 | | - sed -i "s/__version__ = \"[0-9.]*\"/__version__ = \"${VERSION}\"/" contractions/__init__.py |
39 | | - |
40 | | - echo "Building version: ${VERSION}" |
| 76 | + run: uv pip install --system build twine |
41 | 77 |
|
42 | 78 | - name: Build package |
43 | 79 | run: python -m build |
|
0 commit comments