Skip to content

Commit 7e24d83

Browse files
committed
Update development docs
1 parent 1a0c99f commit 7e24d83

File tree

2 files changed

+82
-76
lines changed

2 files changed

+82
-76
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ The production instance of the bot is deployed at https://bors-prod.rust-lang.ne
1414
There are several parameters that can be configured when launching the bot. Parameters without a default value are
1515
required.
1616

17-
| **CLI flag** | **Environment var.** | **Default** | **Description** |
18-
|--------------------|----------------------|-------------|-----------------------------------------------------------|
19-
| `--app-id` | `APP_ID` | | GitHub app ID of the bors bot. |
20-
| `--private-key` | `PRIVATE_KEY` | | Private key of the GitHub app. |
21-
| `--webhook-secret` | `WEBHOOK_SECRET` | | Key used to authenticate GitHub webhooks. |
22-
| `--client-id` | `OAUTH_CLIENT_ID` | | GitHub OAuth client ID for rollup UI (optional). |
23-
| `--client-secret` | `OAUTH_CLIENT_SECRET`| | GitHub OAuth client secret for rollup UI (optional). |
24-
| `--db` | `DATABASE_URL` | | Database connection string. Only PostgreSQL is supported. |
25-
| `--cmd-prefix` | `CMD_PREFIX` | @bors | Prefix used to invoke bors commands in PR comments. |
26-
| `--web_url` | `WEB_URL` | http://localhost:8080| Web URL where the bot's website is deployed (optional).|
27-
| `--permissions` | `PERMISSIONS` | Rust Team API url| Either a URL to the team v1 API or a path to a directory containing JSON files with try/review permissions (optional).|
17+
| **CLI flag** | **Environment var.** | **Default** | **Description** |
18+
|--------------------|-----------------------|-----------------------|------------------------------------------------------------------------------------------------------------------------|
19+
| `--app-id` | `APP_ID` | | GitHub app ID of the bors bot. |
20+
| `--private-key` | `PRIVATE_KEY` | | Private key of the GitHub app. |
21+
| `--webhook-secret` | `WEBHOOK_SECRET` | | Key used to authenticate GitHub webhooks. |
22+
| `--client-id` | `OAUTH_CLIENT_ID` | | GitHub OAuth client ID for rollup UI (optional). |
23+
| `--client-secret` | `OAUTH_CLIENT_SECRET` | | GitHub OAuth client secret for rollup UI (optional). |
24+
| `--db` | `DATABASE_URL` | | Database connection string. Only PostgreSQL is supported. |
25+
| `--cmd-prefix` | `CMD_PREFIX` | @bors | Prefix used to invoke bors commands in PR comments. |
26+
| `--web_url` | `WEB_URL` | http://localhost:8080 | Web URL where the bot's website is deployed (optional). |
27+
| `--permissions` | `PERMISSIONS` | Rust Team API URL | Either a URL to the team v1 API or a path to a directory containing JSON files with try/review permissions (optional). |
2828

2929
### Special branches
3030
The bot uses the following branch names for its operations.

docs/development.md

Lines changed: 71 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
This document should help you make sense of the codebase and provide
33
guidance on working with it and testing it locally.
44

5+
Note that since Bors is a GitHub app, it has a relatively non-trivial first-time
6+
setup that is required to test it on live repositories. You don't *need* to do that
7+
though, as we also have a comprehensive integration test suite, which should be enough
8+
to test most changes.
9+
510
Directory structure:
611
- `migrations`
7-
- `sqlx` migrations that are the source of truth for database schema
12+
- `sqlx` migrations that are the source of truth for database schema.
813
- `src/bors`
914
- Bors commands and their handlers.
1015
- `src/database`
@@ -13,7 +18,7 @@ Directory structure:
1318
- Communication with the GitHub API and definitions of GitHub webhook messages.
1419

1520
## Architecture diagram
16-
The following diagram shows a simplified view on the important state entities of Bors. `bors_process` handles events generated by webhooks. It uses a shared global state through `BorsContext`, which holds a shared connection to the database and a command parser. It also has access to a map of repository state. Each repository state contains an API client for that repository, its loaded config, and permissions loaded from the Team API.
21+
The following diagram shows a simplified view on the important state entities of Bors. `bors_process` handles events generated by webhooks. It uses a shared global state through `BorsContext`, which holds a shared connection to the database and a command parser. It also has access to a map of repository states. Each repository state contains an API client for that repository, its loaded config, and permissions loaded from the Team API.
1722

1823
```mermaid
1924
---
@@ -41,63 +46,6 @@ flowchart
4146
bors_process --> BorsContext
4247
```
4348

44-
## How to test bors on live repositories
45-
Bors has a `cargo` test suite that you can run locally, but sometimes nothing beats an actual test on live, GitHub
46-
repositories. The bot has a staging deployment at the https://github.com/rust-lang/bors-kindergarten repository,
47-
where you can try it however you want.
48-
49-
Nevertheless, sometimes it might be easier to test it on your own repository. The process is a bit involved, but it
50-
can still be done if needed.
51-
52-
One-time setup:
53-
- Create your own GitHub app.
54-
- Configure its webhook secret.
55-
- Configure its private key.
56-
- Give it permissions for `Actions` (r/w), `Checks` (r/w), `Contents` (r/w), `Issues` (r/w) and `Pull requests` (r/w).
57-
- Subscribe it to webhook events `Issue comment`, `Pull request`, `Pull request review`, `Pull request review comment` and `Workflow run`.
58-
- Install your GitHub app on some test repository where you want to test bors.
59-
- Don't forget to configure `rust-bors.toml` in the root of the repository, and also add some example CI workflows.
60-
- Create try/review permissions for Github users
61-
- Copy a review json file `cp data/permissions/bors.review.json.example data/permissions/bors.review.json`
62-
- Copy a try json file `cp data/permissions/bors.try.json.example data/permissions/bors.try.json`
63-
- Get your Github user `ID` `https://api.github.com/users/<your_github_user_name>`
64-
- Edit both `bors.review.json` and `bors.try.json` files to include your GitHub `ID`: `{ "github_ids": [12345678] }`
65-
66-
Everytime you want to run bors:
67-
- Run bors locally.
68-
- Set `APP_ID` to the ID of the app
69-
- Set `WEBHOOK_SECRET` to the webhook secret of the app.
70-
- Set `PRIVATE_KEY` to the private key of the app.
71-
- (optional) Set `WEB_URL` to the public URL of the website of the app.
72-
- (optional) Set `CMD_PREFIX` to the command prefix used to control the bot (e.g. `@bors`).
73-
- (optional) Set `PERMISSIONS` `"data/permissions"` directory path to list users with permissions to perform try/review.
74-
- Set up some globally reachable URL/IP address for your computer, e.g. using [ngrok](https://ngrok.com/).
75-
- Configure the webhook URL for your app to point to `<address>/github`. You can use [gh webhook](https://docs.github.com/en/webhooks/testing-and-troubleshooting-webhooks/using-the-github-cli-to-forward-webhooks-for-testing) for that.
76-
- Try `@bors ping` on some PR on the test repository :)
77-
78-
## Seeding
79-
For testing the merge queue, there's a `scripts/seed.py` script that can automatically create multiple PRs and approve them with `@bors r+` command.
80-
81-
### Prerequisites
82-
```console
83-
$ pip install PyGithub
84-
```
85-
86-
### Usage
87-
The script requires a GitHub personal access token with the following permissions:
88-
- **Contents** (read/write)
89-
- **Pull requests** (read/write)
90-
- **Issues** (write)
91-
92-
```console
93-
$ python scripts/seed.py --repo owner/repo-name --token $GITHUB_TOKEN --count 5
94-
```
95-
96-
### What it does
97-
1. Creates multiple branches with simple changes (new markdown files)
98-
2. Opens pull requests for each branch
99-
3. Posts `@bors r+` comments to approve each PR
100-
10149
## Database
10250
You must have `sqlx-cli` installed for the following commands to work.
10351
```console
@@ -111,8 +59,9 @@ $ docker-compose up -d
11159
```
11260

11361
Then, set the `DATABASE_URL` environment variable to the connection string of the database.
114-
The content of the variable is can be found in the `.env.example` file.
115-
If an `.env` file is present, the environment variable listed in it will be picked up automatically by `sqlx`.
62+
The connection string for the database started by the docker compose file in the repository can be found
63+
in the `.env.example` file.
64+
If an `.env` file is present, environment variables listed in it will be picked up automatically by `sqlx`.
11665

11766
```console
11867
$ export DATABASE_URL=postgres://bors:bors@localhost:5432/bors
@@ -139,20 +88,77 @@ Make sure to also run `cargo sqlx migrate run` to apply the migrations to the da
13988
$ cargo sqlx migrate run
14089
```
14190
4) Add a test data file to `tests/data/migrations/<timestamp>-<new-migration>.sql`.
142-
- The file should contain SQL that inserts some reasonable data into a test database after the migration is applied.
91+
- The file should contain SQL that inserts some reasonable data into a test database after the migration is applied.
14392
The goal is to check that we have a test database with production-like data, so that we can test that applying migrations will not produce errors on a non-empty database.
144-
- If it doesn't make sense to add any data to the migration (e.g. if the migration only adds an index), put `-- Empty to satisfy migration tests` into the file.
93+
- If it doesn't make sense to add any data to the migration (e.g. if the migration only adds an index), put `-- Empty to satisfy migration tests` into the file.
14594

14695
### Regenerate `.sqlx` directory
96+
Before you make a commit that changes SQL queries in the bors codebase, you should regenerate the stored `sqlx` metadata files in the `.sqlx` directory:
97+
14798
```console
14899
$ rm -rf .sqlx
149100
$ cargo sqlx prepare -- --all-targets
150101
$ git add .sqlx
151102
```
152103

153-
After that, you should commit the changes to the `.sqlx` directory.
104+
> Make sure to remove the `.sqlx` directory before running the `prepare` command, to ensure that leftover queries do not remain committed in the repository.
105+
106+
## How to test bors on live repositories
107+
Bors has a `cargo` test suite that you can run locally, but sometimes nothing beats an actual test on live, GitHub
108+
repositories. The bot has a staging deployment at the https://github.com/rust-lang/bors-kindergarten repository,
109+
where you can try it however you want.
110+
111+
Nevertheless, sometimes it might be easier to test it on your own repository. The process is a bit involved, but it
112+
can still be done if needed.
113+
114+
### One-time setup
115+
- Create your own [GitHub app](https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/registering-a-github-app).
116+
- Configure its webhook secret and private key and write them down.
117+
- Give it permissions for `Actions` (r/w), `Checks` (r/w), `Contents` (r/w), `Issues` (r/w) and `Pull requests` (r/w).
118+
- Subscribe it to webhook events `Issue comment`, `Pull request`, `Pull request review`, `Pull request review comment` and `Workflow run`.
119+
- Install your GitHub app on some test repository where you want to test bors.
120+
- Add `rust-bors.toml` in the root of the repository, and also add some example CI workflows.
121+
- Create try/review permissions for GitHub users
122+
- Copy a review JSON file `cp data/permissions/bors.review.json.example data/permissions/bors.review.json`
123+
- Copy a try JSON file `cp data/permissions/bors.try.json.example data/permissions/bors.try.json`
124+
- Get your GitHub user `ID` `https://api.github.com/users/<your_github_user_name>`
125+
- Edit both `bors.review.json` and `bors.try.json` files to include your GitHub `ID`: `{ "github_ids": [12345678] }`
126+
127+
### Everytime you run bors
128+
1. Start the Postgres [database](#Database)
129+
2. Run bors locally, and configure environment variables and/or command-line parameters for it:
130+
- Set `APP_ID` to the ID of the created GitHub app.
131+
- Set `WEBHOOK_SECRET` to the webhook secret of the app.
132+
- Set `PRIVATE_KEY` to the private key of the app.
133+
- (optional) Set `WEB_URL` to the public URL of the website of the app.
134+
- (optional) Set `CMD_PREFIX` to the command prefix used to control the bot (e.g. `@bors`).
135+
- (optional) Set `PERMISSIONS` `"data/permissions"` directory path to list users with permissions to perform try/review.
136+
3. Redirect webhooks from your test repository to bors. You can [gh webhook](https://docs.github.com/en/webhooks/testing-and-troubleshooting-webhooks/using-the-github-cli-to-forward-webhooks-for-testing) for that.
137+
- If you want to do it manually, you need to configure a globally reachable URL/IP address for your computer e.g. using [ngrok](https://ngrok.com/), and then configure the webhook URL of your GitHub app to point to `<your-pc-address>/github`.
138+
4. Try `@bors ping` on some PR on your test repository :)
139+
140+
## Seeding test repositories
141+
For testing the merge queue, there's a `scripts/seed.py` script that can automatically create multiple PRs on a given repository and approve them with `@bors r+` command.
142+
143+
### Prerequisites
144+
```console
145+
$ pip install PyGithub
146+
```
147+
148+
### Usage
149+
The script requires a GitHub personal access token with the following permissions:
150+
- **Contents** (read/write)
151+
- **Pull requests** (read/write)
152+
- **Issues** (write)
154153

155-
Make sure to remove the `.sqlx` directory before running the `prepare` command, to ensure that leftover queries are not do not remain committed to the repository.
154+
```console
155+
$ python scripts/seed.py --repo owner/repo-name --token $GITHUB_TOKEN --count 5
156+
```
157+
158+
### What it does
159+
1. Creates multiple branches with simple changes (new markdown files)
160+
2. Opens pull requests for each branch
161+
3. Posts `@bors r+` comments to approve each PR
156162

157163
## Updating commands
158164
When modifying commands, make sure to update both:

0 commit comments

Comments
 (0)