diff --git a/__tests__/action-docs-workflow.test.ts b/__tests__/action-docs-workflow.test.ts index e508f52..3f80eb1 100644 --- a/__tests__/action-docs-workflow.test.ts +++ b/__tests__/action-docs-workflow.test.ts @@ -28,6 +28,18 @@ describe("Test output", () => { expect(markdown).toEqual(expected); }); + test("With secrets.", async () => { + const markdown = await generateActionMarkdownDocs({ + sourceFile: path.join(fixtureDir, "secrets_workflow.yml"), + includeNameHeader: true, + }); + const expected = ( + readFileSync(path.join(fixtureDir, "secrets_workflow.output"), "utf-8") + ); + + expect(markdown).toEqual(expected); + }); + test("A minimal workflow definition.", async () => { const markdown = await generateActionMarkdownDocs({ sourceFile: path.join(fixtureDir, "minimal_workflow.yml"), diff --git a/__tests__/fixtures/workflow/action_docs_workflow.yml b/__tests__/fixtures/workflow/action_docs_workflow.yml index 6dc25a8..f365d4d 100644 --- a/__tests__/fixtures/workflow/action_docs_workflow.yml +++ b/__tests__/fixtures/workflow/action_docs_workflow.yml @@ -24,6 +24,11 @@ on: required: false default: LF + secrets: + notVerySecret: + description: "A secret" + required: true + jobs: job1: runs-on: ubuntu-latest diff --git a/__tests__/fixtures/workflow/all_fields_one_annotation.output b/__tests__/fixtures/workflow/all_fields_one_annotation.output index 9b5310e..ff04ee2 100644 --- a/__tests__/fixtures/workflow/all_fields_one_annotation.output +++ b/__tests__/fixtures/workflow/all_fields_one_annotation.output @@ -12,6 +12,13 @@ | `inputE` |

A description E

| `string` | `false` | `false` | +### Secrets + +| name | description | required | +| --- | --- | --- | +| `notVerySecret` |

A secret

| `true` | + + ### Outputs | name | description | diff --git a/__tests__/fixtures/workflow/all_fields_workflow.output b/__tests__/fixtures/workflow/all_fields_workflow.output index 3951fac..28da9c8 100644 --- a/__tests__/fixtures/workflow/all_fields_workflow.output +++ b/__tests__/fixtures/workflow/all_fields_workflow.output @@ -11,6 +11,13 @@ | `inputE` |

A description E

| `string` | `false` | `false` | +### Secrets + +| name | description | required | +| --- | --- | --- | +| `notVerySecret` |

A secret

| `true` | + + ### Outputs | name | description | diff --git a/__tests__/fixtures/workflow/all_fields_workflow.yml b/__tests__/fixtures/workflow/all_fields_workflow.yml index 14ceeae..6a860dc 100644 --- a/__tests__/fixtures/workflow/all_fields_workflow.yml +++ b/__tests__/fixtures/workflow/all_fields_workflow.yml @@ -26,6 +26,11 @@ on: required: false default: false + secrets: + notVerySecret: + description: "A secret" + required: true + outputs: outputA: description: 'A description A' diff --git a/__tests__/fixtures/workflow/secrets_workflow.output b/__tests__/fixtures/workflow/secrets_workflow.output new file mode 100644 index 0000000..c943a8a --- /dev/null +++ b/__tests__/fixtures/workflow/secrets_workflow.output @@ -0,0 +1,53 @@ +## A Workflow with secrets + +### Inputs + +| name | description | type | required | default | +| --- | --- | --- | --- | --- | +| `inputA` | | `string` | `false` | `This is a default` | +| `inputB` |

This is a multiline description

| `number` | `true` | `""` | + + +### Secrets + +| name | description | required | +| --- | --- | --- | +| `notVerySecret` |

A secret

| `true` | + + +### Outputs + +| name | description | +| --- | --- | +| `outputA` |

This is output A

| + + +### Usage + +```yaml +jobs: + job1: + uses: ***PROJECT***@***VERSION*** + with: + inputA: + # - Item 1 + # - foo, bar, baz + # - Item 2 + # - [github](https://github.com/) + # - **blah** + # - Item 3 + # + # Type: string + # Required: false + # Default: This is a default + + inputB: + # This is a + # multiline description + # + # Type: number + # Required: true + # Default: "" +``` + + diff --git a/__tests__/fixtures/workflow/secrets_workflow.yml b/__tests__/fixtures/workflow/secrets_workflow.yml new file mode 100644 index 0000000..be35c5d --- /dev/null +++ b/__tests__/fixtures/workflow/secrets_workflow.yml @@ -0,0 +1,46 @@ +name: 'A Workflow with secrets' +on: + push: + branches: + - main + schedule: + - cron: '*/15 * * * *' + workflow_call: + inputs: + inputA: + description: | + - Item 1 + - foo, bar, baz + - Item 2 + - [github](https://github.com/) + - **blah** + - Item 3 + type: string + default: 'This is a default' + required: false + inputB: + description: | + This is a + multiline description + type: number + required: true + + secrets: + notVerySecret: + description: "A secret" + required: true + + outputs: + outputA: + description: 'This is output A' + 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" diff --git a/__tests__/fixtures/workflow/workflow.yml b/__tests__/fixtures/workflow/workflow.yml index d2c9726..af4db33 100644 --- a/__tests__/fixtures/workflow/workflow.yml +++ b/__tests__/fixtures/workflow/workflow.yml @@ -24,6 +24,7 @@ on: multiline description type: number required: true + outputs: outputA: description: 'This is output A' diff --git a/package.json b/package.json index cf71d41..0f9d9a0 100644 --- a/package.json +++ b/package.json @@ -76,4 +76,4 @@ "directories": { "dist": "lib" } -} +} \ No newline at end of file diff --git a/src/action-docs.ts b/src/action-docs.ts index 744ff61..2c72d87 100644 --- a/src/action-docs.ts +++ b/src/action-docs.ts @@ -34,6 +34,7 @@ interface WorkflowTriggerEvent { branches: string[]; cron: string[]; inputs: ActionInputsOutputs; + secrets: ActionInputsOutputs; outputs: ActionInputsOutputs; } @@ -67,6 +68,7 @@ enum InputOutputType { actionInput, workflowInput, actionOutput, + workflowSecret, } const inputOutputHeaders: Record = { @@ -79,6 +81,7 @@ const inputOutputHeaders: Record = { "default", ], [InputOutputType.actionOutput]: ["name", "description"], + [InputOutputType.workflowSecret]: ["name", "description", "required"], }; const inputOutputDefaults: Record = { @@ -260,6 +263,7 @@ function generateWorkflowDocs( options, InputOutputType.workflowInput, ), + secrets: generateSecrets(yml.on.workflow_call?.secrets, options), outputs: generateOutputs(yml.on.workflow_call?.outputs, options), runs: "", usage: generateUsage(yml.on.workflow_call?.inputs, options, false), @@ -285,6 +289,18 @@ function generateInputs( return createMarkdownSection(options, inputMdTable, "Inputs"); } +function generateSecrets( + data: ActionInputsOutputs, + options: DefaultOptions, +): string { + const secretMdTable = createMdTable( + data, + options, + InputOutputType.workflowSecret, + ); + return createMarkdownSection(options, secretMdTable, "Secrets"); +} + function generateOutputs( data: ActionInputsOutputs, options: DefaultOptions,