Skip to content

Commit

Permalink
feat: add support for secrets on workflow_call
Browse files Browse the repository at this point in the history
  • Loading branch information
glungley committed Sep 3, 2024
1 parent 5f01ac1 commit 3acdb4f
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 3 deletions.
5 changes: 5 additions & 0 deletions __tests__/fixtures/workflow/action_docs_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ on:
required: false
default: LF

secrets:
notVerySecret:
description: "A secret"
required: true

jobs:
job1:
runs-on: ubuntu-latest
Expand Down
7 changes: 7 additions & 0 deletions __tests__/fixtures/workflow/all_fields_one_annotation.output
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
| `inputE` | <p>A description E</p> | `string` | `false` | `false` |


### Secrets

| name | description | required |
| --- | --- | --- |
| `notVerySecret` | <p>A secret</p> | `true` |


### Outputs

| name | description |
Expand Down
7 changes: 7 additions & 0 deletions __tests__/fixtures/workflow/all_fields_workflow.output
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
| `inputE` | <p>A description E</p> | `string` | `false` | `false` |


### Secrets

| name | description | required |
| --- | --- | --- |
| `notVerySecret` | <p>A secret</p> | `true` |


### Outputs

| name | description |
Expand Down
5 changes: 5 additions & 0 deletions __tests__/fixtures/workflow/all_fields_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ on:
required: false
default: false

secrets:
notVerySecret:
description: "A secret"
required: true

outputs:
outputA:
description: 'A description A'
Expand Down
7 changes: 7 additions & 0 deletions __tests__/fixtures/workflow/default.output
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
| `inputB` | <p>This is a multiline description</p> | `number` | `true` | `""` |


### Secrets

| name | description | required |
| --- | --- | --- |
| `notVerySecret` | <p>A secret</p> | `true` |


### Outputs

| name | description |
Expand Down
6 changes: 6 additions & 0 deletions __tests__/fixtures/workflow/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ on:
multiline description
type: number
required: true

secrets:
notVerySecret:
description: "A secret"
required: true

outputs:
outputA:
description: 'This is output A'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@
"directories": {
"dist": "lib"
}
}
}
19 changes: 17 additions & 2 deletions src/action-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface WorkflowTriggerEvent {
branches: string[];
cron: string[];
inputs: ActionInputsOutputs;
secrets: ActionInputsOutputs;
outputs: ActionInputsOutputs;
}

Expand Down Expand Up @@ -67,6 +68,7 @@ enum InputOutputType {
actionInput,
workflowInput,
actionOutput,
workflowSecret
}

const inputOutputHeaders: Record<InputOutputType, string[]> = {
Expand All @@ -79,6 +81,7 @@ const inputOutputHeaders: Record<InputOutputType, string[]> = {
"default",
],
[InputOutputType.actionOutput]: ["name", "description"],
[InputOutputType.workflowSecret]: ["name", "description", "required"],
};

const inputOutputDefaults: Record<string, string> = {
Expand Down Expand Up @@ -260,6 +263,10 @@ 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),
Expand All @@ -285,6 +292,14 @@ 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,
Expand Down Expand Up @@ -377,8 +392,8 @@ function createMarkdownSection(
return data === "" || data === undefined
? ""
: `${createMarkdownHeader(options, header)}${data}` +
`${lineBreak}` +
`${lineBreak}`;
`${lineBreak}` +
`${lineBreak}`;
}

function createMarkdownHeader(options: DefaultOptions, header: string): string {
Expand Down

0 comments on commit 3acdb4f

Please sign in to comment.