Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/proud-maps-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"draupnir": patch
---

Add Distrubution information to version information in status / version command.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ version.txt.tmp
version.txt
# branch file generated from npm build
branch.txt
# distribution file generated from npm build
distribution.txt

# Logs
logs
Expand Down
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

# syntax=docker/dockerfile:1.7

# Build-time distribution identifier (default for docker builds). Declared
# before any FROM so it can be overridden with `--build-arg`.
ARG DRAUPNIR_DISTRIBUTION=Docker

FROM node:24-slim AS build-stage
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
apt-get update \
Expand All @@ -27,6 +31,10 @@ RUN --mount=type=cache,target=/root/.npm npm ci
COPY . .

# build and install
# make the build see the distribution value
ARG DRAUPNIR_DISTRIBUTION
ENV DRAUPNIR_DISTRIBUTION=${DRAUPNIR_DISTRIBUTION}

RUN npm run build \
&& npm prune --production

Expand Down
3 changes: 2 additions & 1 deletion apps/draupnir/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
"private": true,
"scripts": {
"build": "tsc --project test/tsconfig.json && npm run build:assets",
"build:assets": "npm run describe-version && npm run describe-branch",
"build:assets": "npm run describe-version && npm run describe-branch && npm run describe-distribution",
"describe-version": "(git describe > version.txt.tmp && mv version.txt.tmp version.txt) || true && rm -f version.txt.tmp",
"describe-branch": "(git rev-parse --abbrev-ref HEAD > branch.txt.tmp && mv branch.txt.tmp branch.txt) || true && rm -f branch.txt.tmp",
"describe-distribution": "echo \"${DRAUPNIR_DISTRIBUTION:-source}\" > distribution.txt.tmp && mv distribution.txt.tmp distribution.txt",

@Gnuxie Gnuxie May 10, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is a "build time" distribution?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gnuxie im confused what your refering to?

And as for what the purpose of this is. Its quite simple its to help us get information about where a draupnir comes from.

How was it built and who is to blame for the environment that builds it. For example is the bot built from source then we can start to question the build environment in ways we cant if the bot came from the official CI.

Its also useful for Nix as well Nix currently appends nix to the version string but its tbh better to have that kind of shit be a dedicated attribute.

This is also useful for the 2 or 3 native packages for Draupnir that exist in the wild. Yes OpenSUSE as far as i know has one.

We have no way of knowing the install method unless we coax that information out of the end users and this data would make it easier for us to define a workflow where the first thing we want is that data if the bot boots far enough to cough it up.

"harness-registration": "node dist/appservice/cli.js -r -u \"http://host.docker.internal:9000\" --enable-source-maps",
"test:unit": "mocha --require './test/tsnode.cjs' --forbid-only 'test/unit/**/*.{ts,tsx}'",
"test:unit:single": "mocha --require test/tsnode.cjs",
Expand Down
7 changes: 6 additions & 1 deletion apps/draupnir/src/appservice/bot/VersionCommand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import {
describeCommand,
} from "@the-draupnir-project/interface-manager";
import { AppserviceBotInterfaceAdaptor } from "./AppserviceBotInterfaceAdaptor";
import { CURRENT_BRANCH, SOFTWARE_VERSION } from "../../config";
import { CURRENT_BRANCH, SOFTWARE_VERSION, DISTRIBUTION } from "../../config";

type AppserviceVersionInfo = {
version: string;
branch: string;
distribution: string;
};

export const AppserviceVersionCommand = describeCommand({
Expand All @@ -26,6 +27,7 @@ export const AppserviceVersionCommand = describeCommand({
return Ok({
version: SOFTWARE_VERSION,
branch: CURRENT_BRANCH,
distribution: DISTRIBUTION,
});
},
});
Expand All @@ -42,6 +44,9 @@ AppserviceBotInterfaceAdaptor.describeRenderer(AppserviceVersionCommand, {
<br />
<b>Branch: </b>
<code>{result.ok.branch}</code>
<br />
<b>Distribution: </b>
<code>{result.ok.distribution}</code>
</root>
);
},
Expand Down
6 changes: 6 additions & 0 deletions apps/draupnir/src/commands/StatusCommand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
DOCUMENTATION_URL,
PACKAGE_JSON,
SOFTWARE_VERSION,
DISTRIBUTION,
} from "../config";
import {
ActionResult,
Expand Down Expand Up @@ -59,6 +60,7 @@ export type StatusInfo = {
branch: string;
repository: string;
documentationURL: string;
distribution: string;
} & DraupnirNotificationRoomsInfo &
WatchedPolicyRoomsInfo;

Expand Down Expand Up @@ -142,6 +144,7 @@ export function draupnirStatusInfo(draupnir: Draupnir): StatusInfo {
documentationURL: DOCUMENTATION_URL,
version: SOFTWARE_VERSION,
branch: CURRENT_BRANCH,
distribution: DISTRIBUTION,
repository: (PACKAGE_JSON["repository"] as string | undefined) ?? "Unknown",
...extractProtectionNotificationRooms(draupnir),
};
Expand Down Expand Up @@ -235,6 +238,9 @@ export function renderStatusInfo(info: StatusInfo): DocumentNode {
<b>Branch: </b>
<code>{info.branch}</code>
<br />
<b>Distribution: </b>
<code>{info.distribution}</code>
<br />
<b>Repository: </b>
<code>{info.repository}</code>
<br />
Expand Down
18 changes: 18 additions & 0 deletions apps/draupnir/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,24 @@ export const CURRENT_BRANCH = (() => {
return /^(.*)$/m.exec(branchFile)?.at(0) ?? defaultText;
})();

export const DISTRIBUTION = (() => {
let distributionFile;
const defaultText =
"A distribution name was either not provided when building Draupnir or could not be read.";
try {
distributionFile = fs.readFileSync(
path.join(__dirname, "../distribution.txt"),
"utf-8"
);
} catch (e) {
LogService.error("config", "Could not read Draupnir distribution", e);
distributionFile = defaultText;
}
// it's important to ignore the newline if the distribution is going to be put
// into <pre> or <code> where it will create an unnecessary newline.
return /^(.*)$/m.exec(distributionFile)?.at(0) ?? defaultText;
})();

export const DOCUMENTATION_URL =
"https://the-draupnir-project.github.io/draupnir-documentation/";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ describe("Test appservice version command", function () {
}
expect(result.ok).toHaveProperty("version");
expect(result.ok).toHaveProperty("branch");
expect(result.ok).toHaveProperty("distribution");
});
});
Loading