|
| 1 | +name: release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "**" |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: release-${{ github.ref }} |
| 10 | + cancel-in-progress: false |
| 11 | + |
| 12 | +jobs: |
| 13 | + validate_tag: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + outputs: |
| 16 | + version: ${{ steps.version.outputs.version }} |
| 17 | + tag: ${{ steps.version.outputs.tag }} |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + - uses: actions/setup-python@v5 |
| 21 | + with: |
| 22 | + python-version: "3.13" |
| 23 | + - id: version |
| 24 | + name: Validate tag against package version |
| 25 | + run: | |
| 26 | + version=$(python - <<'PY' |
| 27 | + import pathlib |
| 28 | + import tomllib |
| 29 | +
|
| 30 | + project = tomllib.loads(pathlib.Path("pyproject.toml").read_text()) |
| 31 | + print(project["project"]["version"]) |
| 32 | + PY |
| 33 | + ) |
| 34 | + tag="${GITHUB_REF_NAME}" |
| 35 | + if [ "${tag}" != "${version}" ] && [ "${tag}" != "v${version}" ]; then |
| 36 | + echo "Tag ${tag} does not match package version ${version}." >&2 |
| 37 | + exit 1 |
| 38 | + fi |
| 39 | + echo "version=${version}" >> "${GITHUB_OUTPUT}" |
| 40 | + echo "tag=${tag}" >> "${GITHUB_OUTPUT}" |
| 41 | +
|
| 42 | + test: |
| 43 | + needs: validate_tag |
| 44 | + runs-on: ubuntu-latest |
| 45 | + strategy: |
| 46 | + fail-fast: false |
| 47 | + matrix: |
| 48 | + python-version: ["3.10", "3.11", "3.12", "3.13"] |
| 49 | + steps: |
| 50 | + - uses: actions/checkout@v4 |
| 51 | + - uses: actions/setup-python@v5 |
| 52 | + with: |
| 53 | + python-version: ${{ matrix.python-version }} |
| 54 | + - name: Install dependencies |
| 55 | + run: | |
| 56 | + python -m pip install --upgrade pip |
| 57 | + python -m pip install -e . |
| 58 | + python -m pip install pytest pytest-cov pandas pyarrow folium matplotlib |
| 59 | + - name: Run tests |
| 60 | + run: pytest --cov=src/carp --cov-branch --cov-fail-under=100 |
| 61 | + |
| 62 | + quality: |
| 63 | + needs: validate_tag |
| 64 | + runs-on: ubuntu-latest |
| 65 | + steps: |
| 66 | + - uses: actions/checkout@v4 |
| 67 | + - uses: actions/setup-python@v5 |
| 68 | + with: |
| 69 | + python-version: "3.13" |
| 70 | + - name: Install dependencies |
| 71 | + run: | |
| 72 | + python -m pip install --upgrade pip |
| 73 | + python -m pip install -e . |
| 74 | + python -m pip install pytest pytest-cov mypy ruff sphinx sphinx-rtd-theme pandas pyarrow folium matplotlib |
| 75 | + - name: Lint |
| 76 | + run: ruff check src examples tests docs |
| 77 | + - name: Type check |
| 78 | + run: mypy src/carp |
| 79 | + - name: Build docs |
| 80 | + run: sphinx-build -W -b html docs docs/_build/html |
| 81 | + |
| 82 | + build: |
| 83 | + needs: [test, quality] |
| 84 | + runs-on: ubuntu-latest |
| 85 | + steps: |
| 86 | + - uses: actions/checkout@v4 |
| 87 | + - uses: actions/setup-python@v5 |
| 88 | + with: |
| 89 | + python-version: "3.13" |
| 90 | + - name: Build distributions |
| 91 | + run: | |
| 92 | + python -m pip install --upgrade pip |
| 93 | + python -m pip install build twine |
| 94 | + python -m build |
| 95 | + python -m twine check dist/* |
| 96 | + - uses: actions/upload-artifact@v4 |
| 97 | + with: |
| 98 | + name: python-package-distributions |
| 99 | + path: dist/ |
| 100 | + |
| 101 | + publish_pypi: |
| 102 | + needs: build |
| 103 | + runs-on: ubuntu-latest |
| 104 | + environment: |
| 105 | + name: pypi |
| 106 | + permissions: |
| 107 | + id-token: write |
| 108 | + steps: |
| 109 | + - uses: actions/download-artifact@v4 |
| 110 | + with: |
| 111 | + name: python-package-distributions |
| 112 | + path: dist/ |
| 113 | + - uses: pypa/gh-action-pypi-publish@release/v1 |
| 114 | + |
| 115 | + publish_github: |
| 116 | + needs: [validate_tag, publish_pypi] |
| 117 | + runs-on: ubuntu-latest |
| 118 | + permissions: |
| 119 | + contents: write |
| 120 | + steps: |
| 121 | + - uses: actions/download-artifact@v4 |
| 122 | + with: |
| 123 | + name: python-package-distributions |
| 124 | + path: dist/ |
| 125 | + - name: Generate checksums |
| 126 | + run: shasum -a 256 dist/* > dist/SHA256SUMS.txt |
| 127 | + - uses: softprops/action-gh-release@v2 |
| 128 | + with: |
| 129 | + name: Release ${{ needs.validate_tag.outputs.tag }} |
| 130 | + tag_name: ${{ needs.validate_tag.outputs.tag }} |
| 131 | + generate_release_notes: true |
| 132 | + files: dist/* |
0 commit comments