Skip to content

Commit 9da850f

Browse files
committed
deprecation fixes and improvements
1 parent 492bf5b commit 9da850f

29 files changed

+272
-117
lines changed

.github/workflows/test.yml

+5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ jobs:
99
- uses: actions/checkout@v2
1010

1111
- name: Use local action
12+
id: example
1213
uses: ./
1314
with:
1415
files: |
1516
example.openapi.yaml
17+
- name: Output export variable
18+
run: |
19+
echo ${{ steps.example.outputs.validFiles }}
20+
echo ${{ steps.example.outputs.invalidFiles }}

README.md

+29-10
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,26 @@ This action uses the swagger-cli to validate a given swagger file(s).
1010

1111
See example for suggested command for finding all files ending in "openapi.yaml".
1212

13-
## Outputs
13+
### `space_separated`
1414

15-
`example.openapi.yaml is valid`
15+
**Optional** Defaults to true.
1616

17-
`example.openapi.yaml is invalid`
17+
For use when passing in a list of files that are space separated.
18+
19+
## Example output
20+
21+
```
22+
Validating file: example.openapi.yaml
23+
example.openapi.yaml is valid
24+
```
25+
26+
## Output variables
27+
28+
### invalidFiles
29+
List of files that failed to validate.
30+
31+
### validFiles
32+
List of valid files.
1833

1934
## Example usage
2035

@@ -38,18 +53,22 @@ jobs:
3853
runs-on: ubuntu-latest
3954

4055
steps:
41-
- uses: actions/checkout@v2
4256
- name: Get OpenAPI files
57+
id: getfiles
58+
uses: actions/checkout@v2
4359
run: |
44-
FILES="$(find . \( -iname "*openapi.yaml" -or -iname "*openapi.yml" \) -not -path "./.github/*")"
45-
FILES_C="$(echo "$FILES" | sed '/^\s*$/d' | wc -l)"
46-
echo ::set-env name=FILE_LIST::$FILES
47-
echo ::set-env name=FILE_COUNT::$FILES_C
48-
echo "Found files:"
49-
echo "$FILES"
60+
# Using github env (newline separated file list)
61+
echo 'FILE_LIST<<EOF' >> $GITHUB_ENV
62+
find lib -type f -iname "*openapi.yaml" >> $GITHUB_ENV
63+
echo 'EOF' >> $GITHUB_ENV
64+
65+
# Using step output (space separated file list)
66+
FILES="$(find lib -type f -iname "*openapi.yaml")"
67+
echo "::set-output name=file_list::$FILES"
5068
- name: swagger-validator
5169
uses: mbowman100/swagger-validator-action@master
5270
if: env.FILE_COUNT != '0' # Comment out if you want it to fail if no files found
5371
with:
5472
files: ${{ env.FILE_LIST }}
73+
# files: ${{ steps.getfiles.outputs.file_list }} # For if you're using output
5574
```

action.yaml

+8-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ branding:
77

88
inputs:
99
files:
10-
description: 'Swagger/OpenAPI file(s) to validate'
10+
description: 'List of Swagger/OpenAPI file(s) to validate. Seperate each file with a new line or a space.'
1111
required: true
12+
space_separated:
13+
description: 'Defaults to true.'
14+
required: false
1215
outputs:
13-
file_list:
14-
description: '<file name> is valid'
16+
invalidFiles:
17+
description: 'List of invalid files.'
18+
validFiles:
19+
description: 'List of valid files.'
1520

1621
runs:
1722
using: 'node12'

example.openapi.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ paths:
3030
schema:
3131
type: string
3232
content:
33-
application/json:
33+
application/json:
3434
schema:
3535
$ref: "#/components/schemas/Pets"
3636
default:

index.js

+35-12
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,59 @@ const core = require('@actions/core');
22
const api = require("@apidevtools/swagger-cli");
33

44
try {
5-
const files = core.getInput('files', { required: true }).trim();
5+
const files = core.getInput(
6+
'files',
7+
{ required: true }
8+
).trim();
9+
10+
const space_separated = core.getInput(
11+
'space_separated',
12+
{
13+
required: false,
14+
default: '1'
15+
}
16+
).trim();
617

718
// Bail if no files
819
if (files == '') {
9-
console.log('No files to validate');
10-
return core.setOutput('No files to validate');
20+
return core.info('No files to validate');
21+
}
22+
23+
if(space_separated == 1) {
24+
files = files.replace(/(\.ya?ml)\s/g, `$1\n`);
1125
}
1226

13-
files.split(" ").forEach(file => {
14-
console.log(`Validating file: ${file}`);
15-
core.setOutput(`Validating file: ${file}`);
27+
var invalidFiles = [];
28+
var validFiles = [];
29+
files.split(/\n/).forEach(file => {
30+
core.info(`Validating file: ${file}`);
1631

17-
validate(file, {
32+
var error = validate(file, {
1833
format: 2,
1934
type: "yaml",
2035
wrap: Infinity
2136
});
37+
38+
if(error) {
39+
invalidFiles.push(file);
40+
} else {
41+
validFiles.push(file);
42+
}
2243
});
44+
45+
core.setOutput('invalidFiles', invalidFiles);
46+
core.setOutput('validFiles', validFiles);
2347
} catch (error) {
24-
console.error(error);
2548
core.setFailed(error);
2649
}
2750

2851
async function validate(file, options) {
52+
var error;
2953
try {
3054
await api.validate(file, options);
31-
console.log(file, " is valid");
32-
core.setOutput(`${file} is valid`);
55+
core.info(`${file} is valid`);
3356
} catch (error) {
34-
console.error(error.message);
35-
core.setFailed(`${file} is invalid`);
57+
core.setFailed(`${file} is invalid\n${error.message}`);
3658
}
59+
return error;
3760
}

node_modules/@actions/core/LICENSE.md

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/core/README.md

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/core/lib/command.d.ts

-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/core/lib/command.js

+3-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/core/lib/command.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/core/lib/core.js

+19-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)