@@ -7,7 +7,7 @@ import { default as deepEqual } from "fast-deep-equal";
77import * as semver from "semver" ;
88import { v4 as uuidV4 } from "uuid" ;
99
10- import { isRunningLocalAction } from "./actions-util" ;
10+ import { isDynamicWorkflow , isRunningLocalAction } from "./actions-util" ;
1111import * as api from "./api-client" ;
1212import * as defaults from "./defaults.json" ;
1313import {
@@ -351,20 +351,37 @@ export async function getCodeQLSource(
351351 toolsInput !== undefined &&
352352 toolsInput === CODEQL_TOOLCACHE_INPUT
353353 ) {
354- // If `toolsInput === "toolcache"`, try to find the latest version of the CLI that's available in the toolcache
355- // and use that. We perform this check here since we can set `cliVersion` directly and don't want to default to
356- // the linked version.
357- logger . info (
358- `Attempting to use the latest CodeQL CLI version in the toolcache, as requested by 'tools: ${ toolsInput } '.` ,
359- ) ;
360-
361- const latestToolcacheVersion = getLatestToolcacheVersion ( logger ) ;
362- if ( latestToolcacheVersion ) {
363- cliVersion = latestToolcacheVersion ;
364- } else {
354+ let latestToolcacheVersion : string | undefined ;
355+
356+ // We only allow `toolsInput === "toolcache"` for `dynamic` events. In general, using `toolsInput === "toolcache"`
357+ // can lead to alert wobble and so it shouldn't be used for an analysis where results are intended to be uploaded.
358+ // We also allow this in test mode.
359+ const allowToolcacheValue = isDynamicWorkflow ( ) || util . isInTestMode ( ) ;
360+ if ( allowToolcacheValue ) {
361+ // If `toolsInput === "toolcache"`, try to find the latest version of the CLI that's available in the toolcache
362+ // and use that. We perform this check here since we can set `cliVersion` directly and don't want to default to
363+ // the linked version.
365364 logger . info (
366- `Found no CodeQL CLI in the toolcache, ignoring 'tools: ${ toolsInput } '.. .` ,
365+ `Attempting to use the latest CodeQL CLI version in the toolcache, as requested by 'tools: ${ toolsInput } '.` ,
367366 ) ;
367+
368+ latestToolcacheVersion = getLatestToolcacheVersion ( logger ) ;
369+ if ( latestToolcacheVersion ) {
370+ cliVersion = latestToolcacheVersion ;
371+ }
372+ }
373+
374+ if ( latestToolcacheVersion === undefined ) {
375+ if ( allowToolcacheValue ) {
376+ logger . info (
377+ `Found no CodeQL CLI in the toolcache, ignoring 'tools: ${ toolsInput } '...` ,
378+ ) ;
379+ } else {
380+ logger . warning (
381+ `Ignoring 'tools: ${ toolsInput } ' because the workflow was not triggered dynamically.` ,
382+ ) ;
383+ }
384+
368385 cliVersion = defaultCliVersion . cliVersion ;
369386 tagName = defaultCliVersion . tagName ;
370387 }
0 commit comments