Skip to content

Tie the version to the PR number and stop hardcoding it - #40

Merged
barkz merged 1 commit into
mainfrom
chore/version-tracks-pr-number
Sep 28, 2026
Merged

barkz merged 1 commit into
mainfrom
chore/version-tracks-pr-number

Conversation

@barkz

@barkz barkz commented Sep 28, 2026

Copy link
Copy Markdown
Owner

What

__version__ has been 0.1.0 since the initial commit — unchanged through 38 merged PRs — so it described nothing. This sets it to 0.2.<PR>, where the patch component is the number of the PR that introduced the change.

0.2.40 for this one.

Why this shape

A build now maps to exactly one PR and its diff, which is the traceability a date-grouped changelog was standing in for. It also sidesteps the judgment call about 1.0: the 0.2 series makes no stability promise while the VS Code extension and IDE work churn the client API.

How it cannot rot

A PR number does not exist until the PR is open, so the bump happens inside the PR:

python3 tools/set_version.py        # infers the number from gh
python3 tools/set_version.py 41     # or explicitly

A new version job in release.yml fails the PR when __version__ and the PR number disagree. That job is the thing the old constant lacked.

The damage hardcoding already did

client.py carried "glean-code/0.1" in two places and auth/oauth.py in a third — every one stale from the moment the version moved, and every request has been sending them for 38 PRs. They now derive from __version__ through a single client.USER_AGENT, and the /doctor probe reports the version too.

A test asserts that no string in glean_code/ hardcodes a version. It reads string tokens via tokenize rather than raw lines, so prose in a comment mentioning an old value doesn't trip it — which it did on my first attempt, flagging the comment that explains the very problem.

Tests

1,173 → 1,177. Verified the guard still fails when a hardcoded UA is reintroduced.

🤖 Generated with Claude Code

__version__ had been "0.1.0" since the initial commit — unchanged through 38
merged PRs — so it described nothing. It is now 0.2.<PR>, where the patch
component is the number of the pull request that introduced the change, making
any build traceable to one PR and its diff.

Because a PR number does not exist until the PR is opened, the bump happens
inside the PR via tools/set_version.py (which can infer the number from gh), and
a new `version` job in release.yml fails the PR when __version__ and the PR
number disagree. That job is what stops the scheme rotting the way the old
constant did.

The User-Agent strings were the real damage from hardcoding: client.py carried
"glean-code/0.1" in two places and auth/oauth.py in a third, all stale from the
moment the version moved. They now derive from __version__ through a single
client.USER_AGENT, and the doctor probe reports the version too.

A test asserts no string anywhere in glean_code/ hardcodes a version. It reads
string tokens via tokenize rather than raw lines, so prose in a comment that
mentions an old value does not trip it — which it did on the first attempt,
flagging the comment explaining the very problem.

Tests: 1,173 -> 1,177.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@barkz
barkz merged commit 5285846 into main Sep 28, 2026
8 checks passed
@barkz
barkz deleted the chore/version-tracks-pr-number branch September 28, 2026 02:22
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