-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR fixes the error noted in #53 where Windows-style paths were not being escaped correctly. It also cleans up the entrypoint script and some documentation/formatting.
- Loading branch information
Showing
9 changed files
with
79 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,72 @@ | ||
#!/usr/bin/env node | ||
const fs = require('fs') | ||
const path = require('path') | ||
const { execSync } = require('child_process') | ||
|
||
// Back up the environment | ||
const envBackup = { ...process.env } | ||
const pathBackup = process.env.PATH | ||
|
||
/** | ||
* This script is used to run the local action. It sets the NODE_OPTIONS | ||
* environment variable to require the bootstrap file, which sets up the | ||
* environment variable to require the bootstrap script, which sets up the | ||
* TypeScript environment for the action. | ||
*/ | ||
|
||
// Set the first argument (path to action directory) as an environment variable. | ||
// This is used in the bootstrap file to check for a `tsconfig.json`. | ||
const actionPath = process.argv[2] ? path.resolve(process.argv[2]) : '' | ||
process.env.TARGET_ACTION_PATH = actionPath | ||
|
||
// Get the other arguments, if present. Validation and error handling is done | ||
// within the package itself. | ||
const entrypoint = process.argv[3] ?? '' | ||
const dotenvFile = process.argv[4] ? path.resolve(process.argv[4]) : '' | ||
|
||
// Get the absolute path to the `@github/local-action` package. | ||
const packagePath = path.resolve(__dirname, '..') | ||
const packageIndex = path.join(packagePath, 'src', 'index.ts') | ||
|
||
// Set the NODE_OPTIONS environment variable to require the bootstrap file | ||
const options = `--require "${path.join(packagePath, 'src', 'bootstrap.js')}"` | ||
process.env.NODE_OPTIONS = process.env.NODE_OPTIONS | ||
? `${process.env.NODE_OPTIONS} ${options}` | ||
: options | ||
|
||
// Run the action | ||
const command = `npx tsx "${packageIndex}" "${actionPath}" "${entrypoint}" "${dotenvFile}"` | ||
|
||
try { | ||
execSync(command, { cwd: packagePath, stdio: 'inherit' }) | ||
} catch (error) { | ||
process.exit(error.status) | ||
} finally { | ||
// Restore the environment | ||
process.env = { ...envBackup } | ||
process.env.PATH = pathBackup | ||
function entrypoint() { | ||
// Save the current environment and path. | ||
const envBackup = { ...process.env } | ||
const pathBackup = process.env.PATH | ||
|
||
// Delete the TARGET_ACTION_PATH environment variable. | ||
delete process.env.TARGET_ACTION_PATH | ||
|
||
try { | ||
// Get the absolute path to the `@github/local-action` package. | ||
const packagePath = path.resolve(__dirname, '..') | ||
|
||
// Get the absolute path to the bootstrap script. On Windows systems, this | ||
// need to be double-escaped so the path resolves correctly. | ||
const bootstrapPath = | ||
process.platform === 'win32' | ||
? path.join(packagePath, 'src', 'bootstrap.js').replaceAll('\\', '\\\\') | ||
: path.join(packagePath, 'src', 'bootstrap.js') | ||
|
||
// Require the bootstrap script in NODE_OPTIONS. | ||
process.env.NODE_OPTIONS = process.env.NODE_OPTIONS | ||
? `${process.env.NODE_OPTIONS} --require ${bootstrapPath}` | ||
: `--require ${bootstrapPath}` | ||
|
||
// Start building the command to run local-action. | ||
let command = `npx tsx "${path.join(packagePath, 'src', 'index.ts')}"` | ||
|
||
// Process the input arguments. | ||
if (process.argv.length === 2) { | ||
// No arguments...display the help message. | ||
command += ' --help' | ||
} else { | ||
// Iterate over the arguments and build the command. | ||
for (const arg of process.argv.slice(2)) { | ||
// If the argument is a directory and TARGET_ACTION_PATH is not set, set | ||
// it to the absolute path of the directory. The first directory is the | ||
// target action path. | ||
if ( | ||
!process.env.TARGET_ACTION_PATH && | ||
fs.existsSync(path.resolve(arg)) && | ||
fs.lstatSync(path.resolve(arg)).isDirectory() | ||
) | ||
process.env.TARGET_ACTION_PATH = path.resolve(arg) | ||
|
||
// Append the argument to the command. | ||
command += ` ${arg}` | ||
} | ||
} | ||
|
||
// Run the command. | ||
execSync(command, { cwd: packagePath, stdio: 'inherit' }) | ||
} catch (error) { | ||
process.exit(error.status) | ||
} finally { | ||
// Restore the environment. | ||
process.env = { ...envBackup } | ||
process.env.PATH = pathBackup | ||
} | ||
} | ||
|
||
entrypoint() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "@github/local-action", | ||
"description": "Local Debugging for GitHub Actions", | ||
"version": "1.4.2", | ||
"version": "1.5.0", | ||
"author": "Nick Alteen <[email protected]>", | ||
"private": false, | ||
"homepage": "https://github.com/github/local-action", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters