File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -283,6 +283,19 @@ export function isSelfHostedRunner(env: Env = getEnv()) {
283283 return env . getOptional ( ActionsEnvVars . RUNNER_ENVIRONMENT ) === "self-hosted" ;
284284}
285285
286+ /**
287+ * Whether the job is running on a runner that GitHub hosts, and whose toolcache is therefore thrown
288+ * away once the job has finished.
289+ *
290+ * Unlike `looksLikeHostedRunner`, this is based on what the service reports for the job rather than
291+ * on how the runner's filesystem happens to be laid out, so it does not match self-hosted runners
292+ * that are configured to resemble hosted ones, such as those that mount a persistent volume at
293+ * `/opt/hostedtoolcache`.
294+ */
295+ export function isGitHubHostedRunner ( env : Env = getEnv ( ) ) {
296+ return env . getOptional ( ActionsEnvVars . RUNNER_ENVIRONMENT ) === "github-hosted" ;
297+ }
298+
286299/** Determines whether the workflow trigger is `dynamic`. */
287300export function isDynamicWorkflow ( env : Env = getEnv ( ) ) : boolean {
288301 return getWorkflowEventName ( env ) === "dynamic" ;
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import * as core from "@actions/core";
55import { getOptionalInput , isDefaultSetup } from "./actions-util" ;
66import { EnvVar } from "./environment" ;
77import { Logger } from "./logging" ;
8- import { isHostedRunner , tryGetFolderBytes } from "./util" ;
8+ import { looksLikeHostedRunner , tryGetFolderBytes } from "./util" ;
99
1010/**
1111 * Returns the total size of all the specified paths.
@@ -109,7 +109,7 @@ export function getDependencyCachingEnabled(): CachingKind {
109109 if ( dependencyCaching !== undefined ) return getCachingKind ( dependencyCaching ) ;
110110
111111 // On self-hosted runners which may have dependencies installed centrally, disable caching by default
112- if ( ! isHostedRunner ( ) ) return CachingKind . None ;
112+ if ( ! looksLikeHostedRunner ( ) ) return CachingKind . None ;
113113
114114 // Disable in advanced workflows by default.
115115 if ( ! isDefaultSetup ( ) ) return CachingKind . None ;
Original file line number Diff line number Diff line change @@ -90,9 +90,8 @@ import {
9090 Result ,
9191 Success ,
9292 Failure ,
93- isHostedRunner ,
93+ looksLikeHostedRunner ,
9494} from "./util" ;
95-
9695export { type Config } from "./config/action-config" ;
9796
9897/**
@@ -938,7 +937,7 @@ export async function isTrapCachingEnabled(
938937 if ( trapCaching !== undefined ) return trapCaching === "true" ;
939938
940939 // On self-hosted runners which may have slow network access, disable TRAP caching by default.
941- if ( ! isHostedRunner ( ) ) return false ;
940+ if ( ! looksLikeHostedRunner ( ) ) return false ;
942941
943942 // If overlay analysis is enabled, then disable TRAP caching since overlay analysis supersedes it.
944943 // This change is gated behind a feature flag.
Original file line number Diff line number Diff line change @@ -842,9 +842,13 @@ export async function checkForTimeout() {
842842 * directory with the name hostedtoolcache which is present on
843843 * GitHub-hosted runners.
844844 *
845- * @returns true iff the runner is hosted by GitHub
845+ * Since this is a heuristic over how the runner happens to be named and laid out, it also matches
846+ * self-hosted runners that are configured to resemble hosted ones. Prefer
847+ * `isGitHubHostedRunner` when you need the answer the Actions service reports.
848+ *
849+ * @returns true iff the runner looks like it is hosted by GitHub
846850 */
847- export function isHostedRunner ( ) {
851+ export function looksLikeHostedRunner ( ) {
848852 return (
849853 // Name of the runner on hosted Windows runners
850854 process . env [ "RUNNER_NAME" ] ?. includes ( "Hosted Agent" ) ||
You can’t perform that action at this time.
0 commit comments