Skip to content

Commit

Permalink
Favor GITHUB_WORKFLOW_REF
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jsoref committed Feb 13, 2024
1 parent c79c360 commit b66391a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Note that the only difference between `v2` and `v3` of the CodeQL Action is the

- Update default CodeQL bundle version to 2.16.2. [#2124](https://github.com/github/codeql-action/pull/2124)
- The CodeQL action no longer fails if it can't write to the telemetry api endpoint. [#2121](https://github.com/github/codeql-action/pull/2121)
- Users of GHES3.9+ and GHEC will no longer need to include `actions: read` permissions to use `upload-sarif` in private repositories.

## 3.24.0 - 02 Feb 2024

Expand Down
12 changes: 12 additions & 0 deletions lib/api-client.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/api-client.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ export async function getGitHubVersion(): Promise<GitHubVersion> {
* Get the path of the currently executing workflow relative to the repository root.
*/
export async function getWorkflowRelativePath(): Promise<string> {
const workflow_ref = process.env["GITHUB_WORKFLOW_REF"];
// When GHES 3.8 support is removed, this if guard and its corresponding
// fallback code can be removed.
if (workflow_ref !== undefined) {
const workflowRegExp = new RegExp("^[^/]+/[^/]+/(.*?)@.*");
const match = workflow_ref.match(workflowRegExp);
if (match) {
return new Promise((resolve) => {
resolve(match[1]);
});
}
}
const repo_nwo = getRequiredEnvParam("GITHUB_REPOSITORY").split("/");
const owner = repo_nwo[0];
const repo = repo_nwo[1];
Expand Down

0 comments on commit b66391a

Please sign in to comment.