# Releases and scaffolding


[`ship_release`](#ship_release) detects the project layout and runs the full release flow. For Python and `nbdev` projects it refreshes `llms.txt`, updates `CHANGELOG.md`, commits and pushes, builds and uploads to PyPI, creates the GitHub release, and bumps the version. For maturin/PyO3, Zig, npm, pure-Rust crate, or `[tool.fastship] release = "tag"` projects it pushes an annotated `vX.Y.Z` tag so CI builds and publishes artifacts, then bumps the version.

``` bash
ship-release
ship-release --yes --no-editor
```

GitHub commands resolve authentication in order: `--token` / `token`, `$FASTSHIP_TOKEN`, a `./token` file (checked in the project root, then the current directory), and `$GITHUB_TOKEN`. Commands raise `CliError` for missing credentials, invalid repo or project state, or refusing to overwrite existing targets without `--force`, `ValueError` for invalid config or `version-files`, and `APIError` or `subprocess.CalledProcessError` when GitHub API or build commands fail.

## Releasing

Run the full release workflow, individual changelog/PyPI/GitHub stages, or squash-merge a quick PR; subclass [`Release`](#release) to customize changelog label groups.

### ship_release

``` python
async def ship_release(
    token:str=None, # GitHub token (else `$FASTSHIP_TOKEN`, `./token`, or `$GITHUB_TOKEN`)
    repo:str=None, # Override repo (`"OWNER/REPO"`)
    repository:str='pypi', # PyPI repository name in `~/.pypirc`
    no_changelog:bool=False, # Skip changelog generation (Python and `nbdev` flows only)
    no_editor:bool=False, # Skip opening `CHANGELOG.md` in `$EDITOR` (Python and `nbdev` flows only)
    yes:bool=False, # Skip confirmation prompt (Python and `nbdev` flows; tag flows never prompt)
    wheel_only:bool=False, # Build only a wheel without an sdist (Python and `nbdev` flows)
    verbose:bool=False, # Pass `--verbose` to `twine upload`
):
```

*Run the full release workflow for the detected project type, then bump and push the version.*

- Plain Python and `nbdev`: refreshes `llms.txt`, updates `CHANGELOG.md`, builds and checks distributions, commits and pushes, creates the GitHub release, uploads to PyPI, and commits a `[skip ci]` version bump.
- Static `[project].version` with no package ([`gh_only`](config.html#gh_only)): skips changelog, build, and PyPI; creates a GitHub release with auto-generated notes and bumps `pyproject.toml`.
- Rust/maturin, Zig, npm, pure-Rust crate, or `[tool.fastship] release = "tag"`: requires a clean git tree, validates `version-files`, refreshes `llms.txt` when applicable, pushes an annotated `v<version>` tag for CI publication, and commits a `[skip ci]` bump.

``` bash
ship-release
ship-release --no-changelog --no-editor --yes
```

### ship_changelog

``` python
async def ship_changelog(
    token:str=None, # GitHub token (else `$FASTSHIP_TOKEN`, `./token`, or `$GITHUB_TOKEN`)
    repo:str=None, # Override repo (`"OWNER/REPO"`)
):
```

*Create or update `CHANGELOG.md` from closed GitHub issues since the last GitHub release.*

Delegates to [`nbdev.release.changelog`](https://nbdev.fast.ai/api/release.html#changelog) for `nbdev` Python projects. Existing changelogs must include `<!-- do not remove -->` near the top; re-running replaces the pending section for the current version.

### ship_pypi

``` python
def ship_pypi(
    repository:str='pypi', # Repository name in `~/.pypirc` (e.g. `"pypi"` or `"testpypi"`)
    quiet:bool=False, # Reduce build and upload output verbosity
    wheel_only:bool=False, # Build only a wheel without an sdist (also honored via `[tool.fastship].wheel-only`)
    verbose:bool=False, # Pass `--verbose` to `twine upload`
):
```

*Build distributions (`python -m build`), validate with `twine check`, and upload via `twine upload`.*

Delegates to [`nbdev.release.release_pypi`](https://nbdev.fast.ai/api/release.html#release_pypi) for `nbdev` Python projects. Does not bump the version.

### ship_release_gh

``` python
async def ship_release_gh(
    token:str=None, # GitHub token (else `$FASTSHIP_TOKEN`, `./token`, or `$GITHUB_TOKEN`)
    repo:str=None, # Override repo (`"OWNER/REPO"`)
    no_changelog:bool=False, # Skip changelog generation (assumes `CHANGELOG.md` is ready)
    no_editor:bool=False, # Skip opening `CHANGELOG.md` in `$EDITOR` (defaults to `nano`)
    yes:bool=False, # Release without prompting for confirmation
):
```

*Update `CHANGELOG.md`, optionally edit it, commit and push tracked changes, and create a GitHub release.*

Delegates to [`nbdev.release.release_gh`](https://nbdev.fast.ai/api/release.html#release_gh) for `nbdev` Python projects. Exits with code 1 if confirmation is declined.

``` bash
ship-gh
ship-gh --no-changelog --no-editor --yes
```

### Release

``` python
def Release(
    owner:str=None, # GitHub owner or organization (inferred from `repo` or git `origin` when omitted)
    repo:str=None, # Repository name or `"OWNER/REPO"` slug
    token:str=None, # GitHub token (else `$FASTSHIP_TOKEN`, `./token`, or `$GITHUB_TOKEN`)
    cfg:fastship.config.ShipConfig | None=None, # Explicit `ShipConfig` (loads via `get_config()` when omitted)
    **groups
):
```

*[`nbdev.release.Release`](https://nbdev.fast.ai/api/release.html#release) configured from [`ShipConfig`](config.html#shipconfig) instead of `nbdev` settings, releasing on `cfg.branch`.*

Resolves changelog label groups in order: explicit `groups` keyword arguments, `.github/release.yml` (or `.yaml`), `[tool.fastship].label_groups`, and `DEFAULT_LABEL_GROUPS`. Changes working directory to `cfg.root` during initialization.

Attributes:

- `cfg`: Loaded [`ShipConfig`](config.html#shipconfig) instance.
- `changefile`: Path to `CHANGELOG.md` (from `cfg.changelog_file`).
- `groups`: Mapping of GitHub issue label to changelog section heading.
- `gh`: Authenticated `GhApi` client for the repository.

#### Release.release

``` python
async def release()->Release: # This `Release` instance
```

*Tag and create a GitHub release for `cfg.version` on `cfg.branch`.*

Uses GitHub’s auto-generated release notes when `cfg.gh_only` is true, and the latest `CHANGELOG.md` entry otherwise.

### ship_pr

``` python
async def ship_pr(
    title:str, # PR title (also used as commit message for uncommitted changes and squash title)
    branch:str=None, # Branch name to create (defaults to `pr/<slug-from-title>`)
    label:str='enhancement', # GitHub label added to the PR
    body:str='', # PR body text, path to an existing file containing it, or `"-"` to read stdin
    token:str=None, # GitHub token (else `$FASTSHIP_TOKEN`, `./token`, or `$GITHUB_TOKEN`)
    repo:str=None, # Override repo (`"OWNER/REPO"`)
    path:str='.', # Repository directory (defaults to current working directory)
):
```

*Create a pull request from uncommitted or unpushed work, squash-merge it, and reset the default branch.*

Run from the default branch with no unpulled commits on `origin`. Creates a branch, commits tracked changes, pushes, opens and labels the PR, and squash-merges it. Afterward it deletes both remote and local PR branches and resets the default branch to `origin/<default>`.

``` bash
ship-pr "Add new feature"
ship-pr "Fix bug" --label bug --body notes.md
```

## Project setup and scaffolding

Create new repositories or wire existing ones for `fastship` releases and GitHub Pages docs.

### ship_new

``` python
def ship_new(
    name:str, # Project name (PyPI name), e.g. `"my-project"`
    package:str=None, # Python package import name, e.g. `"my_project"` (defaults from `name`)
    description:str='A Python package', # Short project description
    path:str='.', # Parent directory to create the project folder in
    gh_org:str='AnswerDotAI', # GitHub organization for `[project.urls]`
    force:bool=False, # Overwrite files if the target folder already exists
)->pathlib._local.Path: # Path to the created project directory
```

*Create a plain Python setuptools project wired for `fastship`.*

Writes `pyproject.toml` (with dynamic `__version__`), `<pkg>/__init__.py`, `README.md`, `CHANGELOG.md`, `MANIFEST.in`, `LICENSE`, `.gitignore`, and `.github/workflows/docs.yml`. Author metadata is read from git’s global `user.name` and `user.email`.

``` bash
ship-new my-project
cd my-project && pip install -e '.[dev]'
```

### ship_rs_new

``` python
def ship_rs_new(
    name:str, # Project name (PyPI and Cargo name), e.g. `"my-project"`
    package:str=None, # Python package import name, e.g. `"my_project"` (defaults from `name`)
    description:str='A PyO3 package', # Short project description
    path:str='.', # Parent directory to create the project folder in
    gh_org:str='AnswerDotAI', # GitHub organization for `[project.urls]`
    force:bool=False, # Overwrite files if the target folder already exists
)->pathlib._local.Path: # Path to the created project directory
```

*Create a maturin/PyO3 Cargo workspace wired for `fastship` Rust commands.*

The root package (`Cargo.toml`, `src/lib.rs`) is a publishable pure-Rust crate, and `py/` holds the unpublished PyO3 extension built through `fastws.build_backend`. Both crates share `[workspace.package].version`.

``` bash
ship-rs-new my-project
cd my-project && pip install -e '.[dev]' && cargo develop && pytest -q
```

### ship_crate_new

``` python
def ship_crate_new(
    name:str, # Crate name (crates.io name), e.g. `"my-crate"`
    description:str='A Rust crate', # Short crate description
    path:str='.', # Parent directory to create the project folder in
    gh_org:str='AnswerDotAI', # GitHub organization for `[package].repository`
    force:bool=False, # Overwrite files if the target folder already exists
)->pathlib._local.Path: # Path to the created project directory
```

*Create a pure-Rust crate wired for `fastship` tag releases and crates.io trusted publishing.*

Writes `Cargo.toml`, `src/lib.rs`, `README.md`, `LICENSE`, `.gitignore`, and `.github/workflows/ci.yml` (using `sccache` and trusted crates.io + GitHub release publishing on `v*` tags).

``` bash
ship-crate-new my-crate
cd my-crate && cargo test
```

### ship_zig_new

``` python
def ship_zig_new(
    name:str, # Project name (PyPI name), e.g. `"my-project"`
    package:str=None, # Python package import name (defaults from `name`)
    description:str='A Zig-backed Python package', # Short project description
    path:str='.', # Parent directory to create the project folder in
    gh_org:str='AnswerDotAI', # GitHub organization for `[project.urls]`
    force:bool=False, # Overwrite files if the target folder already exists
)->pathlib._local.Path: # Path to the created project directory
```

*Create a CFFI/Zig Python project with cross-platform wheels and trusted tag publishing.*

Writes `pyproject.toml`, `setup.py`, `build_lib.py`, `src/lib.zig`, `<pkg>/` CFFI bindings, `tests/test_basic.py`, `README.md`, `DEV.md`, `MANIFEST.in`, `LICENSE`, `.gitignore`, and GitHub Actions workflows (`ci.yml`, `docs.yml`).

``` bash
ship-zig-new my-project
cd my-project && pip install -e '.[dev]' && python build_lib.py && pytest -q
```

### ship_rs_init

``` python
def ship_rs_init(
    branch:str=None, # Release branch for `[tool.fastship]` (defaults to existing or current branch)
    force:bool=False, # Overwrite existing `[tool.fastship]` keys
):
```

*Configure an existing maturin/PyO3 project for `fastship` Rust commands.*

Removes any static `[project].version`, adds `"version"` to `[project].dynamic`, adds `[project.optional-dependencies].dev` when absent, exposes `__version__` from `CARGO_PKG_VERSION` in the PyO3 module (and Python wrapper when present), and writes `[tool.fastship].branch`.

### ship_npm_init

``` python
def ship_npm_init(
    branch:str=None, # Release branch for `[tool.fastship]` (defaults to existing or current branch)
    force:bool=False, # Overwrite an existing `.github/workflows/ci.yml`
)->pathlib._local.Path: # Path to the generated `.github/workflows/ci.yml`
```

*Configure an existing Python+npm or npm-only project for tag-triggered OIDC releases via GitHub Actions.*

Writes `.github/workflows/ci.yml` (running `npm run build` when defined and publishing on `v*` tags). For Python+npm projects, also syncs `package.json`’s version to Python’s version, sets `[tool.fastship] release = "tag"`, and adds `"package.json"` to `version-files`.

### ship_pages

``` python
async def ship_pages(
    token:str=None, # GitHub token (else `$FASTSHIP_TOKEN`, `./token`, or `$GITHUB_TOKEN`)
    runner:str='ubuntu-latest', # GitHub Actions runner label (e.g. `"macos-latest"`)
)->str: # Published GitHub Pages URL
```

*Configure GitHub Pages Actions docs deployment and enable Pages on the GitHub repository.*

Creates `.github/workflows/docs.yml` when absent (adding Rust or `fastws` install steps for maturin projects) and removes legacy `_config.yml` and `_layouts/`. Enables GitHub Pages with `build_type="workflow"` (ignoring HTTP 409 if already enabled), sets the repository homepage, fills `[project.urls].Documentation` if unset, and adds `[project.entry-points.nbdev]` (`pkg = "pkg._modidx:d"`) for non-nbdev packages.

## Local native builds

Build native wheels locally for maturin/PyO3 and Zig projects.

### ship_rs_build

``` python
def ship_rs_build(
    profile:str='release', # Cargo build profile (`"release"`, `"dist"`, `"dev"`, etc.)
    target:str=None, # Optional Rust target triple
    outdir:str='dist', # Directory to write the built wheel into
    args:str='', # Extra CLI arguments forwarded to maturin's build backend
):
```

*Build a maturin/PyO3 wheel through the project’s configured PEP 517 backend (`python -m build --wheel`).*

Passes `--profile` (and `--target` / `args` when given) via `-C maturin.build-args=...`, preserving `fastws.build_backend` native binary staging when configured.

### ship_zig_build

``` python
def ship_zig_build(
    quiet:bool=False, # Reduce build and `twine check` output verbosity
):
```

*Build and `twine check` the current platform wheel for a `fastship` Zig project (`ziglang` in `[build-system].requires`).*
