Skip to content

Commit 153c8d5

Browse files
authored
Support using minimum_zig_version from build.zig.zon
This is a breaking change since `version` being empty now has a different meaning from before. Resolves: #16
1 parent 82c18a2 commit 153c8d5

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ This will automatically download Zig and install it to `PATH`.
2020
You can use `version` to set a Zig version to download. This may be a release (`0.13.0`), a specific nightly
2121
build (`0.14.0-dev.2+0884a4341`), the string `master` for the latest nightly build, or the string `latest`
2222
for the latest full release. It can also refer to a [Mach nominated version][mach-nominated], such as
23-
`2024.5.0-mach`. The default is `latest`.
23+
`2024.5.0-mach`. Finally, leaving the value empty (the default) will cause the action to attempt to resolve
24+
the Zig version from the `minimum_zig_version` field in `build.zig.zon`, falling back to `latest` if that
25+
isn't possible.
2426

2527
```yaml
2628
- uses: mlugg/setup-zig@v1

action.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ name: 'Setup Zig Compiler'
22
description: 'Download and install the Zig compiler, and cache the global Zig cache'
33
inputs:
44
version:
5-
description: 'Version of the Zig compiler, e.g. "0.13.0" or "0.13.0-dev.351+64ef45eb0". "master" uses the latest nightly build. "latest" uses the latest tagged release.'
6-
required: true
7-
default: 'latest'
5+
description: 'Version of the Zig compiler, e.g. "0.13.0" or "0.13.0-dev.351+64ef45eb0". "master" uses the latest nightly build. "latest" uses the latest tagged release. Leave empty to use minimum_zig_version from build.zig.zon, with a fallback to "latest".'
6+
default: ''
87
mirror:
98
description: 'Override of Zig download mirror to use, e.g. "https://pkg.machengine.org/zig".'
109
required: false

common.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const os = require('os');
2+
const fs = require('fs');
23
const path = require('path');
34
const core = require('@actions/core');
45
const github = require('@actions/github');
@@ -8,13 +9,33 @@ const VERSIONS_JSON = 'https://ziglang.org/download/index.json';
89
const MACH_VERSIONS_JSON = 'https://pkg.machengine.org/zig/index.json';
910
const CACHE_PREFIX = "setup-zig-global-cache-";
1011

12+
const MINIMUM_ZIG_VERSION_REGEX = /\.\s*minimum_zig_version\s*=\s*"(.*?)"/;
13+
1114
let _cached_version = null;
1215
async function getVersion() {
1316
if (_cached_version != null) {
1417
return _cached_version;
1518
}
1619

17-
const raw = core.getInput('version');
20+
let raw = core.getInput('version');
21+
if (raw === '') {
22+
try {
23+
const zon = await fs.promises.readFile('build.zig.zon', 'utf8');
24+
const match = MINIMUM_ZIG_VERSION_REGEX.exec(zon);
25+
26+
if (match !== null) {
27+
_cached_version = match[1];
28+
return _cached_version;
29+
}
30+
31+
core.info('Failed to find minimum_zig_version in build.zig.zon (using latest)');
32+
} catch (e) {
33+
core.info(`Failed to read build.zig.zon (using latest): ${e}`);
34+
}
35+
36+
raw = 'latest';
37+
}
38+
1839
if (raw === 'master') {
1940
const resp = await fetch(VERSIONS_JSON);
2041
const versions = await resp.json();

0 commit comments

Comments
 (0)