diff --git a/.node-version b/.node-version index 1cc433a..9944ce6 100644 --- a/.node-version +++ b/.node-version @@ -1 +1 @@ -20.6.0 +21.6.2 diff --git a/bin/local-action b/bin/local-action index 042780c..41ca5b0 100755 --- a/bin/local-action +++ b/bin/local-action @@ -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" "$@" \ No newline at end of file +// 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) +} diff --git a/package-lock.json b/package-lock.json index 1c2d2dd..87af0de 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@github/local-action", - "version": "1.1.0", + "version": "1.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@github/local-action", - "version": "1.1.0", + "version": "1.2.0", "license": "MIT", "dependencies": { "@actions/core": "^1.10.1", diff --git a/package.json b/package.json index 598268c..cb1db40 100644 --- a/package.json +++ b/package.json @@ -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 ", "private": false, "homepage": "https://github.com/github/local-action",