Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions __tests__/action-docs-action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ describe("Test output", () => {
});

describe("Test update readme ", () => {
test("With defaults.", async () => {
await testReadme(
{
sourceFile: "action.yml", // Default value
originalReadme: path.join(fixtureDir, "default_readme.input"),
fixtureReadme: path.join(fixtureDir, "default_readme.output"),
},
{
includeNameHeader: true,
},
);
});

test("Empty readme (all fields)", async () => {
await testReadme(
{
Expand Down
2 changes: 1 addition & 1 deletion __tests__/fixtures/action/action_deprecated.output
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Default test
### Usage

```yaml
- uses: npalm/action-docs@v1
- uses: npalm/action-docs/__tests__/fixtures/action/all_fields_action.yml@v1
with:
inputA:
# A description A
Expand Down
2 changes: 1 addition & 1 deletion __tests__/fixtures/action/action_usage_readme.output
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Usage

```yaml
- uses: npalm/action-docs@v1
- uses: npalm/action-docs/__tests__/fixtures/action/action.yml@v1
with:
inputA:
# - Item 1
Expand Down
2 changes: 1 addition & 1 deletion __tests__/fixtures/action/all_fields_action.output
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This action is a `node12` action.
## Usage

```yaml
- uses: ***PROJECT***@***VERSION***
- uses: ***PROJECT******SOURCE_FILE***@***VERSION***
with:
inputA:
# A description A
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This action is a `node12` action.
### Usage

```yaml
- uses: ***PROJECT***@***VERSION***
- uses: ***PROJECT******SOURCE_FILE***@***VERSION***
with:
inputA:
# A description A
Expand Down
2 changes: 1 addition & 1 deletion __tests__/fixtures/action/all_fields_one_annotation.output
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ This action is a `node12` action.
## Usage

```yaml
- uses: npalm/action-docs@v1
- uses: npalm/action-docs/__tests__/fixtures/action/all_fields_action.yml@v1
with:
inputA:
# A description A
Expand Down
2 changes: 1 addition & 1 deletion __tests__/fixtures/action/all_fields_readme.output
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Default test
### Usage

```yaml
- uses: npalm/action-docs@v1
- uses: npalm/action-docs/__tests__/fixtures/action/all_fields_action.yml@v1
with:
inputA:
# A description A
Expand Down
2 changes: 1 addition & 1 deletion __tests__/fixtures/action/all_fields_usage_readme.output
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Usage

```yaml
- uses: npalm/action-docs@v1
- uses: npalm/action-docs/__tests__/fixtures/action/all_fields_action.yml@v1
with:
inputA:
# A description A
Expand Down
2 changes: 1 addition & 1 deletion __tests__/fixtures/action/default-with-header.output
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ This action is a `node12` action.
### Usage

```yaml
- uses: ***PROJECT***@***VERSION***
- uses: ***PROJECT******SOURCE_FILE***@***VERSION***
with:
inputA:
# - Item 1
Expand Down
2 changes: 1 addition & 1 deletion __tests__/fixtures/action/default.output
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This action is a `node12` action.
## Usage

```yaml
- uses: ***PROJECT***@***VERSION***
- uses: ***PROJECT******SOURCE_FILE***@***VERSION***
with:
inputA:
# - Item 1
Expand Down
11 changes: 11 additions & 0 deletions __tests__/fixtures/action/default_readme.input
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- action-docs-header source="action.yml" -->

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

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

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

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

<!-- action-docs-usage source="action.yml" project="npalm/action-docs" version="v1" -->
58 changes: 58 additions & 0 deletions __tests__/fixtures/action/default_readme.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!-- action-docs-header source="action.yml" -->
## An Action
<!-- action-docs-header source="action.yml" -->

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

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

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

| name | description | 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> | `false` | `test` |
| `inputB` | <p>This is a multiline description</p> | `false` | `test` |
<!-- action-docs-inputs source="action.yml" -->

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

| name | description |
| --- | --- |
| `outputA` | <p>A description</p> |
<!-- action-docs-outputs source="action.yml" -->

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

This action is a `node12` action.
<!-- action-docs-runs source="action.yml" -->

<!-- action-docs-usage source="action.yml" project="npalm/action-docs" version="v1" -->
### Usage

```yaml
- uses: npalm/action-docs@v1
with:
inputA:
# - Item 1
# - foo, bar, baz
# - Item 2
# - [github](https://github.com/)
# - **blah**
# - Item 3
#
# Required: false
# Default: test

inputB:
# This is a
# multiline description
#
# Required: false
# Default: test
```
<!-- action-docs-usage source="action.yml" project="npalm/action-docs" version="v1" -->
2 changes: 1 addition & 1 deletion __tests__/fixtures/action/minimal_action.output
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This action is a `docker` action.
## Usage

```yaml
- uses: ***PROJECT***@***VERSION***
- uses: ***PROJECT******SOURCE_FILE***@***VERSION***
```


Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
```yaml
jobs:
job1:
uses: npalm/action-docs@v1
uses: npalm/action-docs/__tests__/fixtures/workflow/all_fields_workflow.yml@v1
with:
inputA:
# A description A
Expand Down
2 changes: 1 addition & 1 deletion __tests__/fixtures/workflow/all_fields_readme.output
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
```yaml
jobs:
job1:
uses: npalm/action-docs@v1
uses: npalm/action-docs/__tests__/fixtures/workflow/all_fields_workflow.yml@v1
with:
inputA:
# A description A
Expand Down
2 changes: 1 addition & 1 deletion __tests__/fixtures/workflow/all_fields_usage_readme.output
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
```yaml
jobs:
job1:
uses: npalm/action-docs@v1
uses: npalm/action-docs/__tests__/fixtures/workflow/all_fields_workflow.yml@v1
with:
inputA:
# A description A
Expand Down
2 changes: 1 addition & 1 deletion __tests__/fixtures/workflow/all_fields_workflow.output
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
```yaml
jobs:
job1:
uses: ***PROJECT***@***VERSION***
uses: ***PROJECT******SOURCE_FILE***@***VERSION***
with:
inputA:
# A description A
Expand Down
2 changes: 1 addition & 1 deletion __tests__/fixtures/workflow/default.output
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
```yaml
jobs:
job1:
uses: ***PROJECT***@***VERSION***
uses: ***PROJECT******SOURCE_FILE***@***VERSION***
with:
inputA:
# - Item 1
Expand Down
2 changes: 1 addition & 1 deletion __tests__/fixtures/workflow/minimal_workflow.output
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
```yaml
jobs:
job1:
uses: ***PROJECT***@***VERSION***
uses: ***PROJECT******SOURCE_FILE***@***VERSION***
```


2 changes: 1 addition & 1 deletion __tests__/fixtures/workflow/secrets_workflow.output
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
```yaml
jobs:
job1:
uses: ***PROJECT***@***VERSION***
uses: ***PROJECT******SOURCE_FILE***@***VERSION***
with:
inputA:
# - Item 1
Expand Down
2 changes: 1 addition & 1 deletion __tests__/fixtures/workflow/workflow_usage_readme.output
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
```yaml
jobs:
job1:
uses: npalm/action-docs@v1
uses: npalm/action-docs/__tests__/fixtures/workflow/workflow.yml@v1
with:
inputA:
# - Item 1
Expand Down
12 changes: 9 additions & 3 deletions src/action-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,23 @@ function createMdTable(
function createMdCodeBlock(
data: ActionInputsOutputs,
options: DefaultOptions,
isAction = true,
isAction: boolean,
): string {
let codeBlockArray = ["```yaml"];

let indent = "";

if (isAction) {
codeBlockArray.push("- uses: ***PROJECT***@***VERSION***");
codeBlockArray.push("- uses: ***PROJECT******SOURCE_FILE***@***VERSION***");
indent += " ";
} else {
codeBlockArray.push("jobs:");
indent += " ";
codeBlockArray.push(`${indent}job1:`);
indent += " ";
codeBlockArray.push(`${indent}uses: ***PROJECT***@***VERSION***`);
codeBlockArray.push(
`${indent}uses: ***PROJECT******SOURCE_FILE***@***VERSION***`,
);
}

const inputs = getInputOutput(
Expand Down Expand Up @@ -368,6 +370,10 @@ async function updateReadme(
.replace(
"***VERSION***",
matchProjectVersion ? matchProjectVersion[2] : "",
)
.replace(
"***SOURCE_FILE***",
sourceFile !== defaultOptions.sourceFile ? `/${sourceFile}` : "",
);

await replaceInFile({
Expand Down