From 6f51af53c19a796d5342a8d0b9fcf824c81beca3 Mon Sep 17 00:00:00 2001 From: tyler-mairose-sp Date: Mon, 22 Nov 2021 09:54:14 -0500 Subject: [PATCH] Update ReadMe with new example action and re-enable check for action to only run on pull requests --- README.md | 53 ++++++++++++++++++++++++++++++++++++++++++++-------- src/index.js | 22 +++++++++------------- 2 files changed, 54 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index b8bd608..f8bb041 100644 --- a/README.md +++ b/README.md @@ -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/spectral-comment-action@0.1.0 - 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 diff --git a/src/index.js b/src/index.js index b5d2760..655e93c 100644 --- a/src/index.js +++ b/src/index.js @@ -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"), @@ -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); @@ -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!");