diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 65c1a86..2210bed 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,6 +21,8 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: ref: main + # Deploy key on the main ruleset's bypass list, so the release commit can be pushed + ssh-key: ${{ secrets.RELEASE_DEPLOY_KEY }} # Credentials are kept so the job can push the release commit persist-credentials: true # zizmor: ignore[artipacked] - name: Install uv @@ -40,6 +42,17 @@ jobs: VERSION: ${{ steps.drafter.outputs.resolved_version }} run: uv version "$VERSION" + # Build before pushing, so a build failure leaves nothing released + - name: Build + run: uv build + + - name: Store build for the PyPI job + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: dist + path: dist/ + if-no-files-found: error + - name: Commit and push id: commit env: @@ -61,10 +74,28 @@ jobs: gh api -X PATCH "repos/${{ github.repository }}/releases/$RELEASE_ID" \ -F draft=false -f target_commitish="$SHA" - - name: Build and upload artifacts + - name: Upload artifacts env: GH_TOKEN: ${{ github.token }} TAG: ${{ steps.drafter.outputs.tag_name }} - run: | - uv build - gh release upload "$TAG" dist/* + run: gh release upload "$TAG" dist/* + + publish-pypi: + needs: [ release ] + runs-on: ubuntu-latest + environment: pypi + permissions: + # Trusted publishing to PyPI + id-token: write + steps: + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: dist + path: dist + - name: Install uv + uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 + with: + enable-cache: false + version: ">=0.13,<0.14" + - name: Publish to PyPI + run: uv publish diff --git a/CI.md b/CI.md index a1b30de..f1d4e52 100644 --- a/CI.md +++ b/CI.md @@ -5,13 +5,17 @@ | `python.yml` | push / PR to `main` | lint and unit tests | | `security.yml` | push to `main`, all PRs | zizmor workflow audit, gitleaks secret scan | | `release-drafter.yml` | push to `main`, PRs | update the draft release, label PRs | -| `release.yml` | manual | publish a release | +| `release.yml` | manual | publish a release to GitHub and PyPI | | `docs.yml` | push / PR to `main`, manual | build docs, deploy to GitHub Pages (not PRs) | * The docs site deploys through GitHub Pages, so the repo's Pages source must be set to **GitHub Actions**. PRs build the docs in strict mode without deploying * On PRs, `release-drafter.yml` also runs the `require-label` check, which fails until the PR has at least one release label (see [RELEASE.md](RELEASE.md)) +* `release.yml` has two jobs. `release` bumps the version, builds, pushes the release commit with + a deploy key, and publishes the GitHub Release. `publish-pypi` then uploads the same build to + PyPI with trusted publishing, from the `pypi` environment. See [RELEASE.md](RELEASE.md) for the + settings it needs * GitHub Actions are pinned to full commit SHAs, with the version in a trailing comment * Dependabot (`.github/dependabot.yml`) checks weekly for updates to GitHub Actions and Python dependencies, and monthly for the dev container image and dev container features. New releases diff --git a/README.md b/README.md index 6e536f0..b3776d2 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv) [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) ![Python](https://img.shields.io/badge/python-3.15-blue) -[![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE) +[![License: MIT](https://img.shields.io/badge/license-MIT-green)](https://github.com/ahcodedev/pypricecharting/blob/main/LICENSE) PriceCharting API Client written in Python @@ -37,6 +37,7 @@ manage project configuration and commands * `just setup` - install tools and git hooks, then sync dependencies * `just sync` - sync project dependencies +* `just build` - build the sdist and wheel into `dist/` * `just lint` - type check (`ty`), lint and format (`ruff`), and spellcheck (`codespell`). Fixes files in place * `just ci-lint` - same checks as `just lint`, without modifying files * `just test` - run unit tests @@ -58,7 +59,7 @@ manage project configuration and commands ## CI and Security -See [CI.md](CI.md) for the GitHub Actions workflows and Dependabot setup. +See [CI.md](https://github.com/ahcodedev/pypricecharting/blob/main/CI.md) for the GitHub Actions workflows and Dependabot setup. ## Documentation @@ -68,7 +69,10 @@ workflow deploys the site to GitHub Pages on every push to `main`. ## Releases -See [RELEASE.md](RELEASE.md) for how releases and release labels work. +Releases are published to GitHub Releases and to [PyPI](https://pypi.org/project/pypricecharting/) +by the `Release` workflow. See +[RELEASE.md](https://github.com/ahcodedev/pypricecharting/blob/main/RELEASE.md) for how releases +and release labels work. ## Usage diff --git a/RELEASE.md b/RELEASE.md index 7be1f9e..9e0923e 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -23,8 +23,25 @@ labels; other repository labels (e.g. `good first issue`, `question`) are ignore `*.md` adds `documentation`, and `uv.lock` adds `dependencies`. You can add or change them by hand * Merging to `main` updates a draft GitHub Release with the next version and notes * To release, run the **Release** workflow from the Actions tab. It bumps the version in - `pyproject.toml`/`uv.lock`, tags the release, and uploads build artifacts. The GitHub Release - notes are the changelog -* The Release workflow commits the version bump as `Release vX.Y.Z` and pushes it straight to - `main` as `github-actions[bot]`, with no PR. The tag points at that commit. Branch protection - on `main` must allow this push, or the workflow fails before the release is published + `pyproject.toml`/`uv.lock`, builds the package, tags and publishes the GitHub Release with the + build attached, then publishes the same build to [PyPI](https://pypi.org/project/pypricecharting/). + The GitHub Release notes are the changelog +* The workflow regenerates the draft's notes when it starts, so edit the notes after the release + is published, not before +* The version bump is committed as `Release vX.Y.Z` and pushed straight to `main`, with no PR. + The tag points at that commit +* The first release must resolve to a version above the `0.0.1` in `pyproject.toml`, or the + commit step fails with nothing to commit + +## Release setup + +The Release workflow depends on these settings outside the repository files: + +* **Deploy key**: the release commit is pushed over SSH with a write-access deploy key. Its + private half is the `RELEASE_DEPLOY_KEY` Actions secret. If `main` has a ruleset that requires + pull requests or status checks, **Deploy keys** must be on its bypass list +* **PyPI trusted publisher**: PyPI trusts owner `ahcodedev`, repository `pypricecharting`, + workflow `release.yml`, and environment `pypi`. No PyPI token is stored. Renaming the workflow + file or the environment breaks publishing until PyPI is updated +* **`pypi` environment**: the `publish-pypi` job runs in the `pypi` GitHub environment. If it has + required reviewers, the PyPI upload waits for approval after the GitHub Release is published diff --git a/justfile b/justfile index e074254..f212ee5 100644 --- a/justfile +++ b/justfile @@ -1,28 +1,44 @@ +[private] +list: + @just --list +# Build the sdist and wheel into dist/ +build: + uv build +# Lint without modifying files ci-lint: uv run ty check uv run ruff check . uv run ruff format --check . uv run codespell +# Serve the docs site with live reload docs: uv run zensical serve +# Build the docs site in strict mode docs-build: uv run zensical build --strict +# Scan staged changes for secrets git-leaks: gitleaks git --pre-commit --staged --redact +# Type check, lint, format and spellcheck, fixing files in place lint: uv run ty check uv run ruff check . --fix uv run ruff format . uv run codespell +# Run all pre-commit hooks prek: uv run prek +# Install tools and git hooks, then sync dependencies setup: brew bundle install uv run prek install just sync +# Sync all dependency groups sync: uv sync --all-groups +# Run unit tests test: uv run pytest +# Audit GitHub Actions workflows zizmor: zizmor . --collect all diff --git a/mkdocs.yml b/mkdocs.yml index 75f450b..71b97a1 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,5 +1,6 @@ site_name: PyPriceCharting site_description: Python PriceCharting API Client +site_url: https://ahcodedev.github.io/pypricecharting/ repo_url: https://github.com/ahcodedev/pypricecharting repo_name: ahcodedev/pypricecharting strict: true diff --git a/pyproject.toml b/pyproject.toml index 2ac53a6..eb4e310 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,12 +5,29 @@ version = "0.0.1" requires-python = ">=3.15" license = "MIT" license-files = ["LICENSE"] +readme = "README.md" +authors = [ + { name = "ahcodedev" }, +] +keywords = ["pricecharting", "api", "client"] +classifiers = [ + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.15", + "Typing :: Typed", +] dependencies = [ "httpx2>=2.16.0", "pydantic>=2.14.3", ] +[project.urls] +Repository = "https://github.com/ahcodedev/pypricecharting" +Issues = "https://github.com/ahcodedev/pypricecharting/issues" +Documentation = "https://ahcodedev.github.io/pypricecharting/" + [build-system] requires = ["uv_build>=0.13.7,<0.14.0"] build-backend = "uv_build" diff --git a/src/pypricecharting/py.typed b/src/pypricecharting/py.typed new file mode 100644 index 0000000..e69de29