Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions action.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ const replaceEnvVars = (str) => {
/\$\{([a-zA-Z0-9_]+):\+:\$[a-zA-Z0-9_]+\}/g,
(_, key) => ((v) => v ? `:${v}` : "")(process.env[key]),
)
// handles ${FOO:-bar} > $FOO || "bar"
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment states ${FOO:-bar} > $FOO || "bar" but this is misleading. In bash, ${FOO:-bar} means "use $FOO if set and non-empty, otherwise use bar". The implementation uses the JavaScript || operator which has different semantics—it will also use the default for falsy values like 0, false, or empty string (though empty string matches bash behavior).

Consider updating the comment to be more accurate:

// handles ${FOO:-bar} - uses default if FOO is unset or falsy

Or if you want to strictly match bash behavior (use default only when unset or empty):

// handles ${FOO:-bar} - uses default if FOO is unset or empty (bash-style)
Suggested change
// handles ${FOO:-bar} > $FOO || "bar"
// handles ${FOO:-bar} - uses default if FOO is unset or falsy

Copilot uses AI. Check for mistakes.
.replaceAll(
/\$\{([a-zA-Z0-9_]+):-([^}]*)\}/g,
(_, key, defaultVal) => process.env[key] || defaultVal,
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of || operator here may not correctly handle environment variables that are set to an empty string. In bash, ${FOO:-bar} uses the default value when FOO is unset or empty, but process.env[key] || defaultVal will use the default value for any falsy value including 0 or false.

Consider using ?? defaultVal instead to match bash behavior more closely, or explicitly check for undefined/null:

(_, key, defaultVal) => (process.env[key] ?? defaultVal)

However, note that even ?? won't treat empty strings the same as bash does. For exact bash parity, you'd need:

(_, key, defaultVal) => (process.env[key] === undefined || process.env[key] === '') ? defaultVal : process.env[key]
Suggested change
(_, key, defaultVal) => process.env[key] || defaultVal,
(_, key, defaultVal) => (process.env[key] === undefined || process.env[key] === '') ? defaultVal : process.env[key],

Copilot uses AI. Check for mistakes.
)
.replaceAll(/\$\{([a-zA-Z0-9_]+)\}/g, (_, key) => process.env[key] ?? "")
.replaceAll(/\$([a-zA-Z0-9_]+)/g, (_, key) => process.env[key] ?? "");
return value;
Expand Down
5 changes: 4 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"pkgx": "deno^2.1",
"lint": {
"include": ["src/", "./app.ts"],
"exclude": ["**/*.test.ts", "./action.js"]
"exclude": ["**/*.test.ts", "./action.js"],
"rules": {
"exclude": ["no-import-prefix", "no-unversioned-import"]
}
},
"test": {
"include": ["src/"]
Expand Down