Skip to content

Commit f12b1f0

Browse files
authored
fix: fall back to distribution ID when os-release has no version field (#961)
## Summary `getLinuxOSNameVersion()` throws `Failed to determine Linux distribution. Could not read /etc/os-release or /usr/lib/os-release` on distributions whose os-release is readable but contains **no version field at all** — no `VERSION_ID`, no `VERSION_CODENAME`, no `BUILD_ID`. The error message is misleading in that case, and the action fails even though the distribution is perfectly identifiable. Void Linux is such a distribution. Its os-release is: ```sh $ cat /etc/os-release NAME="Void" ID="void" PRETTY_NAME="Void Linux" HOME_URL="https://voidlinux.org/" DOCUMENTATION_URL="https://docs.voidlinux.org/" LOGO="void-logo" ANSI_COLOR="0;38;2;71;128;97" DISTRIB_ID="void" ``` Unlike Arch (fixed by #912 via `BUILD_ID`) and debian:unstable (fixed via `VERSION_CODENAME`, #773), Void ships only `ID`, so both existing fallbacks miss it. This breaks any workflow using `container: ghcr.io/void-linux/void-glibc-full` with caching enabled — e.g. SageMath's CI started failing after bumping to v8: https://github.com/sagemath/sage/actions/runs/29456228986/job/87489892141 (worked around downstream in sagemath/sage#42547 by injecting a fake `BUILD_ID` into the container's os-release). This PR adds a last-resort fallback: if `ID` is present but no version field is, return the plain `ID` (`void`), following the same reasoning as #912 — a stable cache key for a rolling release is better than crashing. Distributions with a version field are unaffected, and files without even an `ID` still raise the existing error.
1 parent ecd24dd commit f12b1f0

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

‎dist/setup/index.cjs‎

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/utils/platforms.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export function getOSNameVersion(): string {
102102

103103
function getLinuxOSNameVersion(): string {
104104
const files = ["/etc/os-release", "/usr/lib/os-release"];
105+
let idWithoutVersion: string | undefined;
105106

106107
for (const file of files) {
107108
try {
@@ -122,11 +123,22 @@ function getLinuxOSNameVersion(): string {
122123
if (id && buildId) {
123124
return `${id}-${buildId}`;
124125
}
126+
// Remember the ID but keep looking: the next file might still
127+
// provide a version field
128+
if (id && idWithoutVersion === undefined) {
129+
idWithoutVersion = id;
130+
}
125131
} catch {
126132
// Try next file
127133
}
128134
}
129135

136+
// Fallback for rolling releases (e.g. void) that have no version
137+
// field at all
138+
if (idWithoutVersion) {
139+
return idWithoutVersion;
140+
}
141+
130142
throw new Error(
131143
"Failed to determine Linux distribution. " +
132144
"Could not read /etc/os-release or /usr/lib/os-release",

0 commit comments

Comments
 (0)