Skip to content

Commit 0aeef32

Browse files
committed
feat: add PR number to pretty version name; move commit hash last
Refine the pretty version name for PR preview builds: - Add `coderBox.prNumber` (the GitHub PR ID), read from CODER_BOX_PR_NUMBER and set in CI from github.event.pull_request.number. Woven into the menu label as "#46" and the file name as "-46" when present. - The installer boot-menu label now puts the PR reference first and moves the commit hash to the very end when a PR title is present: " - Coder Box Installer - PR #46: <title> (<rev>)" Non-PR builds are unchanged: " - Coder Box Installer (<rev>)". Example file name: coder-box-installer-x86_64-linux-pr-46-fix-the-thing.iso
1 parent 33a7211 commit 0aeef32

4 files changed

Lines changed: 44 additions & 20 deletions

File tree

‎.github/workflows/test.yml‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,13 @@ jobs:
138138
# Resolved per-kind plan from the `plan` job. Steps below branch on these.
139139
INSTALLER_FULL: ${{ needs.plan.outputs.installer_full }}
140140
APPLIANCE_FULL: ${{ needs.plan.outputs.appliance_full }}
141-
# PR title woven into the image's pretty version name (boot-menu label +
142-
# ISO file name) via coderBox.prTitle. Set through `env:` (not inlined into
143-
# a run script) so an arbitrary title can't break the shell, and empty for
144-
# non-PR events so tag/main builds keep their plain names.
141+
# PR title + number woven into the image's pretty version name (boot-menu
142+
# label + ISO file name) via coderBox.prTitle / coderBox.prNumber. Set
143+
# through `env:` (not inlined into a run script) so an arbitrary title
144+
# can't break the shell, and empty for non-PR events so tag/main builds
145+
# keep their plain names.
145146
CODER_BOX_PR_TITLE: ${{ github.event.pull_request.title }}
147+
CODER_BOX_PR_NUMBER: ${{ github.event.pull_request.number }}
146148
strategy:
147149
fail-fast: false
148150
matrix:
@@ -181,7 +183,7 @@ jobs:
181183
docker run --rm \
182184
-v "$PWD":/work -w /work \
183185
-v "$dist":/dist \
184-
-e INSTALLER_FULL -e APPLIANCE_FULL -e CODER_BOX_PR_TITLE \
186+
-e INSTALLER_FULL -e APPLIANCE_FULL -e CODER_BOX_PR_TITLE -e CODER_BOX_PR_NUMBER \
185187
nixos/nix:latest \
186188
sh -euc '
187189
# The Makefile builds via "nix build --impure" and needs flakes +

‎Makefile‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ FLAKE ?= .
4848
# checkout (the module then falls back to self.rev / "unknown").
4949
GIT_REV := $(shell git rev-parse HEAD 2>/dev/null)$(shell git diff-index --quiet HEAD -- 2>/dev/null || echo -dirty)
5050

51-
# Optional PR title woven into the image's pretty version name (boot-menu label
52-
# + ISO file name) via coderBox.prTitle. Not injected through the Nix expression
53-
# (an arbitrary title would need shell-escaping); instead the option reads the
54-
# CODER_BOX_PR_TITLE environment variable under `--impure` (which box_cfg already
55-
# uses). CI sets it for PR builds; locally you can preview with e.g.
56-
# CODER_BOX_PR_TITLE="fix the thing" make installer/iso
57-
# Unset → plain names (the option defaults to "").
51+
# Optional PR title + number woven into the image's pretty version name
52+
# (boot-menu label + ISO file name) via coderBox.prTitle / coderBox.prNumber.
53+
# Not injected through the Nix expression (an arbitrary title would need
54+
# shell-escaping); instead the options read the CODER_BOX_PR_TITLE /
55+
# CODER_BOX_PR_NUMBER environment variables under `--impure` (which box_cfg
56+
# already uses). CI sets them for PR builds; locally you can preview with e.g.
57+
# CODER_BOX_PR_TITLE="fix the thing" CODER_BOX_PR_NUMBER=46 make installer/iso
58+
# Unset → plain names (the options default to "").
5859

5960
# Normalize an arch token to a *-linux triple: $(call norm_arch,aarch64) -> aarch64-linux
6061
norm_arch = $(if $(filter %-linux,$(1)),$(1),$(1)-linux)

‎nixos/_images/box-turnkey.nix‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ let
4343
in lib.removeSuffix "-" (lib.removePrefix "-" capped);
4444

4545
prSlug = slugify prTitle;
46+
47+
# PR number (the GitHub PR "ID"). CI injects it alongside the title; included
48+
# in both the menu label ("#46") and the file name ("-46") when present so an
49+
# image can be traced straight back to its PR. Empty for non-PR builds.
50+
prNumber = config.coderBox.prNumber;
51+
prNumMenu = lib.optionalString (prNumber != "") " #${prNumber}";
52+
prNumFile = lib.optionalString (prNumber != "") "-${prNumber}";
4653
in
4754
{
4855
imports = [
@@ -82,22 +89,31 @@ in
8289
description = "Pull-request title this image was built for, woven into the pretty version name (boot-menu label + ISO file name) when non-empty.";
8390
};
8491

92+
# PR number (GitHub PR "ID") for a pull-request preview build. CI sets it via
93+
# CODER_BOX_PR_NUMBER (read under `--impure` like prTitle); empty otherwise.
94+
options.coderBox.prNumber = lib.mkOption {
95+
type = lib.types.str;
96+
default = builtins.getEnv "CODER_BOX_PR_NUMBER";
97+
description = "Pull-request number (ID) this image was built for, woven into the pretty version name when non-empty.";
98+
};
99+
85100
# Derived, read-only fragments so every image flavour appends the PR identity
86101
# the same way. coderBox.prMenuSuffix goes on the boot-menu label;
87-
# coderBox.prFileSuffix goes on the ISO file name. Both are empty when there's
88-
# no PR title, so they're safe to interpolate unconditionally.
102+
# coderBox.prFileSuffix goes on the ISO file name. Both carry the PR number
103+
# ("#46" / "-46") when known, and are empty when there's no PR title, so
104+
# they're safe to interpolate unconditionally.
89105
options.coderBox.prMenuSuffix = lib.mkOption {
90106
type = lib.types.str;
91107
internal = true;
92108
readOnly = true;
93-
default = lib.optionalString (prTitle != "") " - PR: ${menuTitle}";
109+
default = lib.optionalString (prTitle != "") " - PR${prNumMenu}: ${menuTitle}";
94110
description = "Boot-menu label fragment naming the PR this image was built for (empty for non-PR builds).";
95111
};
96112
options.coderBox.prFileSuffix = lib.mkOption {
97113
type = lib.types.str;
98114
internal = true;
99115
readOnly = true;
100-
default = lib.optionalString (prSlug != "") "-pr-${prSlug}";
116+
default = lib.optionalString (prSlug != "") "-pr${prNumFile}-${prSlug}";
101117
description = "ISO file-name fragment naming the PR this image was built for (empty for non-PR builds).";
102118
};
103119

‎nixos/_images/installer/iso.nix‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,15 @@ in
6868
isoImage.volumeID = "CODER_BOX_INSTALLER";
6969
# Boot-menu label (BIOS/isolinux + EFI/grub). See ../appliance/iso.nix for
7070
# the format; leading space is required. Include the short build revision so
71-
# the boot menu shows exactly which image you're booting. The PR-title
72-
# suffix (coderBox.prMenuSuffix, set in box-turnkey.nix) is empty unless this
73-
# is a PR preview build.
74-
isoImage.appendToMenuLabel = " - Coder Box Installer (${boxRevShort})${config.coderBox.prMenuSuffix}";
71+
# the boot menu shows exactly which image you're booting. For a PR preview
72+
# build (coderBox.prMenuSuffix non-empty) the PR reference comes first and
73+
# the commit hash moves to the very end, so the label reads
74+
# " - Coder Box Installer - PR #46: <title> (<rev>)"; otherwise it's just
75+
# " - Coder Box Installer (<rev>)".
76+
isoImage.appendToMenuLabel =
77+
if config.coderBox.prMenuSuffix != ""
78+
then " - Coder Box Installer${config.coderBox.prMenuSuffix} (${boxRevShort})"
79+
else " - Coder Box Installer (${boxRevShort})";
7580

7681
# Record the full build revision for install.sh to print (the baked repo
7782
# under /etc/nixos-repo has no .git, so the script can't get it from git).

0 commit comments

Comments
 (0)