Skip to content

Commit

Permalink
action.yaml Support (#61)
Browse files Browse the repository at this point in the history
This update adds support for `action.yaml` files (instead of just
`action.yml`)

Closes #52
  • Loading branch information
ncalteen authored May 2, 2024
2 parents a02f30e + e0e8c4d commit 474cb00
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 14 deletions.
11 changes: 11 additions & 0 deletions __fixtures__/typescript/success-yaml/.env.fixture
Original file line number Diff line number Diff line change
@@ -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_<name>` format (case-insensitive).
INPUT_milliseconds=2400

# Enable/disable step debug logs
ACTIONS_STEP_DEBUG=false

# Step summary output location
GITHUB_STEP_SUMMARY='summary.md'
16 changes: 16 additions & 0 deletions __fixtures__/typescript/success-yaml/action.yaml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions __fixtures__/typescript/success-yaml/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* eslint-disable @typescript-eslint/no-floating-promises */

import { run } from './main'

run()
12 changes: 12 additions & 0 deletions __fixtures__/typescript/success-yaml/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { getInput, info, setOutput, summary } from '@actions/core'

export async function run(): Promise<void> {
const myInput: string = getInput('myInput')

setOutput('myOutput', myInput)

summary.addRaw('TypeScript Action Succeeded!')
await summary.write()

info('TypeScript Action Succeeded!')
}
24 changes: 21 additions & 3 deletions __tests__/command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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')
Expand Down Expand Up @@ -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()
Expand All @@ -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()
})
Expand Down
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.4.1",
"version": "1.4.2",
"author": "Nick Alteen <[email protected]>",
"private": false,
"homepage": "https://github.com/github/local-action",
Expand Down
20 changes: 12 additions & 8 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@ export async function makeProgram(): Promise<Command> {
/* 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)
}
Expand Down

0 comments on commit 474cb00

Please sign in to comment.