From 825b988465b21bfb62909773d20cd586f32473e8 Mon Sep 17 00:00:00 2001 From: George Lungley Date: Tue, 9 Jul 2024 17:48:35 +0100 Subject: [PATCH] fix: enable paths in usage --- __tests__/action-docs-action.test.ts | 13 +++++ .../fixtures/action/action_deprecated.output | 2 +- .../action/action_usage_readme.output | 2 +- .../fixtures/action/all_fields_action.output | 2 +- .../action/all_fields_action_toc3_cli.output | 2 +- .../action/all_fields_one_annotation.output | 2 +- .../fixtures/action/all_fields_readme.output | 2 +- .../action/all_fields_usage_readme.output | 2 +- .../action/default-with-header.output | 2 +- __tests__/fixtures/action/default.output | 2 +- .../fixtures/action/default_readme.input | 11 ++++ .../fixtures/action/default_readme.output | 58 +++++++++++++++++++ .../fixtures/action/minimal_action.output | 2 +- .../workflow/all_fields_one_annotation.output | 2 +- .../workflow/all_fields_readme.output | 2 +- .../workflow/all_fields_usage_readme.output | 2 +- .../workflow/all_fields_workflow.output | 2 +- __tests__/fixtures/workflow/default.output | 2 +- .../fixtures/workflow/minimal_workflow.output | 2 +- .../fixtures/workflow/secrets_workflow.output | 2 +- .../workflow/workflow_usage_readme.output | 2 +- src/action-docs.ts | 12 +++- 22 files changed, 109 insertions(+), 21 deletions(-) create mode 100644 __tests__/fixtures/action/default_readme.input create mode 100644 __tests__/fixtures/action/default_readme.output diff --git a/__tests__/action-docs-action.test.ts b/__tests__/action-docs-action.test.ts index 0c867e2c..17d608b8 100644 --- a/__tests__/action-docs-action.test.ts +++ b/__tests__/action-docs-action.test.ts @@ -60,6 +60,19 @@ describe("Test output", () => { }); describe("Test update readme ", () => { + test("With defaults.", async () => { + await testReadme( + { + sourceFile: "action.yml", // Default value + originalReadme: path.join(fixtureDir, "default_readme.input"), + fixtureReadme: path.join(fixtureDir, "default_readme.output"), + }, + { + includeNameHeader: true, + }, + ); + }); + test("Empty readme (all fields)", async () => { await testReadme( { diff --git a/__tests__/fixtures/action/action_deprecated.output b/__tests__/fixtures/action/action_deprecated.output index 6a1de0e6..29e65ac5 100644 --- a/__tests__/fixtures/action/action_deprecated.output +++ b/__tests__/fixtures/action/action_deprecated.output @@ -12,7 +12,7 @@ Default test ### Usage ```yaml -- uses: npalm/action-docs@v1 +- uses: npalm/action-docs/__tests__/fixtures/action/all_fields_action.yml@v1 with: inputA: # A description A diff --git a/__tests__/fixtures/action/action_usage_readme.output b/__tests__/fixtures/action/action_usage_readme.output index acceeb00..797942f1 100644 --- a/__tests__/fixtures/action/action_usage_readme.output +++ b/__tests__/fixtures/action/action_usage_readme.output @@ -2,7 +2,7 @@ ## Usage ```yaml -- uses: npalm/action-docs@v1 +- uses: npalm/action-docs/__tests__/fixtures/action/action.yml@v1 with: inputA: # - Item 1 diff --git a/__tests__/fixtures/action/all_fields_action.output b/__tests__/fixtures/action/all_fields_action.output index 85b5296a..a95a3a70 100644 --- a/__tests__/fixtures/action/all_fields_action.output +++ b/__tests__/fixtures/action/all_fields_action.output @@ -28,7 +28,7 @@ This action is a `node12` action. ## Usage ```yaml -- uses: ***PROJECT***@***VERSION*** +- uses: ***PROJECT******SOURCE_FILE***@***VERSION*** with: inputA: # A description A diff --git a/__tests__/fixtures/action/all_fields_action_toc3_cli.output b/__tests__/fixtures/action/all_fields_action_toc3_cli.output index 495be5fb..a16e1a12 100644 --- a/__tests__/fixtures/action/all_fields_action_toc3_cli.output +++ b/__tests__/fixtures/action/all_fields_action_toc3_cli.output @@ -28,7 +28,7 @@ This action is a `node12` action. ### Usage ```yaml -- uses: ***PROJECT***@***VERSION*** +- uses: ***PROJECT******SOURCE_FILE***@***VERSION*** with: inputA: # A description A diff --git a/__tests__/fixtures/action/all_fields_one_annotation.output b/__tests__/fixtures/action/all_fields_one_annotation.output index 4d5beed2..d2251657 100644 --- a/__tests__/fixtures/action/all_fields_one_annotation.output +++ b/__tests__/fixtures/action/all_fields_one_annotation.output @@ -29,7 +29,7 @@ This action is a `node12` action. ## Usage ```yaml -- uses: npalm/action-docs@v1 +- uses: npalm/action-docs/__tests__/fixtures/action/all_fields_action.yml@v1 with: inputA: # A description A diff --git a/__tests__/fixtures/action/all_fields_readme.output b/__tests__/fixtures/action/all_fields_readme.output index 1af27309..45f28798 100644 --- a/__tests__/fixtures/action/all_fields_readme.output +++ b/__tests__/fixtures/action/all_fields_readme.output @@ -12,7 +12,7 @@ Default test ### Usage ```yaml -- uses: npalm/action-docs@v1 +- uses: npalm/action-docs/__tests__/fixtures/action/all_fields_action.yml@v1 with: inputA: # A description A diff --git a/__tests__/fixtures/action/all_fields_usage_readme.output b/__tests__/fixtures/action/all_fields_usage_readme.output index 0bd7c8cc..5ba4573c 100644 --- a/__tests__/fixtures/action/all_fields_usage_readme.output +++ b/__tests__/fixtures/action/all_fields_usage_readme.output @@ -2,7 +2,7 @@ ## Usage ```yaml -- uses: npalm/action-docs@v1 +- uses: npalm/action-docs/__tests__/fixtures/action/all_fields_action.yml@v1 with: inputA: # A description A diff --git a/__tests__/fixtures/action/default-with-header.output b/__tests__/fixtures/action/default-with-header.output index e863447e..581f13d9 100644 --- a/__tests__/fixtures/action/default-with-header.output +++ b/__tests__/fixtures/action/default-with-header.output @@ -26,7 +26,7 @@ This action is a `node12` action. ### Usage ```yaml -- uses: ***PROJECT***@***VERSION*** +- uses: ***PROJECT******SOURCE_FILE***@***VERSION*** with: inputA: # - Item 1 diff --git a/__tests__/fixtures/action/default.output b/__tests__/fixtures/action/default.output index c6c42e36..39f4a514 100644 --- a/__tests__/fixtures/action/default.output +++ b/__tests__/fixtures/action/default.output @@ -24,7 +24,7 @@ This action is a `node12` action. ## Usage ```yaml -- uses: ***PROJECT***@***VERSION*** +- uses: ***PROJECT******SOURCE_FILE***@***VERSION*** with: inputA: # - Item 1 diff --git a/__tests__/fixtures/action/default_readme.input b/__tests__/fixtures/action/default_readme.input new file mode 100644 index 00000000..fb618fbd --- /dev/null +++ b/__tests__/fixtures/action/default_readme.input @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/__tests__/fixtures/action/default_readme.output b/__tests__/fixtures/action/default_readme.output new file mode 100644 index 00000000..a72ac355 --- /dev/null +++ b/__tests__/fixtures/action/default_readme.output @@ -0,0 +1,58 @@ + +## An Action + + + +### Description + +Default test + + + +### Inputs + +| name | description | required | default | +| --- | --- | --- | --- | +| `inputA` | | `false` | `test` | +| `inputB` |

This is a multiline description

| `false` | `test` | + + + +### Outputs + +| name | description | +| --- | --- | +| `outputA` |

A description

| + + + +### Runs + +This action is a `node12` action. + + + +### Usage + +```yaml +- uses: npalm/action-docs@v1 + with: + inputA: + # - Item 1 + # - foo, bar, baz + # - Item 2 + # - [github](https://github.com/) + # - **blah** + # - Item 3 + # + # Required: false + # Default: test + + inputB: + # This is a + # multiline description + # + # Required: false + # Default: test +``` + diff --git a/__tests__/fixtures/action/minimal_action.output b/__tests__/fixtures/action/minimal_action.output index a454489e..d09db61a 100644 --- a/__tests__/fixtures/action/minimal_action.output +++ b/__tests__/fixtures/action/minimal_action.output @@ -9,7 +9,7 @@ This action is a `docker` action. ## Usage ```yaml -- uses: ***PROJECT***@***VERSION*** +- uses: ***PROJECT******SOURCE_FILE***@***VERSION*** ``` diff --git a/__tests__/fixtures/workflow/all_fields_one_annotation.output b/__tests__/fixtures/workflow/all_fields_one_annotation.output index ff04ee20..a809af1b 100644 --- a/__tests__/fixtures/workflow/all_fields_one_annotation.output +++ b/__tests__/fixtures/workflow/all_fields_one_annotation.output @@ -32,7 +32,7 @@ ```yaml jobs: job1: - uses: npalm/action-docs@v1 + uses: npalm/action-docs/__tests__/fixtures/workflow/all_fields_workflow.yml@v1 with: inputA: # A description A diff --git a/__tests__/fixtures/workflow/all_fields_readme.output b/__tests__/fixtures/workflow/all_fields_readme.output index b1d23544..c9d9ddf7 100644 --- a/__tests__/fixtures/workflow/all_fields_readme.output +++ b/__tests__/fixtures/workflow/all_fields_readme.output @@ -8,7 +8,7 @@ ```yaml jobs: job1: - uses: npalm/action-docs@v1 + uses: npalm/action-docs/__tests__/fixtures/workflow/all_fields_workflow.yml@v1 with: inputA: # A description A diff --git a/__tests__/fixtures/workflow/all_fields_usage_readme.output b/__tests__/fixtures/workflow/all_fields_usage_readme.output index 36345839..59ce62f3 100644 --- a/__tests__/fixtures/workflow/all_fields_usage_readme.output +++ b/__tests__/fixtures/workflow/all_fields_usage_readme.output @@ -4,7 +4,7 @@ ```yaml jobs: job1: - uses: npalm/action-docs@v1 + uses: npalm/action-docs/__tests__/fixtures/workflow/all_fields_workflow.yml@v1 with: inputA: # A description A diff --git a/__tests__/fixtures/workflow/all_fields_workflow.output b/__tests__/fixtures/workflow/all_fields_workflow.output index 28da9c84..9cd07b64 100644 --- a/__tests__/fixtures/workflow/all_fields_workflow.output +++ b/__tests__/fixtures/workflow/all_fields_workflow.output @@ -31,7 +31,7 @@ ```yaml jobs: job1: - uses: ***PROJECT***@***VERSION*** + uses: ***PROJECT******SOURCE_FILE***@***VERSION*** with: inputA: # A description A diff --git a/__tests__/fixtures/workflow/default.output b/__tests__/fixtures/workflow/default.output index 188e767e..ab9fc5f0 100644 --- a/__tests__/fixtures/workflow/default.output +++ b/__tests__/fixtures/workflow/default.output @@ -20,7 +20,7 @@ ```yaml jobs: job1: - uses: ***PROJECT***@***VERSION*** + uses: ***PROJECT******SOURCE_FILE***@***VERSION*** with: inputA: # - Item 1 diff --git a/__tests__/fixtures/workflow/minimal_workflow.output b/__tests__/fixtures/workflow/minimal_workflow.output index 18e802cb..af81ebca 100644 --- a/__tests__/fixtures/workflow/minimal_workflow.output +++ b/__tests__/fixtures/workflow/minimal_workflow.output @@ -5,7 +5,7 @@ ```yaml jobs: job1: - uses: ***PROJECT***@***VERSION*** + uses: ***PROJECT******SOURCE_FILE***@***VERSION*** ``` diff --git a/__tests__/fixtures/workflow/secrets_workflow.output b/__tests__/fixtures/workflow/secrets_workflow.output index c943a8ae..bedefd0c 100644 --- a/__tests__/fixtures/workflow/secrets_workflow.output +++ b/__tests__/fixtures/workflow/secrets_workflow.output @@ -27,7 +27,7 @@ ```yaml jobs: job1: - uses: ***PROJECT***@***VERSION*** + uses: ***PROJECT******SOURCE_FILE***@***VERSION*** with: inputA: # - Item 1 diff --git a/__tests__/fixtures/workflow/workflow_usage_readme.output b/__tests__/fixtures/workflow/workflow_usage_readme.output index e2b46d6b..d0352665 100644 --- a/__tests__/fixtures/workflow/workflow_usage_readme.output +++ b/__tests__/fixtures/workflow/workflow_usage_readme.output @@ -4,7 +4,7 @@ ```yaml jobs: job1: - uses: npalm/action-docs@v1 + uses: npalm/action-docs/__tests__/fixtures/workflow/workflow.yml@v1 with: inputA: # - Item 1 diff --git a/src/action-docs.ts b/src/action-docs.ts index 2c72d87c..e5b7b0bd 100644 --- a/src/action-docs.ts +++ b/src/action-docs.ts @@ -121,21 +121,23 @@ function createMdTable( function createMdCodeBlock( data: ActionInputsOutputs, options: DefaultOptions, - isAction = true, + isAction: boolean, ): string { let codeBlockArray = ["```yaml"]; let indent = ""; if (isAction) { - codeBlockArray.push("- uses: ***PROJECT***@***VERSION***"); + codeBlockArray.push("- uses: ***PROJECT******SOURCE_FILE***@***VERSION***"); indent += " "; } else { codeBlockArray.push("jobs:"); indent += " "; codeBlockArray.push(`${indent}job1:`); indent += " "; - codeBlockArray.push(`${indent}uses: ***PROJECT***@***VERSION***`); + codeBlockArray.push( + `${indent}uses: ***PROJECT******SOURCE_FILE***@***VERSION***`, + ); } const inputs = getInputOutput( @@ -368,6 +370,10 @@ async function updateReadme( .replace( "***VERSION***", matchProjectVersion ? matchProjectVersion[2] : "", + ) + .replace( + "***SOURCE_FILE***", + sourceFile !== defaultOptions.sourceFile ? `/${sourceFile}` : "", ); await replaceInFile.replaceInFile({