Skip to content

Commit 29e1660

Browse files
Get stable versions as default (#31)
* Get stable versions as default -beta suffix after semver will look for beta versions * Some refactoring * minor lint fix
1 parent 881be56 commit 29e1660

File tree

4 files changed

+58
-18
lines changed

4 files changed

+58
-18
lines changed

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ The list of all available versions can be found in [virtual-environments](https:
66
# Available parameters
77
| Argument | Description | Format |
88
|-------------------------|--------------------------|--------------------|
9-
| `xcode-version` | Specify the Xcode version to use | - `latest` or<br> - `latest-stable` or<br> - [SemVer](https://semver.org/) string |
9+
| `xcode-version` | Specify the Xcode version to use | - `latest` or<br> - `latest-stable` or<br> - [SemVer](https://semver.org/) string or<br> - [SemVer](https://semver.org/)`-beta` |
1010

1111
**Notes:**
1212
- `latest-stable` points to the latest stable version of Xcode
1313
- `latest` *includes* beta releases that GitHub actions has installed
1414
- SemVer examples: `10`, `11.4`, `12.0`, `11.7.0`, `^11.7.0` (find more examples in [SemVer cheatsheet](https://devhints.io/semver))
15+
- `-beta` suffix after SemVer will only select among beta releases that GitHub actions has installed
1516
- If sets a specific version, wraps it to single quotes in YAML like `'12.0'` to pass it as string because GitHub trimmes trailing `.0` from numbers
1617

1718
# Usage
19+
1820
Set the latest stable Xcode version:
1921
```
2022
jobs:
@@ -37,7 +39,7 @@ jobs:
3739
xcode-version: latest
3840
```
3941

40-
Set the specific version of Xcode:
42+
Set the specific stable version of Xcode:
4143
```
4244
jobs:
4345
build:
@@ -47,5 +49,16 @@ jobs:
4749
with:
4850
xcode-version: '12.0'
4951
```
52+
53+
Set the specific beta version of Xcode:
54+
```
55+
jobs:
56+
build:
57+
runs-on: macos-latest
58+
steps:
59+
- uses: maxim-lobanov/setup-xcode@v1
60+
with:
61+
xcode-version: '12.0-beta'
62+
```
5063
# License
5164
The scripts and documentation in this project are released under the [MIT License](LICENSE)

__tests__/xcode-selector.test.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ jest.mock("child_process");
99
const fakeGetXcodeVersionInfoResult: xcodeUtils.XcodeVersion[] = [
1010
{ version: "10.3.0", buildNumber: "", path: "/Applications/Xcode_10.3.app", releaseType: "GM", stable: true },
1111
{ version: "12.0.0", buildNumber: "", path: "/Applications/Xcode_12_beta.app", releaseType: "Beta", stable: false },
12+
{ version: "12.0.0", buildNumber: "", path: "/Applications/Xcode_12.app", releaseType: "GM", stable: true },
1213
{ version: "11.2.1", buildNumber: "", path: "/Applications/Xcode_11.2.1.app", releaseType: "GM", stable: true },
1314
{ version: "11.4.0", buildNumber: "", path: "/Applications/Xcode_11.4.app", releaseType: "GM", stable: true },
1415
{ version: "11.0.0", buildNumber: "", path: "/Applications/Xcode_11.app", releaseType: "GM", stable: true },
@@ -17,6 +18,7 @@ const fakeGetXcodeVersionInfoResult: xcodeUtils.XcodeVersion[] = [
1718
const fakeGetInstalledXcodeAppsResult: string[] = [
1819
"/Applications/Xcode_10.3.app",
1920
"/Applications/Xcode_12_beta.app",
21+
"/Applications/Xcode_12.app",
2022
"/Applications/Xcode_11.2.1.app",
2123
"/Applications/Xcode_11.4.app",
2224
"/Applications/Xcode_11.app",
@@ -25,6 +27,7 @@ const fakeGetInstalledXcodeAppsResult: string[] = [
2527
];
2628
const expectedGetAllVersionsResult: xcodeUtils.XcodeVersion[] = [
2729
{ version: "12.0.0", buildNumber: "", path: "/Applications/Xcode_12_beta.app", releaseType: "Beta", stable: false },
30+
{ version: "12.0.0", buildNumber: "", path: "/Applications/Xcode_12.app", releaseType: "GM", stable: true },
2831
{ version: "11.4.0", buildNumber: "", path: "/Applications/Xcode_11.4.app", releaseType: "GM", stable: true },
2932
{ version: "11.2.1", buildNumber: "", path: "/Applications/Xcode_11.2.1.app", releaseType: "GM", stable: true },
3033
{ version: "11.2.0", buildNumber: "", path: "/Applications/Xcode_11.2.app", releaseType: "GM", stable: true },
@@ -52,23 +55,28 @@ describe("XcodeSelector", () => {
5255

5356
describe("findVersion", () => {
5457
it.each([
55-
["latest", "12.0.0"],
56-
["latest-stable", "11.4.0"],
57-
["11", "11.4.0"],
58-
["11.x", "11.4.0"],
59-
["11.2.x", "11.2.1"],
60-
["11.2.0", "11.2.0"],
61-
["10.x", "10.3.0"],
62-
["~11.2.0", "11.2.1"],
63-
["^11.2.0", "11.4.0"],
64-
["< 11.0", "10.3.0"],
65-
["10.0.0 - 11.2.0", "11.2.0"],
66-
["give me latest version", null]
67-
] as [string, string | null][])("'%s' -> '%s'", (versionSpec: string, expected: string | null) => {
58+
["latest-stable", "12.0.0", true],
59+
["latest", "12.0.0", false],
60+
["11", "11.4.0", true],
61+
["11.x", "11.4.0", true],
62+
["11.2.x", "11.2.1", true],
63+
["11.2.0", "11.2.0", true],
64+
["10.x", "10.3.0", true],
65+
["~11.2.0", "11.2.1", true],
66+
["^11.2.0", "11.4.0", true],
67+
["< 11.0", "10.3.0", true],
68+
["10.0.0 - 11.2.0", "11.2.0", true],
69+
["12.0-beta", "12.0.0", false],
70+
["12.0", "12.0.0", true],
71+
["give me latest version", null, null]
72+
] as [string, string | null, boolean | null][])("'%s' -> '%s'", (versionSpec: string, expected: string | null, expectedStable: boolean | null) => {
6873
const sel = new XcodeSelector();
6974
sel.getAllVersions = (): xcodeUtils.XcodeVersion[] => expectedGetAllVersionsResult;
70-
const matchedVersion = sel.findVersion(versionSpec)?.version ?? null;
75+
const xcodeVersion = sel.findVersion(versionSpec)
76+
const matchedVersion = xcodeVersion?.version ?? null;
77+
const isStable = xcodeVersion?.stable ?? null;
7178
expect(matchedVersion).toBe(expected);
79+
expect(isStable).toBe(expectedStable);
7280
});
7381
});
7482

dist/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,15 @@ class XcodeSelector {
116116
if (versionSpec === "latest-stable") {
117117
return availableVersions.filter(ver => ver.stable)[0];
118118
}
119-
return (_a = availableVersions.find(ver => semver.satisfies(ver.version, versionSpec))) !== null && _a !== void 0 ? _a : null;
119+
const betaSuffix = "-beta";
120+
let isStable = true;
121+
if (versionSpec.endsWith(betaSuffix)) {
122+
isStable = false;
123+
versionSpec = versionSpec.slice(0, -betaSuffix.length);
124+
}
125+
return ((_a = availableVersions
126+
.filter(ver => ver.stable === isStable)
127+
.find(ver => semver.satisfies(ver.version, versionSpec))) !== null && _a !== void 0 ? _a : null);
120128
}
121129
setVersion(xcodeVersion) {
122130
if (!fs.existsSync(xcodeVersion.path)) {

src/xcode-selector.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,18 @@ export class XcodeSelector {
2929
return availableVersions.filter(ver => ver.stable)[0];
3030
}
3131

32-
return availableVersions.find(ver => semver.satisfies(ver.version, versionSpec)) ?? null;
32+
const betaSuffix = "-beta";
33+
let isStable = true;
34+
if (versionSpec.endsWith(betaSuffix)) {
35+
isStable = false;
36+
versionSpec = versionSpec.slice(0, -betaSuffix.length);
37+
}
38+
39+
return (
40+
availableVersions
41+
.filter(ver => ver.stable === isStable)
42+
.find(ver => semver.satisfies(ver.version, versionSpec)) ?? null
43+
);
3344
}
3445

3546
setVersion(xcodeVersion: XcodeVersion): void {

0 commit comments

Comments
 (0)