Skip to content

Commit 7e27807

Browse files
angelapwenhenrymercergithub-actions[bot]
authored
Only run check SIP enablement once in init step (github#2441)
Co-authored-by: Henry Mercer <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent fd5fa13 commit 7e27807

10 files changed

+46
-16
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Note that the only difference between `v2` and `v3` of the CodeQL Action is the
66

77
## [UNRELEASED]
88

9-
No user facing changes.
9+
- Fix an issue where the `csrutil` system call used for telemetry would fail on MacOS ARM machines with System Integrity Protection disabled. [#2441](https://github.com/github/codeql-action/pull/2441)
1010

1111
## 3.26.4 - 21 Aug 2024
1212

lib/environment.js

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/environment.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/util.js

+13-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/util.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/environment.ts

+6
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ export enum EnvVar {
5050
/** Whether the init action has been run. */
5151
INIT_ACTION_HAS_RUN = "CODEQL_ACTION_INIT_HAS_RUN",
5252

53+
/**
54+
* For MacOS. Result of `csrutil status` to determine whether System Integrity
55+
* Protection is enabled.
56+
*/
57+
IS_SIP_ENABLED = "CODEQL_ACTION_IS_SIP_ENABLED",
58+
5359
/** UUID representing the current job run. */
5460
JOB_RUN_UUID = "JOB_RUN_UUID",
5561

src/init-action.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
checkDiskUsage,
4949
checkForTimeout,
5050
checkGitHubVersionInRange,
51+
checkSipEnablement,
5152
codeQlVersionAtLeast,
5253
DEFAULT_DEBUG_ARTIFACT_NAME,
5354
DEFAULT_DEBUG_DATABASE_NAME,
@@ -56,7 +57,6 @@ import {
5657
getThreadsFlagValue,
5758
initializeEnvironment,
5859
isHostedRunner,
59-
isSipEnabled,
6060
ConfigurationError,
6161
wrapError,
6262
checkActionVersion,
@@ -555,7 +555,7 @@ async function run() {
555555
!(await codeQlVersionAtLeast(codeql, "2.15.1")) &&
556556
process.platform === "darwin" &&
557557
(process.arch === "arm" || process.arch === "arm64") &&
558-
!(await isSipEnabled(logger))
558+
!(await checkSipEnablement(logger))
559559
) {
560560
logger.warning(
561561
"CodeQL versions 2.15.0 and lower are not supported on MacOS ARM machines with System Integrity Protection (SIP) disabled.",

src/util.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ export async function checkDiskUsage(
10211021
if (
10221022
process.platform === "darwin" &&
10231023
(process.arch === "arm" || process.arch === "arm64") &&
1024-
!(await isSipEnabled(logger))
1024+
!(await checkSipEnablement(logger))
10251025
) {
10261026
return undefined;
10271027
}
@@ -1113,11 +1113,20 @@ export function cloneObject<T>(obj: T): T {
11131113
return JSON.parse(JSON.stringify(obj)) as T;
11141114
}
11151115

1116-
// For MacOS runners: runs `csrutil status` to determine whether System
1117-
// Integrity Protection is enabled.
1118-
export async function isSipEnabled(
1116+
// The first time this function is called, it runs `csrutil status` to determine
1117+
// whether System Integrity Protection is enabled; and saves the result in an
1118+
// environment variable. Afterwards, simply return the value of the environment
1119+
// variable.
1120+
export async function checkSipEnablement(
11191121
logger: Logger,
11201122
): Promise<boolean | undefined> {
1123+
if (
1124+
process.env[EnvVar.IS_SIP_ENABLED] !== undefined &&
1125+
["true", "false"].includes(process.env[EnvVar.IS_SIP_ENABLED])
1126+
) {
1127+
return process.env[EnvVar.IS_SIP_ENABLED] === "true";
1128+
}
1129+
11211130
try {
11221131
const sipStatusOutput = await exec.getExecOutput("csrutil status");
11231132
if (sipStatusOutput.exitCode === 0) {
@@ -1126,13 +1135,15 @@ export async function isSipEnabled(
11261135
"System Integrity Protection status: enabled.",
11271136
)
11281137
) {
1138+
core.exportVariable(EnvVar.IS_SIP_ENABLED, "true");
11291139
return true;
11301140
}
11311141
if (
11321142
sipStatusOutput.stdout.includes(
11331143
"System Integrity Protection status: disabled.",
11341144
)
11351145
) {
1146+
core.exportVariable(EnvVar.IS_SIP_ENABLED, "false");
11361147
return false;
11371148
}
11381149
}

0 commit comments

Comments
 (0)