Skip to content

Commit 9137113

Browse files
committed
First stab at a setup that uses Swiftly
1 parent a63db63 commit 9137113

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

src/swiftly/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./swiftly";
2+
export * from "./install-linux";

src/swiftly/install-linux.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { addPath, debug, info } from "@actions/core";
2+
import { downloadTool, find, extractTar, cacheDir } from "@actions/tool-cache";
3+
import { verify } from "../core/gpg";
4+
5+
/**
6+
* Setup Swiftly on Linux
7+
*/
8+
export async function setupLinux() {
9+
let path = find("swiftly", "1.0.0");
10+
11+
if (!path) {
12+
path = await download();
13+
} else {
14+
debug("Found cached Swiftly");
15+
}
16+
17+
addPath(path);
18+
}
19+
20+
async function download() {
21+
info("Downloading Swiftly");
22+
23+
const arch = process.arch;
24+
const url = `https://download.swift.org/swiftly/linux/swiftly-1.0.0-${arch}.tar.gz`;
25+
26+
debug(`Downloading Swiftly from ${url}`);
27+
28+
const [pkg, signature] = await Promise.all([
29+
downloadTool(url),
30+
downloadTool(`${url}.sig`),
31+
]);
32+
33+
await verify(signature, pkg);
34+
35+
const extracted = await extractTar(pkg);
36+
debug(`Extracted Swiftly to ${extracted}`);
37+
38+
const cached = await cacheDir(extracted, "swiftly", "1.0.0");
39+
debug(`Cached Swiftly to ${cached}`);
40+
41+
return cached;
42+
}

src/swiftly/swiftly.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { info } from "@actions/core";
2+
import { cmd } from "../core";
3+
4+
async function swiftly(...args: string[]) {
5+
return await cmd("swiftly", args);
6+
}
7+
8+
/**
9+
* Install Swift using Swiftly
10+
* @param version Version to install
11+
*/
12+
export async function installSwift(version: string) {
13+
info("Initializing Swiftly");
14+
await swiftly("init", "--skip-install", "--quiet-shell-followup");
15+
16+
info(`Installing Swift ${version}`);
17+
await swiftly("install", "--use", version, "--quiet-shell-followup");
18+
}

0 commit comments

Comments
 (0)