Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support document generation for workflows #523

Merged
merged 44 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
9e41f88
GH-240 upgrade packages to remove vulnerabilities
larmitage-bjss Feb 13, 2024
1170ddd
GH-240 move test fixtures to folders to separate action and workflow …
larmitage-bjss Feb 13, 2024
9a7e402
GH-240 duplicate tests for workflows
larmitage-bjss Feb 13, 2024
36949f3
GH-420 add run scripts to run action/workflow manually and run tests …
larmitage-bjss Feb 13, 2024
b10780a
WIP
larmitage-bjss Feb 13, 2024
21ebdb2
Merge pull request #2 from larmitage-bjss/GH-240-upgrade-packages
larmitage-bjss Feb 13, 2024
09dec15
GH-240 update CONTRIBUTING where command does not work and add additi…
larmitage-bjss Feb 13, 2024
945278b
Merge remote-tracking branch 'origin' into GH-240-support-workflows
larmitage-bjss Feb 13, 2024
94a2b15
Merge pull request #3 from larmitage-bjss/GH-240-update-docs
larmitage-bjss Feb 13, 2024
83bcb62
Merge remote-tracking branch 'origin' into GH-240-support-workflows
larmitage-bjss Feb 13, 2024
d1d69a1
GH-240 add option to have a top level header containing the name
larmitage-bjss Feb 13, 2024
e2abbb2
GH-240 add header to readme and tests
larmitage-bjss Feb 13, 2024
d94ecf8
Remove unused files
larmitage-bjss Feb 13, 2024
8fc1b70
Merge pull request #4 from larmitage-bjss/GH-240-add-name-header
larmitage-bjss Feb 13, 2024
8bb6a3e
GH-240 fix error with enum
larmitage-bjss Feb 13, 2024
8df7c09
Merge remote-tracking branch 'origin' into GH-240-support-workflows
larmitage-bjss Feb 13, 2024
ef810cc
GH-240 ability to display workflow inputs and outputs
larmitage-bjss Feb 14, 2024
d55f6e5
GH-240 add usage
larmitage-bjss Feb 14, 2024
a4d2096
GH-240 start adding workflow tests
larmitage-bjss Feb 14, 2024
ef52841
GH-240 get a few more workflow tests working
larmitage-bjss Feb 14, 2024
c4c8295
Merge remote-tracking branch 'upstream/main'
larmitage-bjss Feb 15, 2024
7c7a563
Merge remote-tracking branch 'origin' into GH-240-support-workflows
larmitage-bjss Feb 15, 2024
c6d1883
Update action test files with main
larmitage-bjss Feb 15, 2024
3cd97c2
GH-240 fix test for readme
larmitage-bjss Feb 15, 2024
53c9432
GH-240 all fields readme test working
larmitage-bjss Feb 15, 2024
4ba7bae
GH-240 sort out renaming of action > workflow of test files
larmitage-bjss Feb 15, 2024
513cd72
GH-240 fix crlf test
larmitage-bjss Feb 15, 2024
f67990f
GH-240 all tests fixed
larmitage-bjss Feb 15, 2024
664685e
GH-240 amend readme for workflow functionality
larmitage-bjss Feb 15, 2024
e2f5a89
Merge remote-tracking branch 'upstream/main'
larmitage-bjss Feb 15, 2024
971fa99
Merge remote-tracking branch 'origin' into GH-240-support-workflows
larmitage-bjss Feb 15, 2024
8389a6e
GH-240 add back in new lines at end of files
larmitage-bjss Feb 15, 2024
c0b7bb8
GH-240 tweak to readme to clarify description is only for actions
larmitage-bjss Feb 15, 2024
94ee9e1
Merge branch 'main' into GH-240-support-workflows
larmitage-bjss Feb 16, 2024
6b83e08
Merge remote-tracking branch 'upstream/main' into GH-240-support-work…
larmitage-bjss Mar 5, 2024
e43eb79
GH-240 Fix tests
larmitage-bjss Mar 5, 2024
0c947f7
GH-240 fix workflow syntax
larmitage-bjss Mar 5, 2024
39d9cc9
GH-240 add source option and deprecate action option
larmitage-bjss Mar 5, 2024
bd71f41
GH-240 Make replace in readme backwards compatible with source/action
larmitage-bjss Mar 5, 2024
dfa6c51
GH-240 add backwards compatibility test
larmitage-bjss Mar 5, 2024
d2b41a4
Merge branch 'main' into GH-240-support-workflows
npalm Mar 5, 2024
1fae02e
Fix missed -a to -s in readme
larmitage-bjss Mar 6, 2024
96eea10
GH-420 rename ActionYml to YmlStructure, and actionFile to sourceFile
larmitage-bjss Mar 6, 2024
a207a86
Merge branch 'main' into GH-240-support-workflows
npalm Mar 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "error"
"@typescript-eslint/unbound-method": "error",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you recall which lines are triggering this issue. Would prefer either fix the error, or at an ignore on the line. Not global.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue was with adding enums causing an error already declared in the upper scope
Adding those two lines was as suggested here:
typescript-eslint/typescript-eslint#2466

"no-shadow": "off",
"@typescript-eslint/no-shadow": "error"
},
"env": {
"node": true,
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ Please provide tests for your contribution.
To generate a new fixture for Markdown output run

```bash
./lib/cli.js --no-banner -a __tests__/fixtures/<action>.yml | \
./lib/cli.js --no-banner -s __tests__/fixtures/<action>.yml | \
tail -r | tail -n +2 | tail -r > <action_md>.output
```

For creating a README.md fixture, first create the readme input file for the test, and copy the same file to the an output file. Next run the following command to update the output which can be used to verify the test.


```bash
./lib/cli.js --no-banner -a __tests__/fixtures/<action>.yml -u __tests_/fixtures/<readme>.output
./lib/cli.js --no-banner -s __tests__/fixtures/<action>.yml -u __tests_/fixtures/<readme>.output
```

### Use a Consistent Coding Style
Expand Down
53 changes: 29 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,28 @@

# Action docs

A CLI to generate and update documentation for GitHub actions, based on the action definition `.yml`. To update your README in a GitHub workflow you can use the [action-docs-action](https://github.com/npalm/action-docs-action).
A CLI to generate and update documentation for GitHub actions or workflows, based on the definition `.yml`. To update your README in a GitHub workflow you can use the [action-docs-action](https://github.com/npalm/action-docs-action).
npalm marked this conversation as resolved.
Show resolved Hide resolved

## TL;DR

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

```md
<!-- action-docs-description action="action.yml" -->
<!-- action-docs-header source="action.yml" -->
npalm marked this conversation as resolved.
Show resolved Hide resolved

<!-- action-docs-inputs action="action.yml" -->
<!-- action-docs-description source="action.yml" --> # applicable for actions only

<!-- action-docs-outputs action="action.yml" -->
<!-- action-docs-inputs source="action.yml" -->

<!-- action-docs-runs action="action.yml" -->
<!-- action-docs-outputs source="action.yml" -->

<!-- action-docs-runs source="action.yml" --> # applicable for actions only
```

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.

```md
<!-- action-docs-usage action="action.yml" project="<project>" version="<version>" -->
<!-- action-docs-usage source="action.yml" project="<project>" version="<version>" -->
```

### Generate docs via CLI
Expand Down Expand Up @@ -55,39 +57,42 @@ The following options are available via the CLI

```
Options:
--help Show help [boolean]
--version Show version number [boolean]
-t, --toc-level TOC level used for markdown [number] [default: 2]
-a, --action GitHub action file [string] [default: "action.yml"]
--no-banner Print no banner
-u, --update-readme Update readme file. [string]
-l, --line-breaks Used line breaks in the generated docs.
[string] [choices: "CR", "LF", "CRLF"] [default: "LF"]
-n, --include-name-header Include a header with the action/workflow name.
--version Show version number [boolean]
-t, --toc-level TOC level used for markdown [number] [default: 2]
-a, --action GitHub action file
npalm marked this conversation as resolved.
Show resolved Hide resolved
[deprecated: use "source" instead] [string] [default: "action.yml"]
-s, --source GitHub source file [string] [default: "action.yml"]
--no-banner Print no banner
-u, --update-readme Update readme file. [string]
-l, --line-breaks Used line breaks in the generated docs.
[string] [choices: "CR", "LF", "CRLF"] [default: "LF"]
-n, --include-name-header Include a header with the action/workflow name
[boolean]
--help Show help [boolean]
```

### Update the README

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`.

```md
<!-- action-docs-header action="action.yml" -->
<!-- action-docs-header source="action.yml" -->

<!-- action-docs-description action="action.yml" -->
<!-- action-docs-description source="action.yml" -->

<!-- action-docs-inputs action="action.yml" -->
<!-- action-docs-inputs source="action.yml" -->

<!-- action-docs-outputs action="action.yml" -->
<!-- action-docs-outputs source="action.yml" -->

<!-- action-docs-runs action="action.yml" -->
<!-- action-docs-runs source="action.yml" -->
```

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

If you need to use `another/action.yml`:

1. write it in tags like `action="another/action.yml"`;
1. specify in a command via the `-a` option like `action-docs -a another/action.yml`
1. write it in tags like `source="another/action.yml"`;
1. specify in a command via the `-s` option like `action-docs -s another/action.yml`
larmitage-bjss marked this conversation as resolved.
Show resolved Hide resolved

### Examples

Expand All @@ -106,13 +111,13 @@ action-docs --update-readme
#### Print action markdown for non default action file

```bash
action-docs --action another/action.yaml
action-docs --source another/action.yaml
```

#### Update readme, custom action file and set TOC level 3, custom readme

```bash
action-docs --action ./some-dir/action.yml --toc-level 3 --update-readme docs.md
action-docs --source ./some-dir/action.yml --toc-level 3 --update-readme docs.md
```

## API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { generateActionMarkdownDocs, Options } from "../src";
import { readFileSync, writeFileSync, copyFileSync, unlink } from "fs";
import * as path from "path";

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

// By default an 'action.yml' is expected at the runtime location. Therefore we copy one during th test.
// By default an 'action.yml' is expected at the runtime location. Therefore we copy one during the test.
beforeAll(() => {
copyFileSync(path.join(fixtureDir, "action.yml"), "action.yml");
});
Expand Down Expand Up @@ -61,11 +61,30 @@ describe("Test output", () => {

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"),
});
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"),
},
{
includeNameHeader: true,
},
);
});
test("Empty readme (all fields) with header", 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_header.output"),
},
{
includeNameHeader: true,
},
false,
true,
);
});

test("Filled readme (all fields)", async () => {
Expand All @@ -83,7 +102,9 @@ describe("Test update readme ", () => {
originalReadme: path.join(fixtureDir, "all_fields_readme.input"),
fixtureReadme: path.join(fixtureDir, "all_fields_readme_header.output"),
},
{},
{
includeNameHeader: true,
},
false,
true,
);
Expand Down Expand Up @@ -145,6 +166,21 @@ describe("Test usage format", () => {
});
});

describe("Backwards compatibility", () => {
test("Deprecated action option still works correctly", async () => {
await testReadme(
{
actionFile: path.join(fixtureDir, "all_fields_action.yml"),
originalReadme: path.join(fixtureDir, "action_deprecated.input"),
fixtureReadme: path.join(fixtureDir, "action_deprecated.output"),
},
{
includeNameHeader: true,
},
);
});
});

interface ReadmeTestFixtures {
actionFile: string;
originalReadme: string;
Expand All @@ -160,18 +196,21 @@ async function testReadme(
const expected = <string>readFileSync(files.fixtureReadme, "utf-8");
const original = <string>readFileSync(files.originalReadme, "utf-8");

await generateActionMarkdownDocs({
actionFile: files.actionFile,
updateReadme: true,
includeNameHeader: includeNameHeader,
readmeFile: files.originalReadme,
...overwriteOptions,
});
try {
await generateActionMarkdownDocs({
actionFile: files.actionFile,
updateReadme: true,
includeNameHeader: includeNameHeader,
readmeFile: files.originalReadme,
...overwriteOptions,
});

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

if (doExpect) {
if (doExpect) {
expect(updated).toEqual(expected);
}
} finally {
writeFileSync(files.originalReadme, original);
expect(updated).toEqual(expected);
}
}
Loading