From e8e4a361869191acf53983ac8d1e30b8bddfdf3e Mon Sep 17 00:00:00 2001 From: Nick Alteen Date: Thu, 2 May 2024 11:38:24 -0400 Subject: [PATCH 1/2] Add test fixture using action.yaml --- .../typescript/success-yaml/.env.fixture | 11 +++++++++++ __fixtures__/typescript/success-yaml/action.yaml | 16 ++++++++++++++++ .../typescript/success-yaml/src/index.ts | 5 +++++ __fixtures__/typescript/success-yaml/src/main.ts | 12 ++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 __fixtures__/typescript/success-yaml/.env.fixture create mode 100644 __fixtures__/typescript/success-yaml/action.yaml create mode 100644 __fixtures__/typescript/success-yaml/src/index.ts create mode 100644 __fixtures__/typescript/success-yaml/src/main.ts diff --git a/__fixtures__/typescript/success-yaml/.env.fixture b/__fixtures__/typescript/success-yaml/.env.fixture new file mode 100644 index 0000000..f1b3926 --- /dev/null +++ b/__fixtures__/typescript/success-yaml/.env.fixture @@ -0,0 +1,11 @@ +# Do not commit your actual .env file to Git! This may contain secrets or other +# private information. + +# GitHub Actions inputs should follow `INPUT_` format (case-insensitive). +INPUT_milliseconds=2400 + +# Enable/disable step debug logs +ACTIONS_STEP_DEBUG=false + +# Step summary output location +GITHUB_STEP_SUMMARY='summary.md' \ No newline at end of file diff --git a/__fixtures__/typescript/success-yaml/action.yaml b/__fixtures__/typescript/success-yaml/action.yaml new file mode 100644 index 0000000..3c183c0 --- /dev/null +++ b/__fixtures__/typescript/success-yaml/action.yaml @@ -0,0 +1,16 @@ +name: TypeScript (Success) +description: This action returns without error + +inputs: + myInput: + description: An input + required: true + default: 'default value' + +outputs: + myOutput: + description: An output + +runs: + using: node20 + main: dist/index.js diff --git a/__fixtures__/typescript/success-yaml/src/index.ts b/__fixtures__/typescript/success-yaml/src/index.ts new file mode 100644 index 0000000..1c5eb3f --- /dev/null +++ b/__fixtures__/typescript/success-yaml/src/index.ts @@ -0,0 +1,5 @@ +/* eslint-disable @typescript-eslint/no-floating-promises */ + +import { run } from './main' + +run() diff --git a/__fixtures__/typescript/success-yaml/src/main.ts b/__fixtures__/typescript/success-yaml/src/main.ts new file mode 100644 index 0000000..4500783 --- /dev/null +++ b/__fixtures__/typescript/success-yaml/src/main.ts @@ -0,0 +1,12 @@ +import { getInput, info, setOutput, summary } from '@actions/core' + +export async function run(): Promise { + const myInput: string = getInput('myInput') + + setOutput('myOutput', myInput) + + summary.addRaw('TypeScript Action Succeeded!') + await summary.write() + + info('TypeScript Action Succeeded!') +} From 27df78bc0fb06a55bc54a4db845dff2b562f3d2f Mon Sep 17 00:00:00 2001 From: Nick Alteen Date: Thu, 2 May 2024 11:38:49 -0400 Subject: [PATCH 2/2] Add support for action.yaml --- __tests__/command.test.ts | 24 +++++++++++++++++++++--- package-lock.json | 4 ++-- package.json | 2 +- src/command.ts | 20 ++++++++++++-------- 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/__tests__/command.test.ts b/__tests__/command.test.ts index 8767403..c40ac27 100644 --- a/__tests__/command.test.ts +++ b/__tests__/command.test.ts @@ -48,7 +48,7 @@ describe('Commmand', () => { ) }) - it('Runs if all arguments are provided', async () => { + it('Runs if all arguments are provided (action.yml)', async () => { await ( await makeProgram() ).parseAsync( @@ -66,6 +66,24 @@ describe('Commmand', () => { expect(run_actionSpy).toHaveBeenCalled() }) + it('Runs if all arguments are provided (action.yaml)', async () => { + await ( + await makeProgram() + ).parseAsync( + [ + './__fixtures__/typescript/success-yaml', + 'src/index.ts', + './__fixtures__/typescript/success-yaml/.env.fixture' + ], + { + from: 'user' + } + ) + + expect(process_exitSpy).not.toHaveBeenCalled() + expect(run_actionSpy).toHaveBeenCalled() + }) + it('Exits if no path argument is provided', async () => { process_stderrSpy = jest .spyOn(process.stderr, 'write') @@ -142,7 +160,7 @@ describe('Commmand', () => { process_stderrSpy.mockRestore() }) - it('Exits if the action path does not contain an action.yml', async () => { + it('Exits if the action path does not contain an action.yml or action.yaml', async () => { process_stderrSpy = jest .spyOn(process.stderr, 'write') .mockImplementation() @@ -154,7 +172,7 @@ describe('Commmand', () => { from: 'user' } ) - ).rejects.toThrow('Path must contain an action.yml file') + ).rejects.toThrow('Path must contain an action.yml / action.yaml file') process_stderrSpy.mockRestore() }) diff --git a/package-lock.json b/package-lock.json index f527f90..1677302 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@github/local-action", - "version": "1.4.1", + "version": "1.4.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@github/local-action", - "version": "1.4.1", + "version": "1.4.2", "license": "MIT", "dependencies": { "@actions/core": "^1.10.1", diff --git a/package.json b/package.json index b0b0465..54a5daa 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@github/local-action", "description": "Local Debugging for GitHub Actions", - "version": "1.4.1", + "version": "1.4.2", "author": "Nick Alteen ", "private": false, "homepage": "https://github.com/github/local-action", diff --git a/src/command.ts b/src/command.ts index 301ec63..0ab23d7 100644 --- a/src/command.ts +++ b/src/command.ts @@ -33,15 +33,19 @@ export async function makeProgram(): Promise { /* eslint-enable @typescript-eslint/no-unsafe-member-access */ } - const actionFile: string = path.resolve(actionPath, 'action.yml') - - // Confirm there is an `action.yml` in the directory - if (!fs.existsSync(actionFile)) - throw new InvalidArgumentError('Path must contain an action.yml file') - - // Save the action path and file to environment metadata + // Save the action path to environment metadata EnvMeta.actionPath = actionPath - EnvMeta.actionFile = path.resolve(EnvMeta.actionPath, 'action.yml') + + // Confirm there is an `action.yml` or `action.yaml` in the directory and + // save the path to environment metadata + if (fs.existsSync(path.resolve(actionPath, 'action.yml'))) + EnvMeta.actionFile = path.resolve(EnvMeta.actionPath, 'action.yml') + else if (fs.existsSync(path.resolve(actionPath, 'action.yaml'))) + EnvMeta.actionFile = path.resolve(EnvMeta.actionPath, 'action.yaml') + else + throw new InvalidArgumentError( + 'Path must contain an action.yml / action.yaml file' + ) return path.resolve(value) }