Skip to content

Commit 350522e

Browse files
Update logic to check whether Xcode is stable or beta (#7)
* Update logic to determine whether Xcode is stable or not * remove debug
1 parent 39fba9d commit 350522e

10 files changed

+8071
-2421
lines changed

__tests__/data/xcode-beta.plist

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>licenseID</key>
6+
<string>EA1647</string>
7+
<key>licenseType</key>
8+
<string>Beta</string>
9+
</dict>
10+
</plist>
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>licenseID</key>
6+
<string>EA1647</string>
7+
</dict>
8+
</plist>

__tests__/data/xcode-stable.plist

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>licenseID</key>
6+
<string>EA1647</string>
7+
<key>licenseType</key>
8+
<string>GM</string>
9+
</dict>
10+
</plist>

__tests__/xcode-selector.test.ts

+16-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import * as fs from "fs";
22
import * as child from "child_process";
33
import * as core from "@actions/core";
44
import { XcodeSelector, XcodeVersion } from "../src/xcode-selector";
5+
import * as xcodeUtils from "../src/xcode-utils";
56

67
jest.mock("fs");
78
jest.mock("child_process");
89
jest.mock("@actions/core");
10+
jest.mock("../src/xcode-utils");
911

1012
const buildFsDirentItem = (name: string, opt: { isSymbolicLink: boolean; isDirectory: boolean }): fs.Dirent => {
1113
return {
@@ -39,11 +41,20 @@ const fakeGetVersionsResult: XcodeVersion[] = [
3941

4042
describe("XcodeSelector", () => {
4143
describe("getXcodeVersionFromAppPath", () => {
44+
beforeEach(() => {
45+
jest.spyOn(xcodeUtils, "getXcodeReleaseType").mockImplementation(() => xcodeUtils.XcodeReleaseType.GM);
46+
});
47+
48+
afterEach(() => {
49+
jest.resetAllMocks();
50+
jest.clearAllMocks();
51+
});
52+
4253
it.each([
4354
["/temp/Xcode_11.app", { version: "11.0.0", path: "/temp/Xcode_11.app", stable: true }],
4455
["/temp/Xcode_11.2.app", { version: "11.2.0", path: "/temp/Xcode_11.2.app", stable: true }],
4556
["/temp/Xcode_11.2.1.app", { version: "11.2.1", path: "/temp/Xcode_11.2.1.app", stable: true }],
46-
["/temp/Xcode_11.2.1_beta.app", { version: "11.2.1", path: "/temp/Xcode_11.2.1_beta.app", stable: false }],
57+
["/temp/Xcode_11.2.1_beta.app", { version: "11.2.1", path: "/temp/Xcode_11.2.1_beta.app", stable: true }],
4758
["/temp/Xcode.app", null],
4859
["/temp/Xcode_11.2", null],
4960
["/temp/Xcode.11.2.app", null]
@@ -58,6 +69,7 @@ describe("XcodeSelector", () => {
5869
describe("getAllVersions", () => {
5970
beforeEach(() => {
6071
jest.spyOn(fs, "readdirSync").mockImplementation(() => fakeReadDirResults);
72+
jest.spyOn(xcodeUtils, "getXcodeReleaseType").mockImplementation(() => xcodeUtils.XcodeReleaseType.GM);
6173
});
6274

6375
afterEach(() => {
@@ -68,8 +80,8 @@ describe("XcodeSelector", () => {
6880
it("versions are filtered correctly", () => {
6981
const sel = new XcodeSelector();
7082
const expectedVersions: XcodeVersion[] = [
71-
{ version: "12.0.0", path: "/Applications/Xcode_12_beta.app", stable: false},
72-
{ version: "11.4.0", path: "/Applications/Xcode_11.4_beta.app", stable: false },
83+
{ version: "12.0.0", path: "/Applications/Xcode_12_beta.app", stable: true},
84+
{ version: "11.4.0", path: "/Applications/Xcode_11.4_beta.app", stable: true },
7385
{ version: "11.2.1", path: "/Applications/Xcode_11.2.1.app", stable: true },
7486
{ version: "11.1.0", path: "/Applications/Xcode_11.1.app", stable: true },
7587
{ version: "11.0.0", path: "/Applications/Xcode_11.app", stable: true },
@@ -135,4 +147,5 @@ describe("XcodeSelector", () => {
135147
expect(() => sel.setVersion(xcodeVersion)).toThrow();
136148
});
137149
});
150+
138151
});

__tests__/xcode-utils.test.ts

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import * as path from "path";
2+
import { getXcodeReleaseType, XcodeReleaseType } from "../src/xcode-utils";
3+
4+
jest.mock("path");
5+
6+
describe("getXcodeReleaseType", () => {
7+
const buildPlistPath = (plistName: string) => {
8+
return `${__dirname}/data/${plistName}`;
9+
};
10+
11+
let pathJoinSpy: jest.SpyInstance;
12+
13+
beforeEach(() => {
14+
pathJoinSpy = jest.spyOn(path, "join");
15+
});
16+
17+
it("stable release", () => {
18+
const plistPath = buildPlistPath("xcode-stable.plist");
19+
pathJoinSpy.mockImplementation(() => plistPath);
20+
const releaseType = getXcodeReleaseType("");
21+
expect(releaseType).toBe(XcodeReleaseType.GM);
22+
});
23+
24+
it("beta release", () => {
25+
const plistPath = buildPlistPath("xcode-beta.plist");
26+
pathJoinSpy.mockImplementation(() => plistPath);
27+
const releaseType = getXcodeReleaseType("");
28+
expect(releaseType).toBe(XcodeReleaseType.Beta);
29+
});
30+
31+
it("unknown release", () => {
32+
const plistPath = buildPlistPath("xcode-empty-license.plist");
33+
pathJoinSpy.mockImplementation(() => plistPath);
34+
const releaseType = getXcodeReleaseType("");
35+
expect(releaseType).toBe(XcodeReleaseType.Unknown);
36+
});
37+
38+
it("non-existent plist", () => {
39+
const plistPath = buildPlistPath("xcode-fake.plist");
40+
pathJoinSpy.mockImplementation(() => plistPath);
41+
const releaseType = getXcodeReleaseType("");
42+
expect(releaseType).toBe(XcodeReleaseType.Unknown);
43+
});
44+
45+
afterEach(() => {
46+
jest.resetAllMocks();
47+
jest.clearAllMocks();
48+
});
49+
});

0 commit comments

Comments
 (0)