Skip to content

Commit e55ca62

Browse files
committed
Try to add initial macOS setup
1 parent 4d352c6 commit e55ca62

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

src/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { EOL } from "os";
22
import { equalVersions, getOS } from "./core";
3-
import { installSwift, setupLinux } from "./swiftly";
3+
import { installSwift, setupLinux, setupMacOS } from "./swiftly";
44
import { currentVersion } from "./swift";
55
import { error, getInput, info, setFailed, setOutput } from "@actions/core";
6-
import { coerce, eq } from "semver";
76

87
/**
98
* Main entry point for the action
@@ -24,7 +23,8 @@ async function run() {
2423
// Setup Swiftly on the runner
2524
switch (os) {
2625
case "darwin":
27-
throw Error("Not implemented yet on macOS");
26+
await setupMacOS();
27+
break;
2828
case "linux":
2929
await setupLinux({ skipVerifySignature: true });
3030
break;

src/swiftly/installers/index.ts

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

src/swiftly/installers/macos.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { downloadTool, find } from "@actions/tool-cache";
2+
import { cmd } from "../../core";
3+
import { addPath, debug } from "@actions/core";
4+
5+
export async function setupMacOS() {
6+
let path = find("swiftly", "1.0.0");
7+
8+
if (!path) {
9+
path = await download();
10+
} else {
11+
debug("Found cached Swiftly");
12+
}
13+
14+
addPath(path);
15+
16+
debug(`Added Swiftly to PATH: ${path}`);
17+
}
18+
19+
async function download() {
20+
const pkg = await downloadTool(
21+
"https://download.swift.org/swiftly/darwin/swiftly.pkg",
22+
);
23+
await cmd("installer", "-pkg", pkg, "-target", "CurrentUserHomeDirectory");
24+
return "~/.swiftly/bin/swiftly";
25+
}

0 commit comments

Comments
 (0)