maintenance and improvements #6
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: build | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.9' | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v4 | |
| - name: Install dependencies | |
| run: uv sync | |
| - name: Run pre-commit | |
| run: | | |
| uv run pre-commit run --all-files | |
| - name: Run tests | |
| run: | | |
| uv run python -m unittest discover -s tests -p "*.py" | |
| publish: | |
| needs: test | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' | |
| permissions: | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.9' | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v4 | |
| - name: Install dependencies | |
| run: uv sync | |
| - name: Update version for staging (non-main branches) | |
| if: github.ref != 'refs/heads/main' | |
| run: | | |
| TIMESTAMP=$(date +%Y%m%d%H%M%S) | |
| CURRENT_VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/') | |
| NEW_VERSION="${CURRENT_VERSION}.dev${TIMESTAMP}" | |
| sed -i "s/^version = .*/version = \"${NEW_VERSION}\"/" pyproject.toml | |
| echo "Publishing version ${NEW_VERSION} to Test PyPI" | |
| - name: Build package | |
| run: uv build | |
| - name: Publish to Test PyPI (staging) | |
| if: github.ref != 'refs/heads/main' | |
| run: | | |
| uv publish --publish-url https://test.pypi.org/legacy/ --trusted-publishing always | |
| - name: Publish to PyPI (production) | |
| if: github.ref == 'refs/heads/main' | |
| run: | | |
| uv publish --trusted-publishing always |