Skip to content

Commit

Permalink
refactor(inputs): mv file_path to project_path
Browse files Browse the repository at this point in the history
  • Loading branch information
exiguus committed Feb 8, 2024
1 parent c2f7f42 commit bbb229e
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
id: test-action
uses: ./
with:
file_path: ../src/
project_path: ../src/

- name: Print Output Summary
id: output-summary
Expand Down
8 changes: 0 additions & 8 deletions TODO.md

This file was deleted.

16 changes: 8 additions & 8 deletions __tests__/fta.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import * as fta from '../src/fta'
import { expect } from '@jest/globals'

describe('wait.ts', () => {
it('throws on invalid file_path', async () => {
const file_path = ''
await expect(fta.run(file_path)).rejects.toThrow(
'Param `file_path` does not exist'
it('throws on invalid project_path', async () => {
const project_path = ''
await expect(fta.run(project_path)).rejects.toThrow(
'Param `project_path` does not exist'
)
})

it('throws on non-existent file_path', async () => {
const file_path = 'non-existent-file'
await expect(fta.run(file_path)).rejects.toThrow(
'Param `file_path` does not exist'
it('throws on non-existent project_path', async () => {
const project_path = 'non-existent-file'
await expect(fta.run(project_path)).rejects.toThrow(
'Param `project_path` does not exist'
)
})
})
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ branding:
# Define your inputs here

inputs:
file_path:
project_path:
description: 'Path to the project to analyze'
required: true
default: './src/'
Expand Down
4 changes: 2 additions & 2 deletions dist/fta/run.d.ts

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

20 changes: 10 additions & 10 deletions dist/index.js

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

4 changes: 2 additions & 2 deletions src/fta/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ describe('run function', () => {
expect(result).toHaveProperty('summary')
})

it('should throw an error if file_path does not exist', async () => {
it('should throw an error if project_path does not exist', async () => {
mockFsExistsSync.mockReturnValueOnce(false)

await expect(run()).rejects.toThrow('Param `file_path` does not exist')
await expect(run()).rejects.toThrow('Param `project_path` does not exist')
})

it('should throw an error if config_path does not exist', async () => {
Expand Down
14 changes: 7 additions & 7 deletions src/fta/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ import { writeOutput } from './output'
/**
* Run Fast TypeScript Analysis (FTA) on a file
* @description wrap the fta-cli package to run the fta command
* @param {string} file_path - path to the file to analyze
* @param {string} project_path - path to the file to analyze
* @param {string} config_path - path to the config file
* @param {string} output_path - path to the output file
* @param {Partial<ActionOptions>} options - options to override the config file
* @returns {Promise<ActionOutput>} - the output of the fta command
**/
export async function run(
file_path?: string,
project_path?: string,
config_path?: string,
output_path?: string,
options: Partial<ActionOptions> | null = null
): Promise<ActionOutput> {
if (!file_path) {
file_path = defaultInput.filePath
if (!project_path) {
project_path = defaultInput.filePath
}
if (!config_path) {
config_path = defaultInput.configPath
Expand All @@ -36,8 +36,8 @@ export async function run(
output_path = defaultInput.outputPath
}

if (!fs.existsSync(path.join(__dirname, file_path)))
throw new Error('Param `file_path` does not exist')
if (!fs.existsSync(path.join(__dirname, project_path)))
throw new Error('Param `project_path` does not exist')

// use --format over --json shorthand fta cli cmd
if (options?.json && options?.format !== 'json') {
Expand Down Expand Up @@ -147,7 +147,7 @@ export async function run(
// details is the output of the fta command with the format option
// details are also saved to a file in the github action
const configFile = path.join(__dirname, TMP_CONFIG_FILE)
const filePath = path.join(__dirname, file_path)
const filePath = path.join(__dirname, project_path)
const details = execSync(
`npm exec --package=fta-cli -c 'fta ${filePath} --config-path ${configFile} --format ${mappedOptions.format}'`
).toString()
Expand Down
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as fta from './fta'
*/
export async function run(): Promise<void> {
try {
const file_path: string = core.getInput('file_path')
const project_path: string = core.getInput('project_path')
const config_path: string = core.getInput('config_path')
const output_path: string = core.getInput('output_path')
// fta options
Expand All @@ -22,7 +22,7 @@ export async function run(): Promise<void> {

// Debug logs are only output if the `ACTIONS_STEP_DEBUG` secret is true
if (process.env.ACTIONS_STEP_DEBUG === 'true') {
core.debug(`Input 'file_path' is: ${file_path}`)
core.debug(`Input 'project_path' is: ${project_path}`)
core.debug(`Input 'config_path' is: ${config_path}`)
core.debug(`Input 'output_path' is: ${output_path}`)
// fta options
Expand All @@ -38,7 +38,7 @@ export async function run(): Promise<void> {
// Log the current timestamp, wait, then log the new timestamp
core.debug(new Date().toTimeString())
}
const output = await fta.run(file_path, config_path, output_path, {
const output = await fta.run(project_path, config_path, output_path, {
format,
json,
outputLimit: output_limit,
Expand Down

0 comments on commit bbb229e

Please sign in to comment.