From a4d2096e3a28a96b110b9aecf48aa31f2443acb7 Mon Sep 17 00:00:00 2001 From: Laura Armitage Date: Wed, 14 Feb 2024 16:24:47 +0000 Subject: [PATCH] GH-240 start adding workflow tests --- __tests__/action-docs-workflow.test.ts | 93 ++++++++------- .../workflow/all_fields_action.output | 27 ----- .../fixtures/workflow/all_fields_action.yml | 32 ----- .../fixtures/workflow/all_fields_readme.input | 75 +----------- .../workflow/all_fields_readme.output | 110 +++++++++--------- .../workflow/all_fields_workflow.output | 65 +++++++++++ .../fixtures/workflow/all_fields_workflow.yml | 45 +++++++ .../fixtures/workflow/minimal_action.output | 8 -- .../fixtures/workflow/minimal_action.yml | 5 - .../fixtures/workflow/minimal_workflow.output | 12 ++ .../fixtures/workflow/minimal_workflow.yml | 13 +++ src/action-docs.ts | 6 +- 12 files changed, 243 insertions(+), 248 deletions(-) delete mode 100644 __tests__/fixtures/workflow/all_fields_action.output delete mode 100644 __tests__/fixtures/workflow/all_fields_action.yml create mode 100644 __tests__/fixtures/workflow/all_fields_workflow.output create mode 100644 __tests__/fixtures/workflow/all_fields_workflow.yml delete mode 100644 __tests__/fixtures/workflow/minimal_action.output delete mode 100644 __tests__/fixtures/workflow/minimal_action.yml create mode 100644 __tests__/fixtures/workflow/minimal_workflow.output create mode 100644 __tests__/fixtures/workflow/minimal_workflow.yml diff --git a/__tests__/action-docs-workflow.test.ts b/__tests__/action-docs-workflow.test.ts index 529883f7..dbf24618 100644 --- a/__tests__/action-docs-workflow.test.ts +++ b/__tests__/action-docs-workflow.test.ts @@ -28,37 +28,39 @@ describe("Test output", () => { expect(markdown).toEqual(expected); }); - // test("A minimal action definition.", async () => { - // const markdown = await generateActionMarkdownDocs({ - // actionFile: path.join(fixtureDir, "minimal_action.yml"), - // }); - // const expected = ( - // readFileSync(path.join(fixtureDir, "minimal_action.output"), "utf-8") - // ); + test("A minimal workflow definition.", async () => { + const markdown = await generateActionMarkdownDocs({ + actionFile: path.join(fixtureDir, "minimal_workflow.yml"), + includeNameHeader: true, + }); + const expected = ( + readFileSync(path.join(fixtureDir, "minimal_workflow.output"), "utf-8") + ); - // expect(markdown).toEqual(expected); - // }); + expect(markdown).toEqual(expected); + }); - // test("All fields action definition.", async () => { - // const markdown = await generateActionMarkdownDocs({ - // actionFile: path.join(fixtureDir, "all_fields_action.yml"), - // }); - // const expected = ( - // readFileSync(path.join(fixtureDir, "all_fields_action.output"), "utf-8") - // ); + test("All fields workflow definition.", async () => { + const markdown = await generateActionMarkdownDocs({ + actionFile: path.join(fixtureDir, "all_fields_workflow.yml"), + includeNameHeader: true, + }); + const expected = ( + readFileSync(path.join(fixtureDir, "all_fields_workflow.output"), "utf-8") + ); - // expect(markdown).toEqual(expected); - // }); - // }); + expect(markdown).toEqual(expected); + }); +}); - // describe("Test update readme ", () => { - // test("Empty readme (all fields)", async () => { - // await testReadme({ - // actionFile: path.join(fixtureDir, "all_fields_action.yml"), - // originalReadme: path.join(fixtureDir, "all_fields_readme.input"), - // fixtureReadme: path.join(fixtureDir, "all_fields_readme.output"), - // }); - // }); +describe("Test update readme ", () => { + test("Empty readme (all fields)", async () => { + await testReadme({ + actionFile: path.join(fixtureDir, "all_fields_workflow.yml"), + originalReadme: path.join(fixtureDir, "all_fields_readme.input"), + fixtureReadme: path.join(fixtureDir, "all_fields_readme.output"), + }); + }); // test("Filled readme (all fields)", async () => { // await testReadme({ @@ -104,26 +106,26 @@ describe("Test output", () => { // fixtureReadme: path.join(fixtureDir, "two_actions_readme.output"), // }); // }); - // }); - - // describe("Test usage format", () => { - // test("Multi-line descriptions.", async () => { - // await testReadme({ - // actionFile: path.join(fixtureDir, "workflow.yml"), - // originalReadme: path.join(fixtureDir, "action_usage_readme.input"), - // fixtureReadme: path.join(fixtureDir, "action_usage_readme.output"), - // }); - // }); - - // test("With and without defaults.", async () => { - // await testReadme({ - // actionFile: path.join(fixtureDir, "all_fields_action.yml"), - // originalReadme: path.join(fixtureDir, "all_fields_usage_readme.input"), - // fixtureReadme: path.join(fixtureDir, "all_fields_usage_readme.output"), - // }); - // }); }); +// describe("Test usage format", () => { +// test("Multi-line descriptions.", async () => { +// await testReadme({ +// actionFile: path.join(fixtureDir, "workflow.yml"), +// originalReadme: path.join(fixtureDir, "action_usage_readme.input"), +// fixtureReadme: path.join(fixtureDir, "action_usage_readme.output"), +// }); +// }); + +// test("With and without defaults.", async () => { +// await testReadme({ +// actionFile: path.join(fixtureDir, "all_fields_action.yml"), +// originalReadme: path.join(fixtureDir, "all_fields_usage_readme.input"), +// fixtureReadme: path.join(fixtureDir, "all_fields_usage_readme.output"), +// }); +// }); +// }); + interface ReadmeTestFixtures { actionFile: string; originalReadme: string; @@ -142,6 +144,7 @@ async function testReadme( actionFile: files.actionFile, updateReadme: true, readmeFile: files.originalReadme, + includeNameHeader: true, ...overwriteOptions, }); diff --git a/__tests__/fixtures/workflow/all_fields_action.output b/__tests__/fixtures/workflow/all_fields_action.output deleted file mode 100644 index baf7016d..00000000 --- a/__tests__/fixtures/workflow/all_fields_action.output +++ /dev/null @@ -1,27 +0,0 @@ -## Description - -Default test - -## Inputs - -| name | description | required | default | -| --- | --- | --- | --- | -| `inputA` |

A description A

| `false` | `""` | -| `inputB` |

A description B

| `true` | `""` | -| `inputC` |

A description C

| `true` | `C` | -| `inputD` |

A description D

| `false` | `D` | -| `inputE` |

A description E

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

A description A

| -| `outputB` |

A description B

| - - -## Runs - -This action is a `node12` action. - diff --git a/__tests__/fixtures/workflow/all_fields_action.yml b/__tests__/fixtures/workflow/all_fields_action.yml deleted file mode 100644 index 4be65f94..00000000 --- a/__tests__/fixtures/workflow/all_fields_action.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: 'An Action' -description: 'Default test' -author: 'Niek Palm' -inputs: - inputA: - description: 'A description A' - required: false - inputB: - description: 'A description B' - required: true - inputC: - description: 'A description C' - required: true - default: C - inputD: - description: 'A description D' - required: false - default: D - inputE: - description: 'A description E' - required: false - default: false - -outputs: - outputA: - description: 'A description A' - outputB: - description: 'A description B' - -runs: - using: 'node12' - main: 'dist/index.js' diff --git a/__tests__/fixtures/workflow/all_fields_readme.input b/__tests__/fixtures/workflow/all_fields_readme.input index e535c7d2..ceae792b 100644 --- a/__tests__/fixtures/workflow/all_fields_readme.input +++ b/__tests__/fixtures/workflow/all_fields_readme.input @@ -1,74 +1,7 @@ - -## An Action - + - -### Description + -Default test - + - -### Usage - -```yaml -- uses: npalm/action-docs@v1 - with: - inputA: - # A description A - # - # Required: false - # Default: "" - - inputB: - # A description B - # - # Required: true - # Default: "" - - inputC: - # A description C - # - # Required: true - # Default: C - - inputD: - # A description D - # - # Required: false - # Default: D - - inputE: - # A description E - # - # Required: false - # Default: false -``` - - - -### Inputs - -| name | description | required | default | -| --- | --- | --- | --- | -| `inputA` |

A description A

| `false` | `""` | -| `inputB` |

A description B

| `true` | `""` | -| `inputC` |

A description C

| `true` | `C` | -| `inputD` |

A description D

| `false` | `D` | -| `inputE` |

A description E

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

A description A

| -| `outputB` |

A description B

| - - - -### Runs - -This action is a `node12` action. - + \ No newline at end of file diff --git a/__tests__/fixtures/workflow/all_fields_readme.output b/__tests__/fixtures/workflow/all_fields_readme.output index 028e0233..a39e1cbb 100644 --- a/__tests__/fixtures/workflow/all_fields_readme.output +++ b/__tests__/fixtures/workflow/all_fields_readme.output @@ -1,74 +1,70 @@ - + +## A Workflow + - - - -## Description - -Default test - - - -## Usage + +### Usage ```yaml -- uses: npalm/action-docs@v1 - with: - inputA: - # A description A - # - # Required: false - # Default: "" +jobs: + job1: + uses: ***PROJECT***@***VERSION*** + with: + inputA: + # A description A + # + # Type: string + # Required: false + # Default: "" - inputB: - # A description B - # - # Required: true - # Default: "" + inputB: + # A description B + # + # Type: string + # Required: true + # Default: "" - inputC: - # A description C - # - # Required: true - # Default: C + inputC: + # A description C + # + # Type: string + # Required: true + # Default: C - inputD: - # A description D - # - # Required: false - # Default: D + inputD: + # A description D + # + # Type: string + # Required: false + # Default: D - inputE: - # A description E - # - # Required: false - # Default: false + inputE: + # A description E + # + # Type: string + # Required: false + # Default: false ``` - + - -## Inputs + +### Inputs -| name | description | required | default | -| --- | --- | --- | --- | -| `inputA` |

A description A

| `false` | `""` | -| `inputB` |

A description B

| `true` | `""` | -| `inputC` |

A description C

| `true` | `C` | -| `inputD` |

A description D

| `false` | `D` | -| `inputE` |

A description E

| `false` | `false` | - +| name | description | type | required | default | +| --- | --- | --- | --- | --- | +| `inputA` |

A description A

| `string` | `false` | `""` | +| `inputB` |

A description B

| `string` | `true` | `""` | +| `inputC` |

A description C

| `string` | `true` | `C` | +| `inputD` |

A description D

| `string` | `false` | `D` | +| `inputE` |

A description E

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

A description A

| | `outputB` |

A description B

| - - - -## Runs + -This action is a `node12` action. - diff --git a/__tests__/fixtures/workflow/all_fields_workflow.output b/__tests__/fixtures/workflow/all_fields_workflow.output new file mode 100644 index 00000000..3951facb --- /dev/null +++ b/__tests__/fixtures/workflow/all_fields_workflow.output @@ -0,0 +1,65 @@ +## A Workflow + +### Inputs + +| name | description | type | required | default | +| --- | --- | --- | --- | --- | +| `inputA` |

A description A

| `string` | `false` | `""` | +| `inputB` |

A description B

| `string` | `true` | `""` | +| `inputC` |

A description C

| `string` | `true` | `C` | +| `inputD` |

A description D

| `string` | `false` | `D` | +| `inputE` |

A description E

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

A description A

| +| `outputB` |

A description B

| + + +### Usage + +```yaml +jobs: + job1: + uses: ***PROJECT***@***VERSION*** + with: + inputA: + # A description A + # + # Type: string + # Required: false + # Default: "" + + inputB: + # A description B + # + # Type: string + # Required: true + # Default: "" + + inputC: + # A description C + # + # Type: string + # Required: true + # Default: C + + inputD: + # A description D + # + # Type: string + # Required: false + # Default: D + + inputE: + # A description E + # + # Type: string + # Required: false + # Default: false +``` + + diff --git a/__tests__/fixtures/workflow/all_fields_workflow.yml b/__tests__/fixtures/workflow/all_fields_workflow.yml new file mode 100644 index 00000000..53f74c2f --- /dev/null +++ b/__tests__/fixtures/workflow/all_fields_workflow.yml @@ -0,0 +1,45 @@ +name: 'A Workflow' +on: + workflow_call: + inputs: + inputA: + description: 'A description A' + type: string + required: false + inputB: + description: 'A description B' + type: string + required: true + inputC: + description: 'A description C' + type: string + required: true + default: C + inputD: + description: 'A description D' + type: string + required: false + default: D + inputE: + description: 'A description E' + type: string + required: false + default: false + + outputs: + outputA: + description: 'A description A' + value: ${{ jobs.job1.outputs.step_output1 }} + outputB: + description: 'A description B' + value: ${{ jobs.job1.outputs.step_output1 }} + +jobs: + job1: + runs-on: ubuntu-latest + outputs: + step_output1: ${{ steps.step1.outputs.test }} + steps: + - name: 'Step 1' + id: step1 + run: echo "test=some value" >> "$GITHUB_OUTPUT" \ No newline at end of file diff --git a/__tests__/fixtures/workflow/minimal_action.output b/__tests__/fixtures/workflow/minimal_action.output deleted file mode 100644 index 9c84e492..00000000 --- a/__tests__/fixtures/workflow/minimal_action.output +++ /dev/null @@ -1,8 +0,0 @@ -## Description - -Default test - -## Runs - -This action is a `docker` action. - diff --git a/__tests__/fixtures/workflow/minimal_action.yml b/__tests__/fixtures/workflow/minimal_action.yml deleted file mode 100644 index 6c3d3045..00000000 --- a/__tests__/fixtures/workflow/minimal_action.yml +++ /dev/null @@ -1,5 +0,0 @@ -name: 'An Action' -description: 'Default test' -runs: - using: 'docker' - image: 'Dockerfile' \ No newline at end of file diff --git a/__tests__/fixtures/workflow/minimal_workflow.output b/__tests__/fixtures/workflow/minimal_workflow.output new file mode 100644 index 00000000..57a3cd2c --- /dev/null +++ b/__tests__/fixtures/workflow/minimal_workflow.output @@ -0,0 +1,12 @@ +## A Workflow + +### Usage + +```yaml +jobs: + job1: + uses: ***PROJECT***@***VERSION*** + with: +``` + + diff --git a/__tests__/fixtures/workflow/minimal_workflow.yml b/__tests__/fixtures/workflow/minimal_workflow.yml new file mode 100644 index 00000000..4e8c390a --- /dev/null +++ b/__tests__/fixtures/workflow/minimal_workflow.yml @@ -0,0 +1,13 @@ +name: 'A Workflow' +on: + workflow_call: + +jobs: + job1: + runs-on: ubuntu-latest + outputs: + step_output1: ${{ steps.step1.outputs.test }} + steps: + - name: 'Step 1' + id: step1 + run: echo "test=some value" >> "$GITHUB_OUTPUT" \ No newline at end of file diff --git a/src/action-docs.ts b/src/action-docs.ts index 09bdf467..9c3115e7 100644 --- a/src/action-docs.ts +++ b/src/action-docs.ts @@ -248,13 +248,13 @@ function generateWorkflowDocs( return { header: generateHeader(yml, options), inputs: generateInputs( - yml.on.workflow_call.inputs, + yml.on.workflow_call?.inputs, options, InputOutputType.workflowInput, ), - outputs: generateOutputs(yml.on.workflow_call.outputs, options), + outputs: generateOutputs(yml.on.workflow_call?.outputs, options), runs: "", - usage: generateUsage(yml.on.workflow_call.inputs, options, false), + usage: generateUsage(yml.on.workflow_call?.inputs, options, false), }; }