@@ -4,7 +4,6 @@ import * as path from "path";
44import { performance } from "perf_hooks" ;
55
66import * as toolcache from "@actions/tool-cache" ;
7- import { default as deepEqual } from "fast-deep-equal" ;
87import * as semver from "semver" ;
98import { v4 as uuidV4 } from "uuid" ;
109
@@ -13,7 +12,6 @@ import {
1312 isAnalyzingPullRequest ,
1413 isDynamicWorkflow ,
1514 isGitHubHostedRunner ,
16- isRunningLocalAction ,
1715} from "./actions-util" ;
1816import * as api from "./api-client" ;
1917import {
@@ -44,6 +42,7 @@ import {
4442 logPerLanguageBundleFallback ,
4543} from "./per-language-bundles" ;
4644import { getBundlePlatform } from "./platform" ;
45+ import { getCodeQLAssetDownloadURL } from "./setup/repository" ;
4746import * as tar from "./tar" ;
4847import {
4948 deleteToolcacheBundles ,
@@ -65,83 +64,13 @@ export enum ToolsSource {
6564 Download = "DOWNLOAD" ,
6665}
6766
68- const CODEQL_DEFAULT_ACTION_REPOSITORY = "github/codeql-action" ;
6967const CODEQL_NIGHTLIES_REPOSITORY_OWNER = "dsp-testing" ;
7068const CODEQL_NIGHTLIES_REPOSITORY_NAME = "codeql-cli-nightlies" ;
7169
7270const CODEQL_BUNDLE_VERSION_ALIAS : string [ ] = [ "linked" , "latest" ] ;
7371const CODEQL_NIGHTLY_TOOLS_INPUTS = [ "nightly" , "nightly-latest" ] ;
7472const CODEQL_TOOLCACHE_INPUT = "toolcache" ;
7573
76- export function getCodeQLActionRepository ( logger : Logger ) : string {
77- if ( isRunningLocalAction ( ) ) {
78- // This handles the case where the Action does not come from an Action repository,
79- // e.g. our integration tests which use the Action code from the current checkout.
80- // In these cases, the GITHUB_ACTION_REPOSITORY environment variable is not set.
81- logger . info (
82- "The CodeQL Action is checked out locally. Using the default CodeQL Action repository." ,
83- ) ;
84- return CODEQL_DEFAULT_ACTION_REPOSITORY ;
85- }
86-
87- return util . getRequiredEnvParam ( "GITHUB_ACTION_REPOSITORY" ) ;
88- }
89-
90- async function getCodeQLBundleDownloadURL (
91- tagName : string ,
92- apiDetails : api . GitHubApiDetails ,
93- codeQLBundleName : string ,
94- logger : Logger ,
95- ) : Promise < string > {
96- const codeQLActionRepository = getCodeQLActionRepository ( logger ) ;
97- const potentialDownloadSources = [
98- // This GitHub instance, and this Action.
99- [ apiDetails . url , codeQLActionRepository ] ,
100- // This GitHub instance, and the canonical Action.
101- [ apiDetails . url , CODEQL_DEFAULT_ACTION_REPOSITORY ] ,
102- // GitHub.com, and the canonical Action.
103- [ util . GITHUB_DOTCOM_URL , CODEQL_DEFAULT_ACTION_REPOSITORY ] ,
104- ] ;
105- // We now filter out any duplicates.
106- // Duplicates will happen either because the GitHub instance is GitHub.com, or because the Action is not a fork.
107- const uniqueDownloadSources = potentialDownloadSources . filter (
108- ( source , index , self ) => {
109- return ! self . slice ( 0 , index ) . some ( ( other ) => deepEqual ( source , other ) ) ;
110- } ,
111- ) ;
112- for ( const downloadSource of uniqueDownloadSources ) {
113- const [ apiURL , repository ] = downloadSource ;
114- // If we've reached the final case, short-circuit the API check since we know the bundle exists and is public.
115- if (
116- apiURL === util . GITHUB_DOTCOM_URL &&
117- repository === CODEQL_DEFAULT_ACTION_REPOSITORY
118- ) {
119- break ;
120- }
121- const [ repositoryOwner , repositoryName ] = repository . split ( "/" ) ;
122- try {
123- const release = await api . getApiClient ( ) . rest . repos . getReleaseByTag ( {
124- owner : repositoryOwner ,
125- repo : repositoryName ,
126- tag : tagName ,
127- } ) ;
128- for ( const asset of release . data . assets ) {
129- if ( asset . name === codeQLBundleName ) {
130- logger . info (
131- `Found CodeQL bundle ${ codeQLBundleName } in ${ repository } on ${ apiURL } with URL ${ asset . url } .` ,
132- ) ;
133- return asset . url ;
134- }
135- }
136- } catch ( e ) {
137- logger . info (
138- `Looked for CodeQL bundle ${ codeQLBundleName } in ${ repository } on ${ apiURL } but got error ${ e } .` ,
139- ) ;
140- }
141- }
142- return `https://github.com/${ CODEQL_DEFAULT_ACTION_REPOSITORY } /releases/download/${ tagName } /${ codeQLBundleName } ` ;
143- }
144-
14574function tryGetBundleVersionFromTagName (
14675 tagName : string ,
14776 logger : Logger ,
@@ -720,9 +649,10 @@ export async function getCodeQLSource(
720649 ? "zstd"
721650 : "gzip" ;
722651
652+ const action = { env : getEnv ( ) , logger } ;
723653 const platform = getBundlePlatform ( ) ;
724654 const perLanguageBundleLanguage = await getPerLanguageBundleLanguage (
725- { env : getEnv ( ) , features, logger } ,
655+ { ... action , features } ,
726656 {
727657 rawLanguages,
728658 otherLanguagePacksReason,
@@ -735,11 +665,11 @@ export async function getCodeQLSource(
735665
736666 // Resolves the combined or per-language bundle URL for the requested release.
737667 const resolveBundleURL = ( language ?: BuiltInLanguage ) =>
738- getCodeQLBundleDownloadURL (
739- bundleTagName ,
668+ getCodeQLAssetDownloadURL (
669+ action ,
740670 apiDetails ,
671+ bundleTagName ,
741672 getCodeQLBundleName ( compressionMethod , platform , language ) ,
742- logger ,
743673 ) ;
744674
745675 const combinedBundleURL = await resolveBundleURL ( ) ;
0 commit comments