Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,17 @@ causes network problems because it seems `--network=host` is also not supported
in dind (docker-in-docker). So we instead copy an explicit setup to the existing
postgres, which boots up 10x faster than docker anyway.

1. Copy the setup script
1. Set up the workflow trigger. Include both `pull_request` (for PR analysis) and
`push` to your main branch (to establish a baseline for comparison).

```yaml
on:
pull_request:
push:
branches: [main]
```

2. Copy the setup script

```yaml
jobs:
Expand Down Expand Up @@ -111,7 +121,7 @@ you can change `sudo -u postgres createuser -s -d -r -w me` to create a new user
with a name of your choosing and `sudo -u postgres createdb testing` to create a
db with a different name.

2. Run your migrations and seed scripts. This is just an example showing that
3. Run your migrations and seed scripts. This is just an example showing that
the migrations should target the postgres instance that was set up with the
previous command

Expand All @@ -127,9 +137,9 @@ jobs:
POSTGRES_URL: postgres://me@localhost/testing
```

3. Run your test suite against the same database. You can do this with any tool
4. Run your test suite against the same database. You can do this with any tool
and use any query builder or ORM you like.
4. Run the analyzer. `GITHUB_TOKEN` is needed to post a comment to your PR
5. Run the analyzer. `GITHUB_TOKEN` is needed to post a comment to your PR
reviewing the indexes found in your database. `SITE_API_ENDPOINT` is the
Query Doctor API endpoint used to fetch per-repo configuration.
```yaml
Expand All @@ -154,7 +164,7 @@ jobs:
POSTGRES_URL: postgres://me@localhost/testing
```

5. Add `pull-request: write` permissions to your job to allow
6. Add `pull-request: write` permissions to your job to allow

```yaml
jobs:
Expand Down
9 changes: 9 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ async function runInCI(
comparisonBranch,
runId ?? undefined,
);
reportContext.comparisonBranch = comparisonBranch;
if (!previousRun) {
log.info(
"main",
`No baseline found on branch "${comparisonBranch}". Comparison will be skipped. ` +
`To establish a baseline, run the analyzer on pushes to "${comparisonBranch}" ` +
`(add "push: branches: [${comparisonBranch}]" to your workflow trigger).`,
);
}
}
if (previousRun) {
reportContext.comparison = compareRuns(
Expand Down
4 changes: 3 additions & 1 deletion src/reporters/github/success.md.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
{{ queryStats.total | default('?') }} queries analyzed
{%- if newQueryCount > 0 %} | {{ newQueryCount }} new quer{{ "ies" if newQueryCount != 1 else "y" }}{% endif %}
{% else %}
{{ queryStats.total | default('?') }} queries analyzed — no previous run to compare against.
{{ queryStats.total | default('?') }} queries analyzed — no baseline found to compare against.

> **No baseline on `{{ comparisonBranch }}`** — the analyzer cannot detect regressions without a previous run. To establish a baseline, add a `push` trigger for your comparison branch so the analyzer runs on merges to `{{ comparisonBranch }}`. See the [CI integration guide](https://docs.querydoctor.com/guides/ci-integration/#workflow-trigger) for setup instructions.
{% endif %}

{% if displayImproved.length > 0 %}
Expand Down
1 change: 1 addition & 0 deletions src/reporters/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export interface ReportContext {
metadata: ReportMetadata;
error?: Error;
comparison?: RunComparison;
comparisonBranch?: string;
runUrl?: string;
queryBaseUrl?: string;
}
Expand Down
Loading