Skip to content

Commit dfd393e

Browse files
committed
Add ability to resolve snapshot latest date
1 parent 3aed395 commit dfd393e

12 files changed

+509
-164
lines changed

__tests__/snapshot-resolver.test.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { OS } from "../src/os";
2+
import { SnapshotResolver } from "../src/snapshot-resolver";
3+
4+
describe("build snapshot package info", () => {
5+
const githubToken = process.env.TEST_GITHUB_TOKEN;
6+
if (githubToken) {
7+
const resolver = new SnapshotResolver(githubToken);
8+
const expectedDate = new Date().toISOString().split("T")[0];
9+
10+
it("resolve main branch latest snapshot", async () => {
11+
const toolchain = await resolver.getSnapshot("main-snapshot");
12+
13+
expect(toolchain).toEqual({ branch: "main", date: expectedDate });
14+
});
15+
16+
it("resolve simver branch snapshot", async () => {
17+
const toolchain = await resolver.getSnapshot("6.0-snapshot");
18+
19+
expect(toolchain).toEqual({ branch: "6.0", date: expectedDate });
20+
});
21+
}
22+
23+
const resolver = new SnapshotResolver(null);
24+
25+
it("resolve with explicit date to main", async () => {
26+
const toolchain = await resolver.getSnapshot("main-snapshot-2022-01-28");
27+
28+
expect(toolchain).toEqual({ branch: "main", date: "2022-01-28" });
29+
});
30+
31+
it("resolve with explicit date to semver", async () => {
32+
const toolchain = await resolver.getSnapshot("5.7-snapshot-2022-08-30");
33+
34+
expect(toolchain).toEqual({ branch: "5.7", date: "2022-08-30" });
35+
});
36+
});

__tests__/swift-package.test.ts

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { OS } from "../src/os";
2+
import { getPackage } from "../src/swift-package";
3+
4+
describe("make package", () => {
5+
it("main branch for macOS", async () => {
6+
const pkg = await getPackage("main-snapshot-2024-08-01", {
7+
os: OS.MacOS,
8+
version: "latest",
9+
name: "macOS",
10+
});
11+
12+
expect(pkg).toStrictEqual({
13+
url: "https://swift.org/builds/development/xcode/swift-DEVELOPMENT-SNAPSHOT-2024-08-01-a/swift-DEVELOPMENT-SNAPSHOT-2024-08-01-a-osx.pkg",
14+
name: "swift-DEVELOPMENT-SNAPSHOT-2024-08-01-a-osx",
15+
version: "6.0",
16+
});
17+
});
18+
19+
it("main branch for Ubuntu", async () => {
20+
const pkg = await getPackage("main-snapshot-2024-08-01", {
21+
os: OS.Ubuntu,
22+
version: "22.04",
23+
name: "Ubuntu",
24+
});
25+
26+
expect(pkg).toStrictEqual({
27+
url: "https://swift.org/builds/development/ubuntu2204/swift-DEVELOPMENT-SNAPSHOT-2024-08-01-a/swift-DEVELOPMENT-SNAPSHOT-2024-08-01-a-ubuntu22.04.tar.gz",
28+
name: "swift-DEVELOPMENT-SNAPSHOT-2024-08-01-a-ubuntu22.04",
29+
version: "6.0",
30+
});
31+
});
32+
33+
it("simver branch for macOS", async () => {
34+
const pkg = await getPackage("5.10-snapshot-2024-08-02", {
35+
os: OS.MacOS,
36+
version: "latest",
37+
name: "macOS",
38+
});
39+
40+
expect(pkg).toStrictEqual({
41+
url: "https://swift.org/builds/swift-5.10-branch/xcode/swift-5.10-DEVELOPMENT-SNAPSHOT-2024-08-02-a/swift-5.10-DEVELOPMENT-SNAPSHOT-2024-08-02-a-osx.pkg",
42+
name: "swift-5.10-DEVELOPMENT-SNAPSHOT-2024-08-02-a-osx",
43+
version: "5.10",
44+
});
45+
});
46+
47+
it("simver branch for Ubuntu", async () => {
48+
const pkg = await getPackage("5.10-snapshot-2024-08-02", {
49+
os: OS.Ubuntu,
50+
version: "22.04",
51+
name: "Ubuntu",
52+
});
53+
54+
expect(pkg).toStrictEqual({
55+
url: "https://swift.org/builds/swift-5.10-branch/ubuntu2204/swift-5.10-DEVELOPMENT-SNAPSHOT-2024-08-02-a/swift-5.10-DEVELOPMENT-SNAPSHOT-2024-08-02-a-ubuntu22.04.tar.gz",
56+
name: "swift-5.10-DEVELOPMENT-SNAPSHOT-2024-08-02-a-ubuntu22.04",
57+
version: "5.10",
58+
});
59+
});
60+
});

__tests__/visual-studio.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os from "os";
22
import * as path from "path";
33
import * as vs from "../src/visual-studio";
4-
import { swiftPackage } from "../src/swift-versions";
4+
import { getPackage } from "../src/swift-package";
55
import { OS, System } from "../src/os";
66

77
jest.mock("fs", () => {
@@ -29,7 +29,7 @@ describe("visual studio resolver", () => {
2929
it("fetches visual studio requirement for swift version", async () => {
3030
jest.spyOn(os, "release").mockReturnValue("10.0.17763");
3131

32-
const req5_3 = vs.vsRequirement(swiftPackage("5.3", windows));
32+
const req5_3 = vs.vsRequirement(await getPackage("5.3", windows));
3333
expect(req5_3.version).toBe("16");
3434
expect(req5_3.components).toContain(
3535
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64"
@@ -38,7 +38,7 @@ describe("visual studio resolver", () => {
3838
"Microsoft.VisualStudio.Component.Windows10SDK.17763"
3939
);
4040

41-
const req5_6 = vs.vsRequirement(swiftPackage("5.6", windows));
41+
const req5_6 = vs.vsRequirement(await getPackage("5.6", windows));
4242
expect(req5_6.version).toBe("16");
4343
expect(req5_6.components).toContain(
4444
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64"
@@ -50,21 +50,21 @@ describe("visual studio resolver", () => {
5050

5151
it("adds latest sdk for release newer than or equal to build 17763", async () => {
5252
jest.spyOn(os, "release").mockReturnValue("10.0.17763");
53-
const req17763 = vs.vsRequirement(swiftPackage("5.3", windows));
53+
const req17763 = vs.vsRequirement(await getPackage("5.3", windows));
5454
expect(req17763.components).toContain(
5555
"Microsoft.VisualStudio.Component.Windows10SDK.17763"
5656
);
5757

5858
jest.spyOn(os, "release").mockReturnValue("10.0.18363");
59-
const req18363 = vs.vsRequirement(swiftPackage("5.3", windows));
59+
const req18363 = vs.vsRequirement(await getPackage("5.3", windows));
6060
expect(req18363.components).toContain(
6161
"Microsoft.VisualStudio.Component.Windows10SDK.18363"
6262
);
6363
});
6464

6565
it("adds recommended sdk for release older than build 17763", async () => {
6666
jest.spyOn(os, "release").mockReturnValue("10.0.16299");
67-
const req16299 = vs.vsRequirement(swiftPackage("5.3", windows));
67+
const req16299 = vs.vsRequirement(await getPackage("5.3", windows));
6868
expect(req16299.components).toContain(
6969
"Microsoft.VisualStudio.Component.Windows10SDK.17763"
7070
);

0 commit comments

Comments
 (0)