Skip to content

Commit

Permalink
Implement "latest-stable" support (#5)
Browse files Browse the repository at this point in the history
* add "latest-stable" keyword

* rebuild app, update readme
  • Loading branch information
maxim-lobanov authored Aug 27, 2020
1 parent e8ada21 commit 8d89617
Show file tree
Hide file tree
Showing 7 changed files with 2,503 additions and 1,288 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ jobs:
runs-on: macos-latest
strategy:
matrix:
xcode-version: [10.3, 11, 11.2, 11.4.0, 11.4.1, ^11.4.0, latest]
xcode-version: [10.3, 11, 11.2, 11.4.0, 11.4.1, ^11.4.0, latest, latest-stable]
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v2

- name: setup-xcode
uses: ./
- uses: ./
with:
xcode-version: ${{ matrix.xcode-version }}
40 changes: 27 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,45 @@ The list of all available versions can be found in [virtual-environments](https:
# Available parameters
| Argument | Description | Format |
|-------------------------|--------------------------|--------------------|
| `xcode-version` | Specify the Xcode version to use | `latest` keyword or any [semver](https://semver.org/) string |
| `xcode-version` | Specify the Xcode version to use | `latest`, `latest-stable` or any [semver](https://semver.org/) string |

**Examples:** `latest`, `10`, `11.4`, `11.4.0`, `^11.4.0`

**Note:** `latest` *includes* beta releases that GitHub actions has installed.
**Examples:** `latest`, `latest-stable`, `10`, `11.4`, `11.4.0`, `^11.4.0`
**Note:**
- `latest-stable` points to the latest stable version of Xcode
- `latest` *includes* beta releases that GitHub actions has installed.

# Usage
Set the latest stable Xcode version:
```
name: CI
on: [push]
jobs:
build:
name: Set
runs-on: macos-latest
steps:
- name: setup-xcode
uses: maxim-lobanov/[email protected]
- uses: maxim-lobanov/[email protected]
with:
xcode-version: 11.4 # set the latest available Xcode 11.4.*
xcode-version: latest-stable
```

- name: setup-latest-xcode
uses: maxim-lobanov/[email protected]
Set the latest Xcode version including beta releases:
```
jobs:
build:
runs-on: macos-latest
steps:
- uses: maxim-lobanov/[email protected]
with:
xcode-version: latest # set the latest available Xcode 11.4.*
xcode-version: latest
```

Set the specific version of Xcode:
```
jobs:
build:
runs-on: macos-latest
steps:
- uses: maxim-lobanov/[email protected]
with:
xcode-version: 11.4
```
# License
The scripts and documentation in this project are released under the [MIT License](LICENSE)
35 changes: 20 additions & 15 deletions __tests__/xcode-selector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,26 @@ const fakeReadDirResults = [
buildFsDirentItem("Xcode_11.4.app", { isSymbolicLink: true, isDirectory: false }),
buildFsDirentItem("Xcode_11.4_beta.app", { isSymbolicLink: false, isDirectory: true }),
buildFsDirentItem("Xcode_11.app", { isSymbolicLink: false, isDirectory: true }),
buildFsDirentItem("Xcode_12_beta.app", { isSymbolicLink: false, isDirectory: true }),
buildFsDirentItem("third_party_folder", { isSymbolicLink: false, isDirectory: true }),
];

const fakeGetVersionsResult: XcodeVersion[] = [
{ version: "11.4.0", path: "" },
{ version: "11.2.1", path: "" },
{ version: "11.2.0", path: "" },
{ version: "11.0.0", path: "" },
{ version: "10.3.0", path: "" }
{ version: "12.0.0", path: "", stable: false },
{ version: "11.4.0", path: "", stable: true },
{ version: "11.2.1", path: "", stable: true },
{ version: "11.2.0", path: "", stable: true },
{ version: "11.0.0", path: "", stable: true },
{ version: "10.3.0", path: "", stable: true }
];

describe("XcodeSelector", () => {
describe("getXcodeVersionFromAppPath", () => {
it.each([
["/temp/Xcode_11.app", { version: "11.0.0", path: "/temp/Xcode_11.app"}],
["/temp/Xcode_11.2.app", { version: "11.2.0", path: "/temp/Xcode_11.2.app"}],
["/temp/Xcode_11.2.1.app", { version: "11.2.1", path: "/temp/Xcode_11.2.1.app"}],
["/temp/Xcode_11.2.1_beta.app", { version: "11.2.1", path: "/temp/Xcode_11.2.1_beta.app"}],
["/temp/Xcode_11.app", { version: "11.0.0", path: "/temp/Xcode_11.app", stable: true }],
["/temp/Xcode_11.2.app", { version: "11.2.0", path: "/temp/Xcode_11.2.app", stable: true }],
["/temp/Xcode_11.2.1.app", { version: "11.2.1", path: "/temp/Xcode_11.2.1.app", stable: true }],
["/temp/Xcode_11.2.1_beta.app", { version: "11.2.1", path: "/temp/Xcode_11.2.1_beta.app", stable: false }],
["/temp/Xcode.app", null],
["/temp/Xcode_11.2", null],
["/temp/Xcode.11.2.app", null]
Expand All @@ -66,18 +68,20 @@ describe("XcodeSelector", () => {
it("versions are filtered correctly", () => {
const sel = new XcodeSelector();
const expectedVersions: XcodeVersion[] = [
{ version: "11.4.0", path: "/Applications/Xcode_11.4_beta.app" },
{ version: "11.2.1", path: "/Applications/Xcode_11.2.1.app" },
{ version: "11.1.0", path: "/Applications/Xcode_11.1.app" },
{ version: "11.0.0", path: "/Applications/Xcode_11.app" }
{ version: "12.0.0", path: "/Applications/Xcode_12_beta.app", stable: false},
{ version: "11.4.0", path: "/Applications/Xcode_11.4_beta.app", stable: false },
{ version: "11.2.1", path: "/Applications/Xcode_11.2.1.app", stable: true },
{ version: "11.1.0", path: "/Applications/Xcode_11.1.app", stable: true },
{ version: "11.0.0", path: "/Applications/Xcode_11.app", stable: true },
];
expect(sel.getAllVersions()).toEqual(expectedVersions);
});
});

describe("findVersion", () => {
it.each([
["latest", "11.4.0"],
["latest", "12.0.0"],
["latest-stable", "11.4.0"],
["11", "11.4.0"],
["11.x", "11.4.0"],
["11.2.x", "11.2.1"],
Expand All @@ -102,7 +106,8 @@ describe("XcodeSelector", () => {
let fsSpawnSpy: jest.SpyInstance;
const xcodeVersion: XcodeVersion = {
version: "11.4",
path: "/Applications/Xcode_11.4.app"
path: "/Applications/Xcode_11.4.app",
stable: true
};

beforeEach(() => {
Expand Down
47 changes: 41 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ module.exports =
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ var threw = true;
/******/ try {
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ threw = false;
/******/ } finally {
/******/ if(threw) delete installedModules[moduleId];
/******/ }
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
Expand Down Expand Up @@ -1762,14 +1768,27 @@ module.exports = rcompare

"use strict";

var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.XcodeSelector = void 0;
const child = __importStar(__webpack_require__(129));
const core = __importStar(__webpack_require__(470));
const fs = __importStar(__webpack_require__(747));
Expand All @@ -1791,7 +1810,8 @@ class XcodeSelector {
}
return {
version: version.version,
path: appPath
path: appPath,
stable: !match[2],
};
}
getAllVersions() {
Expand All @@ -1810,6 +1830,9 @@ class XcodeSelector {
if (versionSpec === "latest") {
return availableVersions[0];
}
if (versionSpec === "latest-stable") {
return availableVersions.filter(ver => ver.stable)[0];
}
return (_a = availableVersions.find(ver => semver.satisfies(ver.version, versionSpec))) !== null && _a !== void 0 ? _a : null;
}
setVersion(xcodeVersion) {
Expand Down Expand Up @@ -2253,11 +2276,23 @@ module.exports = inc

"use strict";

var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
Expand Down
Loading

0 comments on commit 8d89617

Please sign in to comment.