Skip to content

Commit 284bf3f

Browse files
authored
feat!: support multiple actions in a single readme (#505)
update - deps - tests - table format - use HTML for descriptions
1 parent dc7fc53 commit 284bf3f

31 files changed

+3909
-4385
lines changed

.eslintrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
"sourceType": "module",
88
"project": "./tsconfig.json"
99
},
10+
"settings": {
11+
"import/resolver": {
12+
"typescript": {}
13+
}
14+
},
1015
"rules": {
1116
"no-console": "off",
1217
"eslint-comments/no-use": "off",

README.md

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@ A CLI to generate and update documentation for GitHub actions, based on the acti
1212

1313
### Add the following comment blocks to your README.md
1414

15-
```
16-
<!-- action-docs-description -->
15+
```md
16+
<!-- action-docs-description action="action.yml" -->
1717

18-
<!-- action-docs-inputs -->
18+
<!-- action-docs-inputs action="action.yml" -->
1919

20-
<!-- action-docs-outputs -->
20+
<!-- action-docs-outputs action="action.yml" -->
2121

22-
<!-- action-docs-runs -->
22+
<!-- action-docs-runs action="action.yml" -->
2323
```
2424

2525
Optionally you can also add the following section to generate a usage guide, replacing \<project\> and \<version\> with the name and version of your project you would like to appear in your usage guide.
2626

27-
```
28-
<!-- action-docs-usage project="<project>" version="<version>" -->
27+
```md
28+
<!-- action-docs-usage action="action.yml" project="<project>" version="<version>" -->
2929
```
3030

31-
### Generate docs via CLI.
31+
### Generate docs via CLI
3232

3333
```bash
3434
npm install -g action-docs
@@ -69,18 +69,22 @@ Options:
6969

7070
Action-docs can update your README based on the `action.yml`. The following sections can be updated: description, inputs, outputs and runs. Add the following tags to your README and run `action-docs -u`.
7171

72-
```
73-
<!-- action-docs-description -->
72+
```md
73+
<!-- action-docs-description action="action.yml" -->
7474

75-
<!-- action-docs-inputs -->
75+
<!-- action-docs-inputs action="action.yml" -->
7676

77-
<!-- action-docs-outputs -->
77+
<!-- action-docs-outputs action="action.yml" -->
7878

79-
<!-- action-docs-runs -->
79+
<!-- action-docs-runs action="action.yml" -->
8080
```
8181

8282
For updating other Markdown files add the name of the file to the command `action-docs -u <file>`.
8383

84+
If you need to use `another/action.yml`:
85+
86+
1. write it in tags like `action="another/action.yml"`;
87+
1. specify in a command via the `-a` option like `action-docs -a another/action.yml`
8488

8589
### Examples
8690

@@ -96,11 +100,10 @@ action-docs
96100
action-docs --update-readme
97101
```
98102

99-
100103
#### Print action markdown for non default action file
101104

102105
```bash
103-
action-docs --action ./action.yaml
106+
action-docs --action another/action.yaml
104107
```
105108

106109
#### Update readme, custom action file and set TOC level 3, custom readme
@@ -109,9 +112,6 @@ action-docs --action ./action.yaml
109112
action-docs --action ./some-dir/action.yml --toc-level 3 --update-readme docs.md
110113
```
111114

112-
113-
114-
115115
## API
116116

117117
```javascript
@@ -127,8 +127,7 @@ await generateActionMarkdownDocs({
127127

128128
## Contribution
129129

130-
We welcome contributions, please checkout the [contribution guide](CONTRIBUTING.md).
131-
130+
We welcome contributions, please checkout the [contribution guide](CONTRIBUTING.md).
132131

133132
## License
134133

__tests__/action-docs.test.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { generateActionMarkdownDocs, Options } from "../src";
2-
import { readFileSync, writeFileSync, copyFileSync, rmSync, unlink } from "fs";
2+
import { readFileSync, writeFileSync, copyFileSync, unlink } from "fs";
33
import * as path from "path";
4-
import { option } from "yargs";
54

65
const fixtureDir = path.join("__tests__", "fixtures");
76

@@ -73,9 +72,35 @@ describe("Test update readme ", () => {
7372
originalReadme: path.join(fixtureDir, "all_fields_readme.input.crlf"),
7473
fixtureReadme: path.join(fixtureDir, "all_fields_readme.output.crlf"),
7574
},
76-
{ lineBreaks: "CRLF" }
75+
{ lineBreaks: "CRLF" },
7776
);
7877
});
78+
79+
test("Readme (inputs) for action-docs-action", async () => {
80+
await testReadme({
81+
actionFile: path.join(fixtureDir, "action_docs_action_action.yml"),
82+
originalReadme: path.join(fixtureDir, "action_docs_action_readme.input"),
83+
fixtureReadme: path.join(fixtureDir, "action_docs_action_readme.output"),
84+
});
85+
});
86+
87+
test("Readme for two action.yml-s", async () => {
88+
await testReadme(
89+
{
90+
actionFile: path.join(fixtureDir, "action_docs_action_action.yml"),
91+
originalReadme: path.join(fixtureDir, "two_actions_readme.input"),
92+
fixtureReadme: path.join(fixtureDir, "two_actions_readme.output"),
93+
},
94+
{},
95+
false,
96+
);
97+
98+
await testReadme({
99+
actionFile: path.join(fixtureDir, "all_fields_action.yml"),
100+
originalReadme: path.join(fixtureDir, "two_actions_readme.input"),
101+
fixtureReadme: path.join(fixtureDir, "two_actions_readme.output"),
102+
});
103+
});
79104
});
80105

81106
describe("Test usage format", () => {
@@ -104,7 +129,8 @@ interface ReadmeTestFixtures {
104129

105130
async function testReadme(
106131
files: ReadmeTestFixtures,
107-
overwriteOptions?: Options
132+
overwriteOptions?: Options,
133+
doExpect: boolean = true,
108134
) {
109135
const expected = <string>readFileSync(files.fixtureReadme, "utf-8");
110136
const original = <string>readFileSync(files.originalReadme, "utf-8");
@@ -118,6 +144,8 @@ async function testReadme(
118144

119145
const updated = <string>readFileSync(files.originalReadme, "utf-8");
120146

121-
writeFileSync(files.originalReadme, original);
122-
expect(updated).toEqual(expected);
147+
if (doExpect) {
148+
writeFileSync(files.originalReadme, original);
149+
expect(updated).toEqual(expected);
150+
}
123151
}

__tests__/cli.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe("CLI tests", () => {
1010
await testReadme(
1111
path.join(fixtureDir, "all_fields_action.yml"),
1212
path.join(fixtureDir, "all_fields_readme.input"),
13-
path.join(fixtureDir, "all_fields_readme.output")
13+
path.join(fixtureDir, "all_fields_readme.output"),
1414
);
1515
});
1616

@@ -19,19 +19,19 @@ describe("CLI tests", () => {
1919
path.join(fixtureDir, "all_fields_action.yml.crlf"),
2020
path.join(fixtureDir, "all_fields_readme.input.crlf"),
2121
path.join(fixtureDir, "all_fields_readme.output.crlf"),
22-
"-l CRLF"
22+
"-l CRLF",
2323
);
2424
});
2525

2626
test("Console output with TOC 3 and no banner.", async () => {
2727
const result = await cli(
28-
`-a __tests__/fixtures/all_fields_action.yml -t 3 --no-banner`
28+
`-a __tests__/fixtures/all_fields_action.yml -t 3 --no-banner`,
2929
);
3030

3131
const expected = <string>(
3232
readFileSync(
3333
path.join(fixtureDir, "all_fields_action_toc3_cli.output"),
34-
"utf-8"
34+
"utf-8",
3535
)
3636
);
3737

@@ -50,15 +50,15 @@ interface CliRespone {
5050
function cli(args: string): Promise<CliRespone> {
5151
return new Promise((resolve) => {
5252
cp.exec(
53-
`ts-node ${path.resolve("src/cli.ts")} ${args}`,
53+
`node ${path.resolve("lib/cli.js")} ${args}`,
5454
(error, stdout, stderr) => {
5555
resolve({
5656
code: error && error.code ? error.code : 0,
5757
error,
5858
stdout,
5959
stderr,
6060
});
61-
}
61+
},
6262
);
6363
});
6464
}
@@ -68,13 +68,13 @@ async function testReadme(
6868
originalReadme: string,
6969
fixtureReadme: string,
7070
extraArgs = "",
71-
exitCode = 0
71+
exitCode = 0,
7272
) {
7373
const expected = <string>readFileSync(fixtureReadme, "utf-8");
7474
const original = <string>readFileSync(originalReadme, "utf-8");
7575

7676
const result = await cli(
77-
`-u ${originalReadme} -a ${actionFile} ${extraArgs}`
77+
`-u ${originalReadme} -a ${actionFile} ${extraArgs}`,
7878
);
7979
expect(result.code).toBe(exitCode);
8080

__tests__/fixtures/action.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ inputs:
55
inputA:
66
required: false
77
description: |
8-
A description
9-
This is a multiline description
8+
- Item 1
9+
- foo, bar, baz
10+
- Item 2
11+
- [github](https://github.com/)
12+
- **blah**
13+
- Item 3
1014
default: test
1115
inputB:
1216
required: false
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: 'Action update docs action'
2+
description: 'Action updates the action documentation.'
3+
author: 'Niek Palm'
4+
5+
branding:
6+
icon: book-open
7+
color: purple
8+
9+
inputs:
10+
readme:
11+
description: 'Readme file to update.'
12+
required: false
13+
default: README.md
14+
actionFile:
15+
description: 'The action definition file.'
16+
required: false
17+
default: action.yml
18+
tocLevel:
19+
description: "TOC level used for the headers."
20+
required: false
21+
default: 2
22+
lineBreaks:
23+
description: "Line breaks to be used in updated readme (LF|CR|CRLF)."
24+
required: false
25+
default: LF
26+
27+
runs:
28+
using: 'node16'
29+
main: 'dist/index.js'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!-- action-docs-inputs action="__tests__/fixtures/action_docs_action_action.yml" -->
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!-- action-docs-inputs action="__tests__/fixtures/action_docs_action_action.yml" -->
2+
## Inputs
3+
4+
| name | description | required | default |
5+
| --- | --- | --- | --- |
6+
| `readme` | <p>Readme file to update.</p> | `false` | `README.md` |
7+
| `actionFile` | <p>The action definition file.</p> | `false` | `action.yml` |
8+
| `tocLevel` | <p>TOC level used for the headers.</p> | `false` | `2` |
9+
| `lineBreaks` | <p>Line breaks to be used in updated readme (LF|CR|CRLF).</p> | `false` | `LF` |
10+
<!-- action-docs-inputs action="__tests__/fixtures/action_docs_action_action.yml" -->
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!-- action-docs-usage project="npalm/action-docs" version="v1" -->
1+
<!-- action-docs-usage action="__tests__/fixtures/action.yml" project="npalm/action-docs" version="v1" -->
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
<!-- action-docs-usage project="npalm/action-docs" version="v1" -->
1+
<!-- action-docs-usage action="__tests__/fixtures/action.yml" project="npalm/action-docs" version="v1" -->
22
## Usage
33

44
```yaml
55
- uses: npalm/action-docs@v1
66
with:
77
inputA:
8-
# A description
9-
# This is a multiline description
8+
# - Item 1
9+
# - foo, bar, baz
10+
# - Item 2
11+
# - [github](https://github.com/)
12+
# - **blah**
13+
# - Item 3
1014
#
1115
# Required: false
1216
# Default: test
@@ -18,4 +22,4 @@
1822
# Required: false
1923
# Default: test
2024
```
21-
<!-- action-docs-usage project="npalm/action-docs" version="v1" -->
25+
<!-- action-docs-usage action="__tests__/fixtures/action.yml" project="npalm/action-docs" version="v1" -->

0 commit comments

Comments
 (0)