Skip to content

fix: enable paths in usage #655

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
@@ -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(
{
2 changes: 1 addition & 1 deletion __tests__/fixtures/action/action_deprecated.output
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion __tests__/fixtures/action/action_usage_readme.output
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion __tests__/fixtures/action/all_fields_action.output
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion __tests__/fixtures/action/all_fields_one_annotation.output
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion __tests__/fixtures/action/all_fields_readme.output
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion __tests__/fixtures/action/all_fields_usage_readme.output
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion __tests__/fixtures/action/default-with-header.output
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ This action is a `node12` action.
### Usage

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

```yaml
- uses: ***PROJECT***@***VERSION***
- uses: ***PROJECT******SOURCE_FILE***@***VERSION***
with:
inputA:
# - Item 1
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
@@ -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
@@ -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
2 changes: 1 addition & 1 deletion __tests__/fixtures/workflow/all_fields_readme.output
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion __tests__/fixtures/workflow/all_fields_usage_readme.output
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion __tests__/fixtures/workflow/all_fields_workflow.output
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@
```yaml
jobs:
job1:
uses: ***PROJECT***@***VERSION***
uses: ***PROJECT******SOURCE_FILE***@***VERSION***
with:
inputA:
# A description A
2 changes: 1 addition & 1 deletion __tests__/fixtures/workflow/default.output
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@
```yaml
jobs:
job1:
uses: ***PROJECT***@***VERSION***
uses: ***PROJECT******SOURCE_FILE***@***VERSION***
with:
inputA:
# - Item 1
2 changes: 1 addition & 1 deletion __tests__/fixtures/workflow/minimal_workflow.output
Original file line number Diff line number Diff line change
@@ -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
@@ -27,7 +27,7 @@
```yaml
jobs:
job1:
uses: ***PROJECT***@***VERSION***
uses: ***PROJECT******SOURCE_FILE***@***VERSION***
with:
inputA:
# - Item 1
2 changes: 1 addition & 1 deletion __tests__/fixtures/workflow/workflow_usage_readme.output
Original file line number Diff line number Diff line change
@@ -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
12 changes: 9 additions & 3 deletions src/action-docs.ts
Original file line number Diff line number Diff line change
@@ -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(
@@ -368,6 +370,10 @@ async function updateReadme(
.replace(
"***VERSION***",
matchProjectVersion ? matchProjectVersion[2] : "",
)
.replace(
"***SOURCE_FILE***",
sourceFile !== defaultOptions.sourceFile ? `/${sourceFile}` : "",
);

await replaceInFile.replaceInFile({
Loading