Skip to content

Commit

Permalink
feat: add support for secrets on workflow_call (#658)
Browse files Browse the repository at this point in the history
  • Loading branch information
glungley authored Oct 12, 2024
1 parent ef62806 commit f427c9a
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 1 deletion.
12 changes: 12 additions & 0 deletions __tests__/action-docs-workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <string>(
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"),
Expand Down
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
53 changes: 53 additions & 0 deletions __tests__/fixtures/workflow/secrets_workflow.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
## A Workflow with secrets

### Inputs

| name | description | type | required | default |
| --- | --- | --- | --- | --- |
| `inputA` | <ul> <li>Item 1<ul> <li>foo, bar, baz</li></ul></li> <li>Item 2<ul> <li><a href="https://github.com/">github</a></li> <li><strong>blah</strong></li></ul></li> <li>Item 3</li> </ul> | `string` | `false` | `This is a default` |
| `inputB` | <p>This is a multiline description</p> | `number` | `true` | `""` |


### Secrets

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


### Outputs

| name | description |
| --- | --- |
| `outputA` | <p>This is output A</p> |


### 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: ""
```


46 changes: 46 additions & 0 deletions __tests__/fixtures/workflow/secrets_workflow.yml
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions __tests__/fixtures/workflow/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ on:
multiline description
type: number
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"
}
}
}
16 changes: 16 additions & 0 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,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),
Expand All @@ -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,
Expand Down

0 comments on commit f427c9a

Please sign in to comment.