Skip to content
Open
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
Export DEVELOPER_DIR instead of invoking xcode-select to set the acti…
…ve Xcode version.

Avoids changing the Xcode version system-wide. When using a self-hosted github
runner, the run isn't necessarily containerized. Changing the system-wide Xcode version
then creates conflicts between concurrent runs.
  • Loading branch information
bobergj committed Jan 4, 2023
commit 5a62fc0b28765665d892c0c7768015118b53f218
8 changes: 2 additions & 6 deletions __tests__/xcode-selector.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import fs from "fs";
import child from "child_process";
import * as core from "@actions/core";
import { XcodeSelector } from "../src/xcode-selector";
import * as xcodeUtils from "../src/xcode-utils";

jest.mock("child_process");

const fakeGetXcodeVersionInfoResult: xcodeUtils.XcodeVersion[] = [
{ version: "10.3.0", buildNumber: "", path: "/Applications/Xcode_10.3.app", releaseType: "GM", stable: true },
{ version: "12.0.0", buildNumber: "", path: "/Applications/Xcode_12_beta.app", releaseType: "Beta", stable: false },
Expand Down Expand Up @@ -83,7 +80,6 @@ describe("XcodeSelector", () => {
describe("setVersion", () => {
let coreExportVariableSpy: jest.SpyInstance;
let fsExistsSpy: jest.SpyInstance;
let fsSpawnSpy: jest.SpyInstance;
const xcodeVersion: xcodeUtils.XcodeVersion = {
version: "11.4",
buildNumber: "12A7300",
Expand All @@ -95,7 +91,6 @@ describe("XcodeSelector", () => {
beforeEach(() => {
coreExportVariableSpy = jest.spyOn(core, "exportVariable");
fsExistsSpy = jest.spyOn(fs, "existsSync");
fsSpawnSpy = jest.spyOn(child, "spawnSync");
});

afterEach(() => {
Expand All @@ -107,7 +102,8 @@ describe("XcodeSelector", () => {
fsExistsSpy.mockImplementation(() => true);
const sel = new XcodeSelector();
sel.setVersion(xcodeVersion);
expect(fsSpawnSpy).toHaveBeenCalledWith("sudo", ["xcode-select", "-s", "/Applications/Xcode_11.4.app"]);
expect(coreExportVariableSpy).toHaveBeenCalledTimes(2)
expect(coreExportVariableSpy).toHaveBeenCalledWith("DEVELOPER_DIR", "/Applications/Xcode_11.4.app/Contents/Developer");
expect(coreExportVariableSpy).toHaveBeenCalledWith("MD_APPLE_SDK_ROOT", "/Applications/Xcode_11.4.app");
});

Expand Down
17 changes: 6 additions & 11 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.XcodeSelector = void 0;
const child = __importStar(__nccwpck_require__(2081));
const core = __importStar(__nccwpck_require__(2186));
const fs = __importStar(__nccwpck_require__(7147));
const semver = __importStar(__nccwpck_require__(1383));
Expand Down Expand Up @@ -134,7 +133,7 @@ class XcodeSelector {
if (!fs.existsSync(xcodeVersion.path)) {
throw new Error(`Invalid version: Directory '${xcodeVersion.path}' doesn't exist`);
}
child.spawnSync("sudo", ["xcode-select", "-s", xcodeVersion.path]);
core.exportVariable("DEVELOPER_DIR", (0, xcode_utils_1.developerDirPath)(xcodeVersion));
// set "MD_APPLE_SDK_ROOT" environment variable to specify Xcode for Mono and Xamarin
core.exportVariable("MD_APPLE_SDK_ROOT", xcodeVersion.path);
}
Expand Down Expand Up @@ -173,7 +172,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getXcodeVersionInfo = exports.getXcodeReleaseType = exports.getInstalledXcodeApps = exports.parsePlistFile = void 0;
exports.developerDirPath = exports.getXcodeVersionInfo = exports.getXcodeReleaseType = exports.getInstalledXcodeApps = exports.parsePlistFile = void 0;
const path = __importStar(__nccwpck_require__(1017));
const fs = __importStar(__nccwpck_require__(7147));
const core = __importStar(__nccwpck_require__(2186));
Expand Down Expand Up @@ -231,6 +230,10 @@ const getXcodeVersionInfo = (xcodeRootPath) => {
};
};
exports.getXcodeVersionInfo = getXcodeVersionInfo;
const developerDirPath = (xcodeVersion) => {
return path.join(xcodeVersion.path, "Contents", "Developer");
};
exports.developerDirPath = developerDirPath;


/***/ }),
Expand Down Expand Up @@ -14276,14 +14279,6 @@ module.exports = require("assert");

/***/ }),

/***/ 2081:
/***/ ((module) => {

"use strict";
module.exports = require("child_process");

/***/ }),

/***/ 6113:
/***/ ((module) => {

Expand Down
11 changes: 7 additions & 4 deletions src/xcode-selector.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import * as child from "child_process";
import * as core from "@actions/core";
import * as fs from "fs";
import * as semver from "semver";
import { getInstalledXcodeApps, getXcodeVersionInfo, XcodeVersion } from "./xcode-utils";
import {
developerDirPath,
getInstalledXcodeApps,
getXcodeVersionInfo,
XcodeVersion,
} from "./xcode-utils";

export class XcodeSelector {
public getAllVersions(): XcodeVersion[] {
Expand Down Expand Up @@ -47,8 +51,7 @@ export class XcodeSelector {
if (!fs.existsSync(xcodeVersion.path)) {
throw new Error(`Invalid version: Directory '${xcodeVersion.path}' doesn't exist`);
}

child.spawnSync("sudo", ["xcode-select", "-s", xcodeVersion.path]);
core.exportVariable("DEVELOPER_DIR", developerDirPath(xcodeVersion));

// set "MD_APPLE_SDK_ROOT" environment variable to specify Xcode for Mono and Xamarin
core.exportVariable("MD_APPLE_SDK_ROOT", xcodeVersion.path);
Expand Down
4 changes: 4 additions & 0 deletions src/xcode-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@ export const getXcodeVersionInfo = (xcodeRootPath: string): XcodeVersion | null
path: xcodeRootPath,
} as XcodeVersion;
};

export const developerDirPath = (xcodeVersion: XcodeVersion): string => {
return path.join(xcodeVersion.path, "Contents", "Developer");
};