Skip to content

Commit

Permalink
Update ReadMe with new example action and re-enable check for action …
Browse files Browse the repository at this point in the history
…to only run on pull requests
  • Loading branch information
tyler-mairose-sp committed Nov 22, 2021
1 parent e7b6901 commit 6f51af5
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 21 deletions.
53 changes: 45 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,58 @@ Check [PR showcase](https://github.com/l-lin/spectral-comment-action/pull/3#issu
Add or edit an existing workflow:

```yaml
name: "test-action"
name: "Run Spectral API Linter"

on:
# only works on pull requests
pull_request:
branches:
- master

jobs:
test:
spectral_workflow:
name: Lint OpenAPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: l-lin/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
file-glob: sample/*.yml
# Checkout the pull request to run Spectral on
- name: Checkout PR branch
uses: actions/checkout@v2
with:
ref: ${{ github.ref }}

# Checkout custom spectral action to comment issues to the PR
- name: Checkout Spectral Action
uses: actions/checkout@v2
with:
repository: tyler-mairose-sp/spectral-comment-action
path: spectral-comment-action
ref: master

# Install node and run npm install on spectral action to install required packages
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: "12.x"
- run: |
ls -al
cd spectral-comment-action
npm ci
# Run get-changed-files step to get all files changed in the PR as a comma seperated list for the spectral linter action to process with our rulesets
- id: files
with:
format: "csv"
uses: jitterbit/get-changed-files@v1

# Run the spectral linter action and recieve a comment on the PR for any issues the linter found
- name: Spectral comment
uses: ./spectral-comment-action/
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
file-glob: ${{ steps.files.outputs.all }}
spectral-root-ruleset: http://raw.githubusercontent.com/sailpoint-oss/api-linter/main/root-ruleset.yaml
spectral-path-ruleset: http://raw.githubusercontent.com/sailpoint-oss/api-linter/main/path-ruleset.yaml
spectral-schema-ruleset: http://raw.githubusercontent.com/sailpoint-oss/api-linter/main/schema-ruleset.yaml

```

## License
Expand Down
22 changes: 9 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const toMarkdown = require("./to_markdown");
async function run() {
try {
const context = github.context;
// if (!context.payload.pull_request) {
// core.error('this action only works on pull_request events');
// core.setOutput('comment-created', 'false');
// return;
// }
if (!context.payload.pull_request) {
core.error("this action only works on pull_request events");
core.setOutput("comment-created", "false");
return;
}

const inputs = {
githubToken: core.getInput("github-token"),
Expand Down Expand Up @@ -64,8 +64,8 @@ async function run() {
fileContents[i].file.substr(0, fileContents[i].file.lastIndexOf("/"))
);

let pbs = "";
let pbs = "";

if (fileContents[i].file.includes(`sailpoint-api.`)) {
console.log(`Running root ruleset on ${fileContents[i].file}`);
pbs = await runSpectral(rootSpectral, fileContents[i].content, false);
Expand All @@ -77,18 +77,14 @@ async function run() {
pbs = await runSpectral(schemaSpectral, fileContents[i].content, true);
}

//console.log(fileContents[i].file + ":" + fileContents[i].content);
console.log(`Directory Name: ` + __dirname);
console.log(`Current Working Directory: ` + process.cwd());
//console.log(`Current Working Directory: ` + process.cwd());

//const pbs = await runSpectral(rootSpectral, fileContents[i].content);
//console.dir(pbs);
processedPbs = processPbs(fileContents[i].file, processedPbs, pbs);
}

const md = await toMarkdown(processedPbs, project);

console.log(md);
//console.log(md);

if (md === "") {
core.info("No lint error found! Congratulation!");
Expand Down

0 comments on commit 6f51af5

Please sign in to comment.