| 1 | # Contributing to Utopia |
| 2 | |
| 3 | [中文](CONTRIBUTING.zh-CN.md) |
| 4 | |
| 5 | Welcome. This file covers what is specific to this repository; general open-source etiquette is assumed. |
| 6 | |
| 7 | ## Branches and how changes land |
| 8 | |
| 9 | | Branch | What it is | |
| 10 | |---|---| |
| 11 | | `main` | Stable, matches the released version. Only maintainers merge into it, from `dev` | |
| 12 | | `dev` | Integration branch. Every contribution lands here first | |
| 13 | |
| 14 | Your path as a contributor: |
| 15 | |
| 16 | ```bash |
| 17 | git switch dev && git pull |
| 18 | git switch -c fix/some-thing # branch off dev, not main |
| 19 | # make changes, commit with -s (see DCO below) |
| 20 | git push -u origin fix/some-thing |
| 21 | ``` |
| 22 | |
| 23 | Then open a PR with **base `dev`, not `main`**. A maintainer merges once CI and review pass. |
| 24 | |
| 25 | Merging `dev → main` is done by maintainers on their own schedule; contributors don't need to think about it. Two rules keep the two branches from drifting apart, and both are for maintainers: |
| 26 | |
| 27 | - **Back-merge `main` into `dev` right after a release.** The `dev → main` merge commit lives only on `main`, so without this `main` reads as ahead even though the trees are identical, and the gap grows by one every release. |
| 28 | - **Urgent fixes go through `dev` too.** A PR opened straight against `main` is the one thing that makes the two branches genuinely diverge, and then someone has to reconcile them by hand. |
| 29 | |
| 30 | Both branches are protected: pull request required, CI (`backend` and `web`) must pass, no force pushes, no deletions, and admins are held to the same rules. |
| 31 | |
| 32 | ## Issue first, or straight to a PR |
| 33 | |
| 34 | | Change | What to do | |
| 35 | |---|---| |
| 36 | | Bug fixes, docs, i18n strings, tests | Open a PR directly | |
| 37 | | New features, dependency changes | Open an [issue](https://github.com/deeplethe/utopia/issues) first and describe the use case | |
| 38 | | Data model, ontology contract, public API | Discuss in an issue, then land an [ADR](docs/decisions/) before writing code | |
| 39 | |
| 40 | `docs/decisions/` is where this project's reasoning lives. An ADR records **why this and not that**, including the approaches that were tried and failed. For a change of any size, that document outlives the code. |
| 41 | |
| 42 | ## Local setup |
| 43 | |
| 44 | Requires Docker, Rust 1.85+, Node 20+, pnpm. |
| 45 | |
| 46 | ```bash |
| 47 | docker compose up -d db # Postgres with pgvector |
| 48 | cargo run -p utopia-server # runs migrations, :1516 |
| 49 | cd web && pnpm install && pnpm dev # :5173, proxies /api to the backend |
| 50 | ``` |
| 51 | |
| 52 | ## Before you push |
| 53 | |
| 54 | CI runs exactly this. Green locally means green in CI: |
| 55 | |
| 56 | ```bash |
| 57 | cargo fmt --all --check |
| 58 | cargo clippy --workspace --all-targets -- -D warnings |
| 59 | cargo test --workspace |
| 60 | cd web && pnpm install --frozen-lockfile && pnpm build # build type-checks |
| 61 | ``` |
| 62 | |
| 63 | ### Database-backed tests **skip** without the env var |
| 64 | |
| 65 | This is the easiest thing to get wrong here. A green `cargo test --workspace` does not mean everything ran. A number of tests begin like this: |
| 66 | |
| 67 | ```rust |
| 68 | let Ok(url) = std::env::var("UTOPIA_DATABASE_URL") else { |
| 69 | eprintln!("skipping: UTOPIA_DATABASE_URL not set"); |
| 70 | return Ok(()); |
| 71 | }; |
| 72 | ``` |
| 73 | |
| 74 | They guard what the compiler cannot see: table aliases inside SQL strings, how `NULL` behaves in a comparison, rows an `INNER JOIN` silently drops, whether a recursive CTE expands the same ancestor twice under diamond inheritance. `cargo check` and clippy say nothing about any of it. |
| 75 | |
| 76 | If you touched SQL under `crates/utopia-store/`, set it and run again: |
| 77 | |
| 78 | ```bash |
| 79 | export UTOPIA_DATABASE_URL=postgres://utopia:utopia@localhost:5432/utopia |
| 80 | cargo test --workspace |
| 81 | ``` |
| 82 | |
| 83 | ## Things review will send back |
| 84 | |
| 85 | **Don't collide migration numbers.** `migrations/` rolls forward by number. Check the latest number on `main` before opening a PR — two branches each writing an `0011_` has happened, and after the merge neither one runs. |
| 86 | |
| 87 | **UI strings go in i18n.** Add to both `web/src/i18n/en.ts` and `zh.ts`; no hard-coded strings in components. |
| 88 | |
| 89 | **Comments explain why.** This repository comments densely and deliberately records the traps it fell into ("the first version used OR, and the Elon Musk article then produced a snapshot every 6KB"). Follow that. A comment restating what the code does will be asked to go. |
| 90 | |
| 91 | **Commit messages: one English sentence, stating the motivation.** No long body. Skim `git log` for the register. |
| 92 | |
| 93 | **Every workflow declares its own `permissions:`.** The repository default is now read-and-write, because one workflow commits a generated chart. A workflow without a `permissions:` block inherits that default, so leaving it out silently hands write access to something that only needed to read. Declare the minimum the job actually needs — `contents: read` for anything that just builds or tests. |
| 94 | |
| 95 | ## DCO: sign off every commit |
| 96 | |
| 97 | We use the [DCO](https://developercertificate.org/), not a CLA. You keep the copyright on your code; you are certifying that you have the right to submit it under Apache-2.0. |
| 98 | |
| 99 | Commit with `-s` and git adds the line for you: |
| 100 | |
| 101 | ```bash |
| 102 | git commit -s -m "Fix the thing" |
| 103 | ``` |
| 104 | |
| 105 | which appends: |
| 106 | |
| 107 | ``` |
| 108 | Signed-off-by: Your Name <your@email> |
| 109 | ``` |
| 110 | |
| 111 | Forgot? `git commit --amend -s` for the last commit, or `git rebase --signoff HEAD~3` for several (adjust the count), then `git push -f`. |
| 112 | |
| 113 | Use a real name and a reachable email address. |
| 114 | |
| 115 | ## License |
| 116 | |
| 117 | By contributing you agree that your work is released under [Apache-2.0](LICENSE). |