Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
swift: ["5.6.1"]
include:
- os: windows-latest
swift: "5.3"
steps:
- uses: actions/checkout@v3
- run: npm install
Expand Down
7 changes: 7 additions & 0 deletions __tests__/os.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ describe("os resolver", () => {
expect(mac.os).toBe(os.OS.MacOS);
expect(mac.version).toBe("latest");
expect(mac.name).toBe("macOS");

setSystem({ os: "win32", dist: "Windows", release: "latest" });

let windows = await os.getSystem();
expect(windows.os).toBe(os.OS.Windows);
expect(windows.version).toBe("latest");
expect(windows.name).toBe("Windows");
});

it("throws an error if the os is not supported", async () => {
Expand Down
10 changes: 9 additions & 1 deletion __tests__/swift-versions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as versions from "../src/swift-versions";

const macOS: System = { os: OS.MacOS, version: "latest", name: "macOS" };
const ubuntu: System = { os: OS.Ubuntu, version: "latest", name: "Ubuntu" };
const windows: System = { os: OS.Windows, version: "latest", name: "Windows" };

describe("swift version resolver", () => {
it("identifies X.X.X versions", async () => {
Expand Down Expand Up @@ -39,12 +40,19 @@ describe("swift version resolver", () => {
});

it("throws an error if the version isn't available for the system", async () => {
expect.assertions(1);
expect.assertions(2);

try {
await versions.verify("5.0.3", macOS);
} catch (e) {
expect(e).toEqual(new Error('Version "5.0.3" is not available'));
}

try {
await versions.verify("5.2", windows);
} catch (e) {
expect(e).toEqual(new Error('Version "5.2" is not available'));
}
});

it("throws an error if version is invalid", async () => {
Expand Down
91 changes: 91 additions & 0 deletions __tests__/visual-studio.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import os from "os";
import * as path from "path";
import * as vs from "../src/visual-studio";
import { swiftPackage } from "../src/swift-versions";
import { OS, System } from "../src/os";

jest.mock("fs", () => {
const original = jest.requireActual("fs");
return {
...original,
existsSync: jest.fn((path) => true),
};
});

const windows: System = { os: OS.Windows, version: "latest", name: "Windows" };

describe("visual studio resolver", () => {
const env = process.env;

beforeEach(() => {
jest.resetModules();
process.env = { ...env };
});

afterEach(() => {
process.env = env;
});

it("fetches visual studio requirement for swift version", async () => {
jest.spyOn(os, "release").mockReturnValue("10.0.17763");

const req5_3 = vs.vsRequirement(swiftPackage("5.3", windows));
expect(req5_3.version).toBe("16");
expect(req5_3.components).toContain(
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64"
);
expect(req5_3.components).toContain(
"Microsoft.VisualStudio.Component.Windows10SDK.17763"
);

const req5_6 = vs.vsRequirement(swiftPackage("5.6", windows));
expect(req5_6.version).toBe("16");
expect(req5_6.components).toContain(
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64"
);
expect(req5_6.components).toContain(
"Microsoft.VisualStudio.Component.Windows10SDK.17763"
);
});

it("adds latest sdk for release newer than or equal to build 17763", async () => {
jest.spyOn(os, "release").mockReturnValue("10.0.17763");
const req17763 = vs.vsRequirement(swiftPackage("5.3", windows));
expect(req17763.components).toContain(
"Microsoft.VisualStudio.Component.Windows10SDK.17763"
);

jest.spyOn(os, "release").mockReturnValue("10.0.18363");
const req18363 = vs.vsRequirement(swiftPackage("5.3", windows));
expect(req18363.components).toContain(
"Microsoft.VisualStudio.Component.Windows10SDK.18363"
);
});

it("adds recommended sdk for release older than build 17763", async () => {
jest.spyOn(os, "release").mockReturnValue("10.0.16299");
const req16299 = vs.vsRequirement(swiftPackage("5.3", windows));
expect(req16299.components).toContain(
"Microsoft.VisualStudio.Component.Windows10SDK.17763"
);
});

it("finds vswhere path from environment value", async () => {
const vswherePath = path.join("C:", "bin");
const vswhereExe = path.join(vswherePath, "vswhere.exe");
process.env.VSWHERE_PATH = vswherePath;
expect(await vs.getVsWherePath()).toBe(vswhereExe);
});

it("finds vswhere path from ProgramFiles environment value", async () => {
const vswhereExe = path.join(
"C:",
"Program Files (x86)",
"Microsoft Visual Studio",
"Installer",
"vswhere.exe"
);
process.env["ProgramFiles(x86)"] = path.join("C:", "Program Files (x86)");
expect(await vs.getVsWherePath()).toBe(vswhereExe);
});
});
3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as system from "./os";
import * as versions from "./swift-versions";
import * as macos from "./macos-install";
import * as linux from "./linux-install";
import * as windows from "./windows-install";
import { getVersion } from "./get-version";

async function run() {
Expand All @@ -20,6 +21,8 @@ async function run() {
case system.OS.Ubuntu:
await linux.install(version, platform);
break;
case system.OS.Windows:
await windows.install(version, platform);
}

const current = await getVersion();
Expand Down
11 changes: 11 additions & 0 deletions src/os.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@ import getos from "getos";
export enum OS {
MacOS,
Ubuntu,
Windows,
}

export namespace OS {
export function all(): OS[] {
return [OS.MacOS, OS.Ubuntu, OS.Windows];
}
}

const AVAILABLE_OS: { [platform: string]: string[] } = {
macOS: ["latest", "11.0", "10.15"],
Ubuntu: ["latest", "20.04", "18.04", "16.04"],
Windows: ["latest", "10"],
};

export interface System {
Expand Down Expand Up @@ -41,6 +49,9 @@ export async function getSystem(): Promise<System> {
name: "Ubuntu",
};
break;
case "win32":
system = { os: OS.Windows, version: "latest", name: "Windows" };
break;
default:
throw new Error(`"${detectedSystem.os}" is not a supported platform`);
}
Expand Down
35 changes: 21 additions & 14 deletions src/swift-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ import * as core from "@actions/core";
import { System, OS } from "./os";

const VERSIONS_LIST: [string, OS[]][] = [
["5.6.1", [OS.MacOS, OS.Ubuntu]],
["5.6", [OS.MacOS, OS.Ubuntu]],
["5.5.3", [OS.MacOS, OS.Ubuntu]],
["5.5.2", [OS.MacOS, OS.Ubuntu]],
["5.5.1", [OS.MacOS, OS.Ubuntu]],
["5.5", [OS.MacOS, OS.Ubuntu]],
["5.4.3", [OS.MacOS, OS.Ubuntu]],
["5.4.2", [OS.MacOS, OS.Ubuntu]],
["5.4.1", [OS.MacOS, OS.Ubuntu]],
["5.4", [OS.MacOS, OS.Ubuntu]],
["5.3.3", [OS.MacOS, OS.Ubuntu]],
["5.3.2", [OS.MacOS, OS.Ubuntu]],
["5.3.1", [OS.MacOS, OS.Ubuntu]],
["5.3", [OS.MacOS, OS.Ubuntu]],
["5.6.1", OS.all()],
["5.6", OS.all()],
["5.5.3", OS.all()],
["5.5.2", OS.all()],
["5.5.1", OS.all()],
["5.5", OS.all()],
["5.4.3", OS.all()],
["5.4.2", OS.all()],
["5.4.1", OS.all()],
["5.4", OS.all()],
["5.3.3", OS.all()],
["5.3.2", OS.all()],
["5.3.1", OS.all()],
["5.3", OS.all()],
["5.2.5", [OS.Ubuntu]],
["5.2.4", [OS.MacOS, OS.Ubuntu]],
["5.2.3", [OS.Ubuntu]],
Expand Down Expand Up @@ -68,6 +68,7 @@ function notEmpty<T>(value: T | null | undefined): value is T {
export interface Package {
url: string;
name: string;
version: string;
}

export function swiftPackage(version: string, system: System): Package {
Expand All @@ -86,13 +87,19 @@ export function swiftPackage(version: string, system: System): Package {
archiveName = `swift-${version}-RELEASE-ubuntu${system.version}`;
archiveFile = `${archiveName}.tar.gz`;
break;
case OS.Windows:
platform = "windows10";
archiveName = `swift-${version}-RELEASE-windows10.exe`;
archiveFile = archiveName;
break;
default:
throw new Error("Cannot create download URL for an unsupported platform");
}

return {
url: `https://swift.org/builds/swift-${version}-release/${platform}/swift-${version}-RELEASE/${archiveFile}`,
name: archiveName,
version: version,
};
}

Expand Down
Loading