|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + workflow_run: |
| 8 | + workflows: ["Auto Merge"] |
| 9 | + types: [completed] |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + |
| 14 | +jobs: |
| 15 | + lint: |
| 16 | + name: Lint |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v6 |
| 20 | + - uses: astral-sh/setup-uv@v7 |
| 21 | + - uses: actions/setup-python@v6 |
| 22 | + with: |
| 23 | + python-version: "3.13" |
| 24 | + - name: Install dependencies |
| 25 | + run: uv sync --group dev |
| 26 | + - name: Lint |
| 27 | + run: uv run ruff check pirebok tests |
| 28 | + |
| 29 | + test: |
| 30 | + name: Test |
| 31 | + strategy: |
| 32 | + matrix: |
| 33 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 34 | + runs-on: ${{ matrix.os }} |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@v6 |
| 37 | + - uses: astral-sh/setup-uv@v7 |
| 38 | + - uses: actions/setup-python@v6 |
| 39 | + with: |
| 40 | + python-version: "3.13" |
| 41 | + - name: Install dependencies |
| 42 | + run: uv sync --group dev |
| 43 | + - name: Test |
| 44 | + run: uv run pytest --cov=pirebok --cov-branch --cov-report=xml --cov-report=term-missing tests |
| 45 | + - uses: codecov/codecov-action@v5 |
| 46 | + with: |
| 47 | + files: coverage.xml |
| 48 | + |
| 49 | + release: |
| 50 | + name: Release |
| 51 | + needs: [lint, test] |
| 52 | + if: >- |
| 53 | + (github.ref == 'refs/heads/main' && github.event_name == 'push') || |
| 54 | + (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') |
| 55 | + runs-on: ubuntu-latest |
| 56 | + permissions: |
| 57 | + contents: write |
| 58 | + pages: write |
| 59 | + steps: |
| 60 | + - uses: actions/checkout@v6 |
| 61 | + with: |
| 62 | + fetch-depth: 0 |
| 63 | + - uses: astral-sh/setup-uv@v7 |
| 64 | + - uses: actions/setup-python@v6 |
| 65 | + with: |
| 66 | + python-version: "3.13" |
| 67 | + |
| 68 | + - name: Install dependencies |
| 69 | + run: uv sync --group dev |
| 70 | + |
| 71 | + - name: Determine next version |
| 72 | + id: next_version |
| 73 | + run: | |
| 74 | + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") |
| 75 | +
|
| 76 | + if [ -z "$LATEST_TAG" ]; then |
| 77 | + NEW_VERSION="0.0.1" |
| 78 | + else |
| 79 | + VERSION=${LATEST_TAG#v} |
| 80 | + IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION" |
| 81 | +
|
| 82 | + COMMITS=$(git log "${LATEST_TAG}..HEAD" --pretty=format:"%s") |
| 83 | +
|
| 84 | + BUMP="patch" |
| 85 | + if echo "$COMMITS" | grep -qiE "^feat(\(.+\))?!:|BREAKING CHANGE"; then |
| 86 | + BUMP="major" |
| 87 | + elif echo "$COMMITS" | grep -qiE "^feat(\(.+\))?:"; then |
| 88 | + BUMP="minor" |
| 89 | + fi |
| 90 | +
|
| 91 | + case $BUMP in |
| 92 | + major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;; |
| 93 | + minor) MINOR=$((MINOR + 1)); PATCH=0 ;; |
| 94 | + patch) PATCH=$((PATCH + 1)) ;; |
| 95 | + esac |
| 96 | +
|
| 97 | + NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}" |
| 98 | + fi |
| 99 | +
|
| 100 | + echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT |
| 101 | + echo "tag=v$NEW_VERSION" >> $GITHUB_OUTPUT |
| 102 | + echo "Releasing v$NEW_VERSION" |
| 103 | +
|
| 104 | + - name: Create tag |
| 105 | + run: | |
| 106 | + git tag ${{ steps.next_version.outputs.tag }} |
| 107 | + git push origin ${{ steps.next_version.outputs.tag }} |
| 108 | +
|
| 109 | + - name: Build documentation |
| 110 | + run: uv run mkdocs build |
| 111 | + |
| 112 | + - name: Publish documentation |
| 113 | + uses: peaceiris/actions-gh-pages@v4 |
| 114 | + with: |
| 115 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 116 | + publish_dir: ./site |
| 117 | + |
| 118 | + - name: Build wheels and source tarball |
| 119 | + run: uv build |
| 120 | + |
| 121 | + - name: Create GitHub release |
| 122 | + uses: softprops/action-gh-release@v2 |
| 123 | + with: |
| 124 | + tag_name: ${{ steps.next_version.outputs.tag }} |
| 125 | + generate_release_notes: true |
| 126 | + files: dist/*.whl |
| 127 | + draft: false |
| 128 | + prerelease: false |
| 129 | + |
| 130 | + - name: Publish to PyPI |
| 131 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 132 | + with: |
| 133 | + user: __token__ |
| 134 | + password: ${{ secrets.PYPI_TOKEN }} |
| 135 | + skip-existing: true |
0 commit comments