Skip to content

Commit 68b7ab6

Browse files
Add support for installing maintenance version (#30)
1 parent 73c788d commit 68b7ab6

File tree

4 files changed

+46
-22
lines changed

4 files changed

+46
-22
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
- {shards: '0.14', crystal: '1.3'}
2424
- {shards: latest, crystal: latest}
2525
- {shards: nightly, crystal: nightly}
26+
- {crystal: 'branch:master'}
2627
exclude:
2728
- os: windows-latest
2829
config: {shards: '0.12.0', crystal: '0.35.1'}
@@ -55,7 +56,7 @@ jobs:
5556
- run: |
5657
v='${{ matrix.config.crystal }}'
5758
crystal --version | grep -E "${v}\\b"
58-
if: ${{ contains(matrix.config.crystal, '.') }}
59+
if: ${{ contains(matrix.config.crystal, '.') && !contains(matrix.config.crystal, 'branch:') }}
5960
- run: |
6061
crystal spec .github/test/crystal-libs_spec.cr
6162
- run: |

.github/workflows/release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
- {shards: '0.14', crystal: '1.3'}
2424
- {shards: latest, crystal: latest}
2525
- {shards: nightly, crystal: nightly}
26+
- {crystal: 'branch:master'}
2627
exclude:
2728
- os: windows-latest
2829
config: {shards: '0.12.0', crystal: '0.35.1'}
@@ -55,7 +56,7 @@ jobs:
5556
- run: |
5657
v='${{ matrix.config.crystal }}'
5758
crystal --version | grep -E "${v}\\b"
58-
if: ${{ contains(matrix.config.crystal, '.') }}
59+
if: ${{ contains(matrix.config.crystal, '.') && !contains(matrix.config.crystal, 'branch:') }}
5960
- run: |
6061
crystal spec .github/test/crystal-libs_spec.cr
6162
- run: |

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ Alternatively, you can use the container-based approach [as in the starter workf
6868

6969
Install Crystal from the latest continuous build on [crystal.git][] master.
7070

71+
* **`crystal: "branch:foo/bar"`**
72+
73+
Install Crystal from the latest maintenance build on [crystal.git][] branch specified after `branch:`.
74+
7175
* * **`shards: true`** (default)
7276

7377
Ensure that *some* released version of [Shards][] is available.

index.js

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async function run() {
3333
params.shards = "nightly";
3434
}
3535
params.path = Core.getInput("destination") || Path.join(
36-
process.env["RUNNER_TEMP"], `crystal-${params.crystal}-${params.shards}-${params.arch}`,
36+
process.env["RUNNER_TEMP"], `crystal-${params.crystal.replace("branch:", "")}-${params.shards}-${params.arch}`,
3737
);
3838
Core.setOutput("path", params.path);
3939

@@ -87,17 +87,22 @@ const Nightly = "nightly";
8787
const Any = "true";
8888
const None = "false";
8989
const NumericVersion = /^\d([.\d]*\d)?$/;
90+
const BranchVersion = /^branch:(.+)$/;
9091

9192
function checkVersion(version, allowed, earliestAllowed = null) {
9293
const numericVersion = NumericVersion.test(version) && version;
9394
if (numericVersion && (!earliestAllowed || cmpTags(numericVersion, earliestAllowed) >= 0)) {
9495
allowed[allowed.indexOf(NumericVersion)] = numericVersion;
9596
}
97+
const branchVersion = BranchVersion.test(version) && version;
98+
if (branchVersion) {
99+
allowed[allowed.indexOf(BranchVersion)] = branchVersion;
100+
}
96101

97102
if (allowed.includes(version)) {
98103
return version;
99104
}
100-
if ([Latest, Nightly, numericVersion].includes(version)) {
105+
if ([Latest, Nightly, numericVersion, branchVersion].includes(version)) {
101106
throw `Version "${version}" is not supported on ${getPlatform()}`;
102107
}
103108
throw `Version "${version}" is invalid`;
@@ -116,7 +121,7 @@ async function subprocess(command, options) {
116121
}
117122

118123
async function installCrystalForLinux({crystal, shards, arch = getArch(), path}) {
119-
checkVersion(crystal, [Latest, Nightly, NumericVersion]);
124+
checkVersion(crystal, [Latest, Nightly, NumericVersion, BranchVersion]);
120125
const filePatterns = {"x86_64": /-linux-x86_64\.tar\.gz$/, "x86": /-linux-i686\.tar\.gz$/};
121126
checkArch(arch, Object.keys(filePatterns));
122127

@@ -141,7 +146,7 @@ async function installCrystalForLinux({crystal, shards, arch = getArch(), path})
141146
}
142147

143148
async function installCrystalForMac({crystal, shards, arch = "x86_64", path}) {
144-
checkVersion(crystal, [Latest, Nightly, NumericVersion]);
149+
checkVersion(crystal, [Latest, Nightly, NumericVersion, BranchVersion]);
145150
if (crystal === Latest || crystal === Nightly || cmpTags(crystal, "1.2") >= 0) {
146151
checkArch(arch, ["universal", "x86_64", "aarch64"]);
147152
} else {
@@ -186,12 +191,17 @@ async function installAptPackages(packages) {
186191

187192
async function installBinaryRelease({crystal, filePattern, path}) {
188193
if (crystal === Nightly) {
189-
await IO.mv(await downloadCrystalNightly(filePattern), path);
194+
await IO.mv(await downloadCrystalNightly(filePattern, "master"), path);
190195
} else {
191-
if (crystal === Latest) {
192-
crystal = null;
196+
const version = BranchVersion.exec(crystal);
197+
if (version) {
198+
await IO.mv(await downloadCrystalNightly(filePattern, version[1]), path);
199+
} else {
200+
if (crystal === Latest) {
201+
crystal = null;
202+
}
203+
await IO.mv(await downloadCrystalRelease(filePattern, crystal), path);
193204
}
194-
await IO.mv(await downloadCrystalRelease(filePattern, crystal), path);
195205
}
196206
}
197207

@@ -373,21 +383,21 @@ async function downloadSource({name, repo, ref}) {
373383
return onlySubdir(await ToolCache.extractZip(downloadedPath));
374384
}
375385

376-
async function downloadCrystalNightly(filePattern) {
377-
Core.info("Looking for latest Crystal build");
386+
async function downloadCrystalNightly(filePattern, branch) {
387+
Core.info(`Looking for latest Crystal build of branch '${branch}'`);
378388

379389
let build;
380390
for (let offset = 0; ;) {
381-
const req = `/tree/master?filter=successful&shallow=true&limit=100&offset=${offset}`;
391+
const req = `/tree/${branch}?filter=successful&shallow=true&limit=100&offset=${offset}`;
382392
const resp = await fetch(CircleApiBase + req);
383393
const builds = await resp.json();
384394
build = builds.find((b) => b["workflows"]["job_name"] === "dist_artifacts");
385395
if (build) {
386396
break;
387397
}
388398
offset += builds.length;
389-
if (offset >= 1000) {
390-
throw "Could not find a matching nightly build";
399+
if (offset >= 1000 || builds.length === 0) {
400+
throw `Could not find a matching build for branch '${branch}'`;
391401
}
392402
}
393403
Core.info(`Found Crystal build ${build["build_url"]}`);
@@ -397,6 +407,9 @@ async function downloadCrystalNightly(filePattern) {
397407
const resp = await fetch(CircleApiBase + req);
398408
const artifacts = await resp.json();
399409
const artifact = artifacts.find((a) => filePattern.test(a["path"]));
410+
if (artifact === undefined) {
411+
throw `Could not find build artifacts for build ${build["build_num"]}`;
412+
}
400413

401414
Core.info(`Downloading Crystal build from ${artifact["url"]}`);
402415
const downloadedPath = await ToolCache.downloadTool(artifact["url"]);
@@ -406,14 +419,19 @@ async function downloadCrystalNightly(filePattern) {
406419
}
407420

408421
async function installCrystalForWindows({crystal, shards, arch = "x86_64", path}) {
409-
checkVersion(crystal, [Latest, Nightly, NumericVersion], "1.3");
422+
checkVersion(crystal, [Latest, Nightly, NumericVersion, BranchVersion], "1.3");
410423
checkArch(arch, ["x86_64"]);
411424

412425
if (crystal === Nightly) {
413-
await IO.mv(await downloadCrystalNightlyForWindows(), path);
426+
await IO.mv(await downloadCrystalNightlyForWindows("master"), path);
414427
} else {
415-
const filePattern = /-windows-x86_64-msvc(-unsupported)?\.zip$/;
416-
await installBinaryRelease({crystal, shards, filePattern, path});
428+
const version = BranchVersion.exec(crystal);
429+
if (version) {
430+
await IO.mv(await downloadCrystalNightlyForWindows(version[1]), path);
431+
} else {
432+
const filePattern = /-windows-x86_64-msvc(-unsupported)?\.zip$/;
433+
await installBinaryRelease({crystal, shards, filePattern, path});
434+
}
417435
}
418436

419437
Core.info("Setting up environment for Crystal");
@@ -425,11 +443,11 @@ async function installCrystalForWindows({crystal, shards, arch = "x86_64", path}
425443
}
426444
}
427445

428-
async function downloadCrystalNightlyForWindows() {
429-
Core.info("Looking for latest Crystal build");
446+
async function downloadCrystalNightlyForWindows(branch) {
447+
Core.info(`Looking for latest Crystal build of branch '${branch}'`);
430448

431449
const runsResp = await github.rest.actions.listWorkflowRuns({
432-
...RepoCrystal, "workflow_id": "win.yml", "branch": "master",
450+
...RepoCrystal, "workflow_id": "win.yml", "branch": branch,
433451
"event": "push", "status": "success", "per_page": 1,
434452
});
435453
const [workflowRun] = runsResp.data["workflow_runs"];

0 commit comments

Comments
 (0)