Skip to content

feat: expose the running build's commit at GET /version - #1639

Merged
BenjaminMichaelis merged 2 commits into
mainfrom
feat/expose-build-commit
Nov 15, 2026
Merged

BenjaminMichaelis merged 2 commits into
mainfrom
feat/expose-build-commit

Conversation

@BenjaminMichaelis

Copy link
Copy Markdown
Member

Why

This is groundwork for post-deploy smoke tests that will gate production. az containerapp update returns about 45 s before traffic shifts to the new revision, so a smoke test that starts right away would test the old build. Today the site can't say which commit it is running. .git is excluded from the Docker build context, and nothing passes the SHA in.

What

  • Dockerfile: a new SOURCE_REVISION build arg is passed to dotnet build as -p:SourceRevisionId, so AssemblyInformationalVersion becomes 1.0.0+<sha>.
    • The ARG is declared after COPY . ., so restore layers stay cached. Every RUN after an ARG implicitly uses it.
    • A comment notes that publish must stay before the EF bundle step, which rebuilds without the property.
  • Workflow: passes SOURCE_REVISION=${{ github.sha }} to both image builds. deploy-production imports the same image from dev ACR, so prod reports the same commit.
  • GET/HEAD /version returns { "version": "1.0.0+<sha>", "commit": "<sha>" }.
    • It sends Cache-Control: no-store, is not rate limited, and is excluded from tracing like /health and /alive.
    • It is not shown anywhere in the site UI.
    • The SHA is already public through the repo and the deployed/prod/<sha> tags.
  • For local builds, SourceLink already stamps the HEAD SHA, so /version works under dotnet run and Aspire too.

Tests

VersionEndpointTests:

  • Response shape and no-store.
  • HEAD returns 200.
  • 40 consecutive requests, above the 30/min global limit, all return 200.
  • BuildInfo parsing cases.
  • A CI-only check (GITHUB_ACTIONS=true) that the build is stamped with GITHUB_SHA. I simulated it locally: it passes with HEAD and fails with a wrong SHA.

All 202 Web tests pass locally.

I did not run a real docker build locally. Building with -p:SourceRevisionId=deadbeefcafe produced 1.0.0+deadbeefcafe. The container-validation job builds the image, and the upcoming dev smoke step will assert that /version's commit equals github.sha.

Post-deploy smoke tests need to confirm the new revision is serving traffic
before testing it (az containerapp update returns before traffic shifts).
.git is excluded from the Docker build context, so the image could not know
which commit it was built from.

- Dockerfile: SOURCE_REVISION build arg -> -p:SourceRevisionId, so
  AssemblyInformationalVersion becomes 1.0.0+<sha>. Declared after COPY . .
  so restore layers stay cached.
- Workflow: pass SOURCE_REVISION=${{ github.sha }} to both image builds
  (production imports the same image, so it reports the same commit).
- GET/HEAD /version returns {version, commit}: no-store, not rate limited,
  excluded from tracing like /health and /alive. Not shown in the site UI.
Use HasJsonContent, IsValidJsonObject and JsonElement IsDeepEqualTo so a
renamed or extra field in the /version payload fails the test.
@BenjaminMichaelis
BenjaminMichaelis merged commit b33e90b into main Nov 15, 2026
13 checks passed
@BenjaminMichaelis
BenjaminMichaelis deleted the feat/expose-build-commit branch November 15, 2026 04:10
BenjaminMichaelis added a commit that referenced this pull request Nov 15, 2026
## Why

Production is currently promoted as soon as `deploy-development`
finishes, even if dev is broken. `az containerapp update` also returns
about 45 s **before** traffic shifts to the new revision. Builds on
#1639 (`GET /version`).

## What

New steps at the end of `deploy-development`:

1. **Wait for the new revision.** `scripts/wait-for-deployed-commit.sh`
polls `https://dev.essentialcsharp.com/version` until it reports
`github.sha` 3 times in a row (10-minute timeout). The URL can be
overridden with `vars.SITE_BASE_URL`. On timeout it prints `az
containerapp revision list`.
2. **Smoke test.** `dotnet test` runs the new
`EssentialCSharp.Web.E2ETests` project filtered to
`[Category=Deployed]`. TRX results are uploaded on failure.

The steps run **inside** `deploy-development`, not in a separate job, so
they hold its concurrency group, and the next push can't swap the dev
image mid-test. `deploy-production` already `needs` this job, so a
failed smoke run blocks promotion. Dev keeps the failed build until the
next push; there is no automatic rollback.

### Checks (anonymous, read-only apart from one form post per provider)

| Check | Catches |
|---|---|
| `/health`, `/alive` return 200 | App is up |
| `/version` commit equals `github.sha` | Testing the right build |
| `/home` renders, and its canonical link uses the deployed origin |
`SiteSettings:BaseUrl` misconfiguration |
| Sitemap has more than 100 pages, all on the deployed host, and a
chapter page renders | Image built without book content, broken content
routing |
| Login page has the hCaptcha site key and GitHub/Microsoft buttons |
Captcha or external login config missing (captcha fails closed) |
| `POST /Identity/Account/ExternalLogin` for GitHub and Microsoft
returns 302 to the provider's authorize endpoint with `client_id` and
`redirect_uri=<site>/signin-<provider>` | Provider registration, client
id, callback/forwarded-headers config |

The full OAuth round trip, secrets and consent are out of scope.
Logged-in flows (login and AI chat) will follow separately. They need a
dev test account and a captcha decision first.

### Safety and robustness
- Tests **skip** unless `E2E_BASE_URL` or `E2E_EXPECTED_COMMIT` is set,
so the normal 3-OS PR test run is unaffected. If either is set, the
tests always run, so a malformed URL fails the gate instead of skipping
everything and passing.
- Each request is retried once on 429, 5xx, a connection error or a
timeout.
- Each run makes about 13 requests. Only 2 count against the content
limiter (20/hour per IP for anonymous users). `/health`, `/alive` and
`/version` are exempt.

## Verification
- Ran the deployed tests against real dev before #1639 deployed: 7/8
passed. `/version` returned 302 because that build predates it, which is
expected. After this merges, the deploy will include `/version`.
- Exercised the wait script locally against a fake `/version` for
success, wrong-commit timeout, unreachable host (the curl error is
shown) and missing `jq`.
- Unset variables give 8 skipped tests. A malformed `E2E_BASE_URL` makes
all 8 fail with a clear message.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant