diff --git a/Readme.md b/Readme.md index 8bc1923..08fc323 100644 --- a/Readme.md +++ b/Readme.md @@ -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: @@ -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 @@ -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 @@ -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: diff --git a/src/main.ts b/src/main.ts index d34543e..7e032c8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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( diff --git a/src/reporters/github/success.md.j2 b/src/reporters/github/success.md.j2 index 9018fb4..b5224f7 100644 --- a/src/reporters/github/success.md.j2 +++ b/src/reporters/github/success.md.j2 @@ -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 %} diff --git a/src/reporters/reporter.ts b/src/reporters/reporter.ts index e777739..165296f 100644 --- a/src/reporters/reporter.ts +++ b/src/reporters/reporter.ts @@ -81,6 +81,7 @@ export interface ReportContext { metadata: ReportMetadata; error?: Error; comparison?: RunComparison; + comparisonBranch?: string; runUrl?: string; queryBaseUrl?: string; }