Skip to content

Commit 4280b0e

Browse files
committed
Favor GITHUB_WORKFLOW_REF
Introduced with GHES 3.9: https://docs.github.com/en/[email protected]/actions/learn-github-actions/variables GITHUB_WORKFLOW_REF means that actions don't need to use `actions: read` to determine the path to the running workflow.
1 parent 65b0987 commit 4280b0e

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
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+
- Users of GHES 3.9+ and GHEC will no longer need to include `actions: read` permissions to use `upload-sarif` in private repositories.
1010

1111
## 3.24.3 - 15 Feb 2024
1212

lib/api-client.js

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

lib/api-client.js.map

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

src/api-client.ts

+12
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,18 @@ export async function getGitHubVersion(): Promise<GitHubVersion> {
119119
* Get the path of the currently executing workflow relative to the repository root.
120120
*/
121121
export async function getWorkflowRelativePath(): Promise<string> {
122+
const workflow_ref = process.env["GITHUB_WORKFLOW_REF"];
123+
// When GHES 3.8 support is removed, this if guard and its corresponding
124+
// fallback code can be removed.
125+
if (workflow_ref !== undefined) {
126+
const workflowRegExp = new RegExp("^[^/]+/[^/]+/(.*?)@.*");
127+
const match = workflow_ref.match(workflowRegExp);
128+
if (match) {
129+
return new Promise((resolve) => {
130+
resolve(match[1]);
131+
});
132+
}
133+
}
122134
const repo_nwo = getRequiredEnvParam("GITHUB_REPOSITORY").split("/");
123135
const owner = repo_nwo[0];
124136
const repo = repo_nwo[1];

0 commit comments

Comments
 (0)