@@ -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
@@ -35,7 +34,6 @@ import {
3534 Feature ,
3635 FeatureEnablement ,
3736} from "./feature-flags" ;
38- import { GITHUB_DOTCOM_URL } from "./github" ;
3937import { BuiltInLanguage } from "./languages" ;
4038import { Logger } from "./logging" ;
4139import { getCodeQlVersionsForOverlayBaseDatabases } from "./overlay/caching" ;
@@ -44,10 +42,7 @@ import {
4442 logPerLanguageBundleFallback ,
4543} from "./per-language-bundles" ;
4644import { getBundlePlatform } from "./platform" ;
47- import {
48- CODEQL_DEFAULT_ACTION_REPOSITORY ,
49- getCodeQLActionRepository ,
50- } from "./setup/repository" ;
45+ import { getCodeQLAssetDownloadURL } from "./setup/repository" ;
5146import * as tar from "./tar" ;
5247import {
5348 deleteToolcacheBundles ,
@@ -76,64 +71,6 @@ const CODEQL_BUNDLE_VERSION_ALIAS: string[] = ["linked", "latest"];
7671const CODEQL_NIGHTLY_TOOLS_INPUTS = [ "nightly" , "nightly-latest" ] ;
7772const CODEQL_TOOLCACHE_INPUT = "toolcache" ;
7873
79- async function getCodeQLBundleDownloadURL (
80- tagName : string ,
81- apiDetails : api . GitHubApiDetails ,
82- codeQLBundleName : string ,
83- logger : Logger ,
84- ) : Promise < string > {
85- const codeQLActionRepository = getCodeQLActionRepository ( {
86- logger,
87- env : getEnv ( ) ,
88- } ) ;
89- const potentialDownloadSources = [
90- // This GitHub instance, and this Action.
91- [ apiDetails . url , codeQLActionRepository ] ,
92- // This GitHub instance, and the canonical Action.
93- [ apiDetails . url , CODEQL_DEFAULT_ACTION_REPOSITORY ] ,
94- // GitHub.com, and the canonical Action.
95- [ GITHUB_DOTCOM_URL , CODEQL_DEFAULT_ACTION_REPOSITORY ] ,
96- ] ;
97- // We now filter out any duplicates.
98- // Duplicates will happen either because the GitHub instance is GitHub.com, or because the Action is not a fork.
99- const uniqueDownloadSources = potentialDownloadSources . filter (
100- ( source , index , self ) => {
101- return ! self . slice ( 0 , index ) . some ( ( other ) => deepEqual ( source , other ) ) ;
102- } ,
103- ) ;
104- for ( const downloadSource of uniqueDownloadSources ) {
105- const [ apiURL , repository ] = downloadSource ;
106- // If we've reached the final case, short-circuit the API check since we know the bundle exists and is public.
107- if (
108- apiURL === GITHUB_DOTCOM_URL &&
109- repository === CODEQL_DEFAULT_ACTION_REPOSITORY
110- ) {
111- break ;
112- }
113- const [ repositoryOwner , repositoryName ] = repository . split ( "/" ) ;
114- try {
115- const release = await api . getApiClient ( ) . rest . repos . getReleaseByTag ( {
116- owner : repositoryOwner ,
117- repo : repositoryName ,
118- tag : tagName ,
119- } ) ;
120- for ( const asset of release . data . assets ) {
121- if ( asset . name === codeQLBundleName ) {
122- logger . info (
123- `Found CodeQL bundle ${ codeQLBundleName } in ${ repository } on ${ apiURL } with URL ${ asset . url } .` ,
124- ) ;
125- return asset . url ;
126- }
127- }
128- } catch ( e ) {
129- logger . info (
130- `Looked for CodeQL bundle ${ codeQLBundleName } in ${ repository } on ${ apiURL } but got error ${ e } .` ,
131- ) ;
132- }
133- }
134- return `https://github.com/${ CODEQL_DEFAULT_ACTION_REPOSITORY } /releases/download/${ tagName } /${ codeQLBundleName } ` ;
135- }
136-
13774function tryGetBundleVersionFromTagName (
13875 tagName : string ,
13976 logger : Logger ,
@@ -712,9 +649,10 @@ export async function getCodeQLSource(
712649 ? "zstd"
713650 : "gzip" ;
714651
652+ const action = { env : getEnv ( ) , logger } ;
715653 const platform = getBundlePlatform ( ) ;
716654 const perLanguageBundleLanguage = await getPerLanguageBundleLanguage (
717- { env : getEnv ( ) , features, logger } ,
655+ { ... action , features } ,
718656 {
719657 rawLanguages,
720658 otherLanguagePacksReason,
@@ -727,11 +665,11 @@ export async function getCodeQLSource(
727665
728666 // Resolves the combined or per-language bundle URL for the requested release.
729667 const resolveBundleURL = ( language ?: BuiltInLanguage ) =>
730- getCodeQLBundleDownloadURL (
731- bundleTagName ,
668+ getCodeQLAssetDownloadURL (
669+ action ,
732670 apiDetails ,
671+ bundleTagName ,
733672 getCodeQLBundleName ( compressionMethod , platform , language ) ,
734- logger ,
735673 ) ;
736674
737675 const combinedBundleURL = await resolveBundleURL ( ) ;
0 commit comments