Skip to content

Commit

Permalink
Switch to Node.js entrypoint (#36)
Browse files Browse the repository at this point in the history
The bash entrypoint was causing issues trying to resolve paths, so this
approach attempts to prevent that from being an issue across platforms.
  • Loading branch information
ncalteen authored Feb 23, 2024
2 parents c244633 + f096dea commit 0672ca7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.6.0
21.6.2
44 changes: 35 additions & 9 deletions bin/local-action
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
#!/usr/bin/env bash
#!/usr/bin/env node
const path = require('path')
const { execSync } = require('child_process')

# 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
# TypeScript environment for the action.
/**
* 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
* TypeScript environment for the action.
*/

# Set the first argument (local path to action) as an env var. This is used
# in the bootstrap file to check for a `tsconfig.json`.
export TARGET_ACTION_PATH="$1"
// 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

# Set the NODE_OPTIONS environment variable to require the bootstrap file
NODE_OPTIONS='--require "./src/bootstrap.js"' npx tsx "./src/index.ts" "$@"
// 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)
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
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.1.0",
"version": "1.2.0",
"author": "Nick Alteen <[email protected]>",
"private": false,
"homepage": "https://github.com/github/local-action",
Expand Down

0 comments on commit 0672ca7

Please sign in to comment.