Skip to content

Commit

Permalink
deprecation fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mbowman100 committed Nov 15, 2020
1 parent 492bf5b commit 9da850f
Show file tree
Hide file tree
Showing 29 changed files with 272 additions and 117 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ jobs:
- uses: actions/checkout@v2

- name: Use local action
id: example
uses: ./
with:
files: |
example.openapi.yaml
- name: Output export variable
run: |
echo ${{ steps.example.outputs.validFiles }}
echo ${{ steps.example.outputs.invalidFiles }}
39 changes: 29 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,26 @@ This action uses the swagger-cli to validate a given swagger file(s).

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

## Outputs
### `space_separated`

`example.openapi.yaml is valid`
**Optional** Defaults to true.

`example.openapi.yaml is invalid`
For use when passing in a list of files that are space separated.

## Example output

```
Validating file: example.openapi.yaml
example.openapi.yaml is valid
```

## Output variables

### invalidFiles
List of files that failed to validate.

### validFiles
List of valid files.

## Example usage

Expand All @@ -38,18 +53,22 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Get OpenAPI files
id: getfiles
uses: actions/checkout@v2
run: |
FILES="$(find . \( -iname "*openapi.yaml" -or -iname "*openapi.yml" \) -not -path "./.github/*")"
FILES_C="$(echo "$FILES" | sed '/^\s*$/d' | wc -l)"
echo ::set-env name=FILE_LIST::$FILES
echo ::set-env name=FILE_COUNT::$FILES_C
echo "Found files:"
echo "$FILES"
# Using github env (newline separated file list)
echo 'FILE_LIST<<EOF' >> $GITHUB_ENV
find lib -type f -iname "*openapi.yaml" >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
# Using step output (space separated file list)
FILES="$(find lib -type f -iname "*openapi.yaml")"
echo "::set-output name=file_list::$FILES"
- name: swagger-validator
uses: mbowman100/swagger-validator-action@master
if: env.FILE_COUNT != '0' # Comment out if you want it to fail if no files found
with:
files: ${{ env.FILE_LIST }}
# files: ${{ steps.getfiles.outputs.file_list }} # For if you're using output
```
11 changes: 8 additions & 3 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ branding:

inputs:
files:
description: 'Swagger/OpenAPI file(s) to validate'
description: 'List of Swagger/OpenAPI file(s) to validate. Seperate each file with a new line or a space.'
required: true
space_separated:
description: 'Defaults to true.'
required: false
outputs:
file_list:
description: '<file name> is valid'
invalidFiles:
description: 'List of invalid files.'
validFiles:
description: 'List of valid files.'

runs:
using: 'node12'
Expand Down
2 changes: 1 addition & 1 deletion example.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ paths:
schema:
type: string
content:
application/json:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
Expand Down
47 changes: 35 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,59 @@ const core = require('@actions/core');
const api = require("@apidevtools/swagger-cli");

try {
const files = core.getInput('files', { required: true }).trim();
const files = core.getInput(
'files',
{ required: true }
).trim();

const space_separated = core.getInput(
'space_separated',
{
required: false,
default: '1'
}
).trim();

// Bail if no files
if (files == '') {
console.log('No files to validate');
return core.setOutput('No files to validate');
return core.info('No files to validate');
}

if(space_separated == 1) {
files = files.replace(/(\.ya?ml)\s/g, `$1\n`);
}

files.split(" ").forEach(file => {
console.log(`Validating file: ${file}`);
core.setOutput(`Validating file: ${file}`);
var invalidFiles = [];
var validFiles = [];
files.split(/\n/).forEach(file => {
core.info(`Validating file: ${file}`);

validate(file, {
var error = validate(file, {
format: 2,
type: "yaml",
wrap: Infinity
});

if(error) {
invalidFiles.push(file);
} else {
validFiles.push(file);
}
});

core.setOutput('invalidFiles', invalidFiles);
core.setOutput('validFiles', validFiles);
} catch (error) {
console.error(error);
core.setFailed(error);
}

async function validate(file, options) {
var error;
try {
await api.validate(file, options);
console.log(file, " is valid");
core.setOutput(`${file} is valid`);
core.info(`${file} is valid`);
} catch (error) {
console.error(error.message);
core.setFailed(`${file} is invalid`);
core.setFailed(`${file} is invalid\n${error.message}`);
}
return error;
}
9 changes: 9 additions & 0 deletions node_modules/@actions/core/LICENSE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion node_modules/@actions/core/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions node_modules/@actions/core/lib/command.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 3 additions & 16 deletions node_modules/@actions/core/lib/command.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node_modules/@actions/core/lib/command.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 19 additions & 3 deletions node_modules/@actions/core/lib/core.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9da850f

Please sign in to comment.