|
| 1 | +# GitHub + PyPI Setup Guide |
| 2 | + |
| 3 | +This checklist takes a local `pgpkg` repository to a production-ready GitHub repository with automated PyPI publishing. |
| 4 | + |
| 5 | +## 1) Create and push the GitHub repository |
| 6 | + |
| 7 | +1. Create an empty GitHub repo (for example, `pgpkg`). |
| 8 | +2. Add the remote and push: |
| 9 | + |
| 10 | +```bash |
| 11 | +git remote add origin git@github.com:<OWNER>/pgpkg.git |
| 12 | +git push -u origin <BRANCH> |
| 13 | +``` |
| 14 | + |
| 15 | +3. Push all long-lived branches you want preserved. |
| 16 | + |
| 17 | +## 2) Repository settings (recommended hygiene) |
| 18 | + |
| 19 | +1. Enable branch protection on the default branch: |
| 20 | + - Require pull request before merging |
| 21 | + - Require status checks to pass |
| 22 | + - Require branches to be up to date before merging |
| 23 | +2. Require these checks from CI: |
| 24 | + - `quality` |
| 25 | + - `unit (3.11)` |
| 26 | + - `unit (3.12)` |
| 27 | + - `unit (3.13)` |
| 28 | + - `integration (postgres:14-alpine)` |
| 29 | + - `integration (postgres:15-alpine)` |
| 30 | + - `integration (postgres:16-alpine)` |
| 31 | + - `integration (postgres:17-alpine)` |
| 32 | + - `build-docs` |
| 33 | +3. Enable "Automatically delete head branches" after merge. |
| 34 | +4. Enable Dependabot alerts and security updates. |
| 35 | +5. In Settings -> Pages, set Source to `GitHub Actions` so `.github/workflows/docs-pages.yml` can publish the MkDocs site. |
| 36 | + |
| 37 | +## 3) PyPI account and project prerequisites |
| 38 | + |
| 39 | +You need an account on: |
| 40 | +- https://pypi.org |
| 41 | + |
| 42 | +### Required access |
| 43 | + |
| 44 | +- You must be an Owner or Maintainer for the project on PyPI. |
| 45 | +- You must have admin rights on the GitHub repository to configure environments and workflows. |
| 46 | + |
| 47 | +## 4) Preferred publishing model: Trusted Publishing (OIDC) |
| 48 | + |
| 49 | +This repository already includes `.github/workflows/publish-pypi.yml`, which is configured for trusted publishing. |
| 50 | + |
| 51 | +### 4a) Configure GitHub environments |
| 52 | + |
| 53 | +Create these environments in GitHub: |
| 54 | +- `pypi` |
| 55 | + |
| 56 | +Optional hardening: |
| 57 | +- Add required reviewers for `pypi` environment |
| 58 | +- Restrict deployment branches/tags |
| 59 | + |
| 60 | +### 4b) Configure trusted publisher on PyPI |
| 61 | + |
| 62 | +In PyPI project settings, add a trusted publisher with: |
| 63 | +- Owner: `<OWNER>` |
| 64 | +- Repository: `pgpkg` |
| 65 | +- Workflow filename: `publish-pypi.yml` |
| 66 | +- Environment: `pypi` |
| 67 | + |
| 68 | +## 5) Credentials you actually need |
| 69 | + |
| 70 | +With trusted publishing configured correctly: |
| 71 | +- No PyPI API token is needed in GitHub secrets. |
| 72 | +- No username/password is needed in CI. |
| 73 | +- The only required "credential" in CI is GitHub's OIDC identity (`id-token: write`, already set in workflow). |
| 74 | + |
| 75 | +You still need: |
| 76 | +- GitHub account with repo admin rights |
| 77 | +- PyPI account with project owner/maintainer rights |
| 78 | + |
| 79 | +## 6) Optional fallback model: API token publishing |
| 80 | + |
| 81 | +Only use this if trusted publishing cannot be enabled. |
| 82 | + |
| 83 | +1. Create a project-scoped API token in PyPI. |
| 84 | +2. Add these repository secrets: |
| 85 | + - `PYPI_API_TOKEN` |
| 86 | +3. Update publish workflow to pass `password: ${{ secrets.<TOKEN_NAME> }}` to `pypa/gh-action-pypi-publish`. |
| 87 | + |
| 88 | +## 7) First release flow |
| 89 | + |
| 90 | +1. Run local gate: |
| 91 | + |
| 92 | +```bash |
| 93 | +uv run pre-commit run --all-files |
| 94 | +uv run ty check src tests |
| 95 | +uv run pytest -q |
| 96 | +uv build --out-dir dist |
| 97 | +uv run python -m twine check dist/* |
| 98 | +uv run mkdocs build --strict |
| 99 | +``` |
| 100 | + |
| 101 | +2. Create GitHub Release tag `v0.1.0` to trigger PyPI publish. |
| 102 | + |
| 103 | +Optional manual path: |
| 104 | +- GitHub Actions -> `Publish` -> `Run workflow` -> `expected_version=0.1.0` |
| 105 | + |
| 106 | +3. Verify install from PyPI: |
| 107 | + |
| 108 | +```bash |
| 109 | +uv venv /tmp/pgpkg-smoke |
| 110 | +uv pip install --python /tmp/pgpkg-smoke/bin/python pgpkg |
| 111 | +/tmp/pgpkg-smoke/bin/pgpkg --help |
| 112 | +``` |
| 113 | + |
| 114 | +The `Publish` workflow's build job also smoke-tests a generated wrapper wheel, |
| 115 | +so a successful publish already validates both the base CLI wheel and the |
| 116 | +wrapper packaging path before upload. |
| 117 | + |
| 118 | +TestPyPI is intentionally not wired up in this repository right now. If access |
| 119 | +is restored later, add a separate environment and publish job rather than |
| 120 | +reusing the PyPI lane implicitly. |
| 121 | + |
| 122 | +## 8) Post-setup metadata cleanup |
| 123 | + |
| 124 | +Add canonical URLs in `pyproject.toml`: |
| 125 | + |
| 126 | +```toml |
| 127 | +[project.urls] |
| 128 | +Homepage = "https://github.com/<OWNER>/pgpkg" |
| 129 | +Repository = "https://github.com/<OWNER>/pgpkg" |
| 130 | +Documentation = "https://<OWNER>.github.io/pgpkg/" |
| 131 | +Issues = "https://github.com/<OWNER>/pgpkg/issues" |
| 132 | +``` |
| 133 | + |
| 134 | +## 9) Quick troubleshooting |
| 135 | + |
| 136 | +- "invalid-publisher" or "publisher not trusted": trusted publisher fields do not exactly match repo/workflow/environment. For this repo, confirm `bitner/pgpkg`, workflow `publish-pypi.yml`, and environment `pypi` exactly. |
| 137 | +- Publish job not starting: verify environment name in workflow matches configured environment. |
| 138 | +- Artifact missing in publish job: ensure build job used `uv build --out-dir dist` and uploaded `dist/*`. |
0 commit comments