Current section
Files
Jump to
Current section
Files
CONTRIBUTING.md
# Contributing to Replicant
Thank you for your interest in contributing to Replicant!
## Prerequisites
- **Elixir** and **Erlang/OTP** at the exact versions in
[`.tool-versions`](https://github.com/baselabs/replicant/blob/main/.tool-versions).
- **PostgreSQL** with `wal_level=logical` for integration tests, on any supported major:
the platform engine named in [`.github/postgres.ref`](.github/postgres.ref) or a
compatibility major listed in [`.github/postgres-lanes.json`](.github/postgres-lanes.json).
Point `REPLICANT_TEST_URL` at it; `.github/actions/postgres` and `scripts/ci/postgres.sh`
show exactly how CI starts each server, with password authentication.
## Getting Started
```bash
git clone https://github.com/baselabs/replicant.git
cd replicant
mix deps.get --check-locked
mix test
```
There is no pre-commit hook. Checks run when a maintainer submits your change
through the `kci/` landing (see [CI](#ci) below); running them locally first is up to you.
## Development Workflow
1. Fork the repository and work on a short-lived branch.
2. Make your changes with clear, descriptive commit messages.
3. These are the checks CI runs on a maintainer's landing candidate:
```bash
mix format # Format code
mix credo --strict # Lint
mix compile --warnings-as-errors # Zero warnings
mix test # Run tests
mix dialyzer # Type checking
mix audit # Dependency + Hex advisory audit
# or all quality gates at once:
mix quality
```
4. Update `CHANGELOG.md` under `[Unreleased]`.
5. Open a Pull Request against `main`.
### The reference example
[`examples/replication_pipeline`](examples/replication_pipeline/README.md) is a
separate nested Mix project (it path-depends on this library), so it has its
own lockfile and gates. From the repository root, audit that lock with the
root project's locked audit tool, then run the example's own gates:
```bash
mix deps.get --check-locked
mix deps.audit --path examples/replication_pipeline
cd examples/replication_pipeline
mix deps.get --check-locked
mix hex.audit
mix format --check-formatted && mix compile --warnings-as-errors \
&& mix credo --strict && mix dialyzer
docker compose up -d --build # the full stack (source → pipeline → dest)
```
CI runs the dependency audit in `static` and the remaining example gates in
the `reference-example` job — the public sink API's
end-to-end canary — so a change to the sink surface that compiles clean here
can still red there. The repo-root `.dockerignore` is a whitelist (the
example's build context is the repo root); extend it only by adding a
specific `!path`.
## CI
The infrastructure maintainers' CI requirements bind every workflow and release script here;
maintainers read them before changing either.
Every check above, `mix test` on all six PostgreSQL majors, and the docs and
package build are jobs in
[`.github/workflows/qualification.yml`](.github/workflows/qualification.yml).
No workflow runs repository code from a pull request. A fork's change is
qualified when a maintainer lands it through a `kci/<commit>` branch.
[`ci.yml`](.github/workflows/ci.yml) runs the checks once on that candidate,
and `main` moves only on its `qualified` check.
Qualification jobs do not cache dependencies, builds, or Dialyzer PLTs. Each candidate
has a new cache scope, and a cache written on `main` would be restorable by candidates.
Workflow timeouts follow the infrastructure CI requirements. Each comment
names its slowest measured green run and duration; an unmeasured publish job uses
the unmeasured limit until its own first green run.
Every runtime installer takes versions only from the shared `scripts/toolchain.sh`
reader's outputs, selects them strictly, and uses its `--installed` check to refuse a
differing Elixir version, full OTP patch version, or Elixir OTP build suffix.
The example Dockerfile explains its separately pinned container toolchain.
Release scripts read GitHub through `gh api`. The package-check step receives only
its read-only job token as `GH_TOKEN: ${{ github.token }}`, with job-level
`contents: read`; qualification reads no repository or environment secret. Release
absence requires the HTTP 404 status line from `gh api -i` (exit 1); HTTP 200 means
the release exists. Other statuses, transport errors, missing authentication, or
failed metadata reads refuse the check without including response values in errors.
Hex metadata still uses public unauthenticated reads.
## Publishing (release operator only)
Publishing runs in [`.github/workflows/publish.yml`](.github/workflows/publish.yml),
on GitHub-hosted Ubuntu 24.04 with the exact `.tool-versions` runtime. Qualification
and publishing pin the same Hex version because Hex records its version in package
metadata. No workstation publish command or credential-file loader remains.
After the version commit lands on `main`, infra asks an owner (`corepay` or
`palermo-git`) to dispatch **Publish to Hex** on `main` with no inputs. The default
branch ruleset guarantees qualification; publishing makes no run lookup or
artifact download. The owner must also be the triggering actor on a rerun.
Infra declares the GitHub `publish` environment and its `HEX_API_KEY` secret.
Only the archive upload step receives that secret.
An early anonymous Hex lookup refuses a package name that does not already exist:
a first publication of `replicant` is the owner's decision. All lookup errors fail
closed. The workflow checks out the dispatched SHA without persisted credentials.
Building requires a clean checkout of live `origin/main` and refuses a local or
remote version tag or GitHub release. Only the keyless build step receives the job
token through `GH_TOKEN` for GitHub reads; tokens never enter arguments or files.
Both qualification and publication build the package twice from `git archive`
and compare its bytes, inspect the exact package manifest and Hex checksum, then
audit and compile its extracted source using the committed producer lock.
The generated external consumer starts without a lock and resolves fresh, runs
both audits on that resolution, compiles, and exercises the public API.
Documentation renders once with warnings as errors from the extracted package and
producer lock. After rendering, the builder writes a top-level `release.json`
with exactly `package`, `version`, and the full CI `GITHUB_SHA` as `commit`.
Inspection checks those fields and every visible rendered file and refuses EPUB.
ExDoc 0.40.4 supplies a fixed Makeup grouping prefix. Only HTML and Markdown ship.
Hex 2.7.0 sorts archive entries and fixes archive metadata. Under infra's release
rule, this path never replaces or compares served docs: it keeps them and reads
them back by presence and `release.json` provenance. Hex itself allows docs
republishing, but replacing docs on resume could rebind their provenance away
from the commit infra tags. Comparing a rebuild would refuse a held release whose
package bytes match. The producer lock is not packaged, so equal package
bytes alone do not establish which commit rendered served docs.
The single credentialed step runs `mix run --no-mix-exs` from the runner's temporary
directory, which holds no `mix.exs`, with those two inspected file paths. Its
standalone script uses only Hex's APIs and file reads: it refuses to run inside a
Mix project, loads no project code, fetches no dependencies, and rebuilds nothing.
Immediately before uploading, it rechecks that the package name exists. A version
already served by Hex without a tag is a held or partial release: the job compares
its package checksum with the archive it just built, both before and inside the
keyed step. A different package checksum, retirement, malformed metadata, or
lookup failure refuses publication. Identical package bytes skip that upload.
Docs planning keeps a readable served gzip tarball even when metadata says docs
are absent. Upload requires both `has_docs: false` and an HTTP 404 from the
repository. If metadata says `has_docs: true` but the repository returns 404,
publication refuses the disagreement instead of risking replacement during a
repository/CDN delay. Other statuses or malformed bodies refuse. A second owner dispatch on the same commit finishes an approved hold or
interrupted upload; neither package nor served docs are replaced.
Read-back requires the exact served package bytes, no retirement, and served docs.
The docs must be a readable gzip archive with `index.html` and a valid
`release.json` naming this package and version. A following keyless step downloads
the served archives and uses `git merge-base --is-ancestor` against the fetched,
complete default-branch history: the docs commit must equal the dispatched commit
or be its ancestor, and the dispatch must be on that history. Missing history,
missing provenance, or an unrelated commit refuses. Legacy served docs without
`release.json` are kept during planning but cannot pass provenance read-back.
The anonymous docs API redirects to
`https://repo.hex.pm/docs/replicant-<version>.tar.gz`.
After successful read-back, the workflow retains one `release-assets` artifact:
`replicant-<version>.tar`, `replicant-<version>-docs.tar.gz`, `SHA256SUMS`,
`published_commit`, and `RELEASE-NOTES.md`.
Both archives are the bytes Hex serves; `SHA256SUMS` is computed only over those
retained bytes. `published_commit` is retained and exposed as a read-back step
output. The docs suffix distinguishes the gzip docs archive from the package.
Release notes contain the version section from the changelog inside the served
package, followed by the published commit and both archive digests. The section
must occur exactly once and contain more than headings or whitespace; the workflow
checks this before building, and read-back repeats it against the served package.
Temporary archives are removed even after failure. Infra tags `v<version>` at the
published commit from served `release.json`, compares the artifact's package
archive with Hex's served bytes, and creates the GitHub release from those assets.
No workflow creates a release or runs on a tag.
Consumers verify the permanent [GitHub release](https://github.com/baselabs/replicant/releases)
for `v<version>`, downloading its archives and `SHA256SUMS`:
```bash
gh release download vX.Y.Z --repo baselabs/replicant --pattern 'replicant-*' --pattern SHA256SUMS --pattern published_commit
sha256sum --check SHA256SUMS
curl --fail --silent --show-error https://repo.hex.pm/tarballs/replicant-X.Y.Z.tar -o hex.tar
cmp replicant-X.Y.Z.tar hex.tar
tar -xOf replicant-X.Y.Z-docs.tar.gz release.json
cat published_commit
rm hex.tar
```
Check that `release.json` names `replicant`, this version, and the same full commit
as `published_commit` and the release tag. No rebuilt docs digest is involved.
Record the verified package digest in `scripts/release/published_packages.sha256`
through the normal landing process. All four release identities (tag, Hex package,
HexDocs, GitHub release) and the ledger must agree for subsequent package checks.
Held versions never add or alter manifest entries speculatively. An interrupted
or ambiguous upload requires infra to inspect public state before the owner
retries the same commit. A tagged version or existing GitHub release always refuses.
Agents never release, deploy, publish, tag, create a GitHub release, dispatch the
publish workflow, or handle publish credentials. Their work ends at the commit on
`main`.
## Code Style
- Use `mix format` — `.formatter.exs` holds the config.
- Add `@moduledoc` and `@doc` to public modules and functions.
- Read [`docs/INVARIANTS.md`](docs/INVARIANTS.md) before changing decoder,
assembler, identifier, or telemetry code — its Critical Rules (no row values
in errors/logs/telemetry, validated
identifiers, transaction-granularity exactly-once, TOAST-sentinel handling,
tenant-blindness) are binding.
## License
By contributing, you agree that your contributions will be licensed under the MIT License.