diff --git a/__tests__/bootstrap.test.ts b/__tests__/bootstrap.test.ts index a5477fd..a3dccb8 100644 --- a/__tests__/bootstrap.test.ts +++ b/__tests__/bootstrap.test.ts @@ -2,8 +2,6 @@ import fs from 'fs' import { ResetCoreMetadata } from '../src/stubs/core-stubs' import { ResetEnvMetadata } from '../src/stubs/env-stubs' -let envBackup: { [key: string]: string | undefined } = process.env - let fs_existsSyncSpy: jest.SpyInstance let fs_readFileSyncSpy: jest.SpyInstance @@ -17,9 +15,6 @@ describe('Bootstrap', () => { // Reset metadata ResetEnvMetadata() ResetCoreMetadata() - - // Back up environment variables - envBackup = process.env }) afterEach(() => { @@ -28,9 +23,6 @@ describe('Bootstrap', () => { // Reset module imports jest.resetModules() - - // Restore environment variables - process.env = envBackup }) it('Does nothing if no target action path is provided', async () => { diff --git a/__tests__/commands/run.test.ts b/__tests__/commands/run.test.ts index 61c8fa3..212600b 100644 --- a/__tests__/commands/run.test.ts +++ b/__tests__/commands/run.test.ts @@ -10,8 +10,6 @@ const summary_writeSpy: jest.SpyInstance = jest .spyOn(summary, 'write') .mockImplementation() -let envBackup: { [key: string]: string | undefined } = process.env - describe('Command: run', () => { beforeAll(() => { // Prevent output during tests @@ -24,17 +22,11 @@ describe('Command: run', () => { // Reset metadata ResetEnvMetadata() ResetCoreMetadata() - - // Back up environment variables - envBackup = process.env }) afterEach(() => { // Reset all spies jest.resetAllMocks() - - // Restore environment variables - process.env = envBackup }) describe('TypeScript', () => { diff --git a/__tests__/stubs/core-stubs.test.ts b/__tests__/stubs/core-stubs.test.ts index acf45a1..90d35ca 100644 --- a/__tests__/stubs/core-stubs.test.ts +++ b/__tests__/stubs/core-stubs.test.ts @@ -31,8 +31,6 @@ import { EnvMeta, ResetEnvMetadata } from '../../src/stubs/env-stubs' import type { CoreMetadata } from '../../src/types' import path from 'path' -let envBackup: { [key: string]: string | undefined } = process.env - /** Empty CoreMetadata Object */ const empty: CoreMetadata = { exitCode: 0, @@ -66,17 +64,11 @@ describe('Core', () => { // Reset metadata ResetEnvMetadata() ResetCoreMetadata() - - // Back up environment variables - envBackup = process.env }) afterEach(() => { // Reset all spies jest.resetAllMocks() - - // Restore environment variables - process.env = envBackup }) describe('CoreMeta', () => { diff --git a/__tests__/stubs/env-stubs.test.ts b/__tests__/stubs/env-stubs.test.ts index 628677e..0a9eefd 100644 --- a/__tests__/stubs/env-stubs.test.ts +++ b/__tests__/stubs/env-stubs.test.ts @@ -9,11 +9,9 @@ const empty: EnvMetadata = { dotenvFile: '', entrypoint: '', env: {}, - envBackup: {}, inputs: {}, outputs: {}, - path: '', - pathBackup: '' + path: '' } describe('Env', () => { @@ -45,11 +43,9 @@ describe('Env', () => { EnvMeta.dotenvFile = '.env' EnvMeta.entrypoint = 'index.ts' EnvMeta.env = { TEST: 'test' } - EnvMeta.envBackup = { TEST: 'testBackup' } EnvMeta.inputs = { input: { description: 'test input' } } EnvMeta.outputs = { output: { description: 'test output' } } EnvMeta.path = '/usr/bin' - EnvMeta.pathBackup = '/usr/bin/backup' // Verify the updated metadata expect(EnvMeta).toMatchObject({ @@ -58,11 +54,9 @@ describe('Env', () => { dotenvFile: '.env', entrypoint: 'index.ts', env: { TEST: 'test' }, - envBackup: { TEST: 'testBackup' }, inputs: { input: { description: 'test input' } }, outputs: { output: { description: 'test output' } }, - path: '/usr/bin', - pathBackup: '/usr/bin/backup' + path: '/usr/bin' }) // Reset the metadata diff --git a/bin/local-action b/bin/local-action index 41ca5b0..81fc708 100755 --- a/bin/local-action +++ b/bin/local-action @@ -2,6 +2,10 @@ 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 @@ -35,4 +39,8 @@ try { execSync(command, { cwd: packagePath, stdio: 'inherit' }) } catch (error) { process.exit(error.status) +} finally { + // Restore the environment + process.env = { ...envBackup } + process.env.PATH = pathBackup } diff --git a/package-lock.json b/package-lock.json index 87af0de..1c4cee8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@github/local-action", - "version": "1.2.0", + "version": "1.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@github/local-action", - "version": "1.2.0", + "version": "1.3.0", "license": "MIT", "dependencies": { "@actions/core": "^1.10.1", diff --git a/package.json b/package.json index cb1db40..871cb69 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@github/local-action", "description": "Local Debugging for GitHub Actions", - "version": "1.2.0", + "version": "1.3.0", "author": "Nick Alteen ", "private": false, "homepage": "https://github.com/github/local-action", diff --git a/src/commands/run.ts b/src/commands/run.ts index 0f68aec..f6a5211 100644 --- a/src/commands/run.ts +++ b/src/commands/run.ts @@ -36,10 +36,6 @@ export async function action(): Promise { const path = await import('path') const YAML = await import('yaml') - // Back up the environment - EnvMeta.envBackup = { ...process.env } - EnvMeta.pathBackup = process.env.PATH - CoreMeta.colors = { cyan: /* istanbul ignore next */ (msg: string) => console.log(chalk.cyan(msg)), @@ -141,8 +137,4 @@ export async function action(): Promise { warning } }) - - // Reset environment and PATH - process.env = EnvMeta.envBackup - process.env.PATH = EnvMeta.pathBackup } diff --git a/src/stubs/env-stubs.ts b/src/stubs/env-stubs.ts index d937325..3f98b96 100644 --- a/src/stubs/env-stubs.ts +++ b/src/stubs/env-stubs.ts @@ -9,11 +9,9 @@ export const EnvMeta: EnvMetadata = { dotenvFile: '', entrypoint: '', env: {}, - envBackup: {}, inputs: {}, outputs: {}, - path: '', - pathBackup: '' + path: '' } /** @@ -27,9 +25,7 @@ export function ResetEnvMetadata(): void { EnvMeta.dotenvFile = '' EnvMeta.entrypoint = '' EnvMeta.env = {} - EnvMeta.envBackup = {} EnvMeta.inputs = {} EnvMeta.outputs = {} EnvMeta.path = '' - EnvMeta.pathBackup = '' } diff --git a/src/types.ts b/src/types.ts index a565b95..a3f3008 100644 --- a/src/types.ts +++ b/src/types.ts @@ -15,18 +15,9 @@ export type EnvMetadata = { TZ?: string | undefined } - /** Backup of environment variables prior to action invocation */ - envBackup: { - [key: string]: string | undefined - TZ?: string | undefined - } - /** System path */ path: string - /** Backup of system path prior to action invocation */ - pathBackup: string | undefined - /** Inputs defined in `action.yml` */ inputs: { [key: string]: Input }