@@ -485,17 +485,60 @@ export async function loadUserConfig(
485485 apiDetails : api . GitHubApiCombinedDetails ,
486486 tempDir : string ,
487487) : Promise < UserConfig > {
488- if ( isLocal ( configFile ) ) {
489- if ( configFile !== userConfigFromActionPath ( tempDir ) ) {
490- // If the config file is not generated by the Action, it should be relative to the workspace.
491- configFile = path . resolve ( workspacePath , configFile ) ;
492- // Error if the config file is now outside of the workspace
493- if ( ! ( configFile + path . sep ) . startsWith ( workspacePath + path . sep ) ) {
494- throw new ConfigurationError (
495- errorMessages . getConfigFileOutsideWorkspaceErrorMessage ( configFile ) ,
496- ) ;
488+ // Compute the path of the generated configuration file.
489+ const generatedConfigFile = userConfigFromActionPath ( tempDir ) ;
490+
491+ // A helper function to decide if the given path is relative to the workspacePath.
492+ const isWorkspaceRelative = ( fp : string ) =>
493+ ( fp + path . sep ) . startsWith ( workspacePath + path . sep ) ;
494+
495+ // We must decide if `configFile` refers to a local or remote file. Using the old remote file
496+ // address format, an address referred to a remote file if it contained '@' somewhere. The
497+ // new format makes all components, except for the repo name optional, and (in theory) a
498+ // repo name could be something like `foo.yml`. That creates ambiguity over whether a
499+ // file is local or not.
500+ let localFile = false ;
501+
502+ if ( configFile === generatedConfigFile ) {
503+ // The generated file is always local.
504+ localFile = true ;
505+ } else if ( isLocal ( configFile ) ) {
506+ // If the config file is not generated by the Action, it should be relative to the workspace.
507+ const localFilePath = path . resolve ( workspacePath , configFile ) ;
508+
509+ // Determine whether the resulting path is relative to the workspace.
510+ const workspaceRelative = isWorkspaceRelative ( localFilePath ) ;
511+
512+ // If the path is relative to the workspace and the file exists, then we use it.
513+ if ( workspaceRelative && fs . existsSync ( localFilePath ) ) {
514+ configFile = localFilePath ;
515+ localFile = true ;
516+ } else {
517+ const allowNewFormat = await actionState . features . getValue (
518+ Feature . NewRemoteFileAddresses ,
519+ ) ;
520+
521+ // If the FF for the new format is not enabled or the input path is explicitly local,
522+ // throw the old errors depending on whether the file is outside of the workspace or not.
523+ // Otherwise, we assume the path refers to a remote file.
524+ if ( isRelativePath ( configFile ) || ! allowNewFormat ) {
525+ if ( workspaceRelative ) {
526+ throw new ConfigurationError (
527+ errorMessages . getConfigFileDoesNotExistErrorMessage ( localFilePath ) ,
528+ ) ;
529+ } else {
530+ throw new ConfigurationError (
531+ errorMessages . getConfigFileOutsideWorkspaceErrorMessage (
532+ localFilePath ,
533+ ) ,
534+ ) ;
535+ }
497536 }
498537 }
538+ }
539+
540+ // Try to load the file according to whether it is local or not.
541+ if ( localFile ) {
499542 const validateConfig = await actionState . features . getValue (
500543 Feature . ValidateDbConfig ,
501544 ) ;
@@ -1321,13 +1364,6 @@ export function getLocalConfig(
13211364 configFile : string ,
13221365 validateConfig : boolean ,
13231366) : UserConfig {
1324- // Error if the file does not exist
1325- if ( ! fs . existsSync ( configFile ) ) {
1326- throw new ConfigurationError (
1327- errorMessages . getConfigFileDoesNotExistErrorMessage ( configFile ) ,
1328- ) ;
1329- }
1330-
13311367 return parseUserConfig (
13321368 logger ,
13331369 configFile ,
0 commit comments