Skip to content

Commit

Permalink
Merge pull request #4 from SpectralOps/install-and-run
Browse files Browse the repository at this point in the history
Install and run spectral in a single command
  • Loading branch information
guylev008 authored May 17, 2022
2 parents 1f7e8b8 + adcc0f5 commit e95d97c
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 28 deletions.
67 changes: 47 additions & 20 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,69 @@
name: CI

# Controls when the workflow will run
# Controls when the workflow will run
on: [push, workflow_dispatch]

env:
SPECTRAL_DSN: ${{ secrets.SPECTRAL_DSN }}

jobs:
ubuntu:
name: Spectral ubuntu
ubuntu-ci:
name: Spectral ubuntu CI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Spectral
uses: spectralops/spectral-github-action@v1
- name: Install and run Spectral CI
uses: spectralops/spectral-github-action@v2
with:
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
- name: Spectral Scan
run: spectral scan
macOS:
name: Spectral macOS
runs-on: macos-latest
spectral-args: scan --ok
ubuntu-audit:
name: Spectral ubuntu audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install and run Spectral Audit
uses: spectralops/spectral-github-action@v2
with:
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
spectral-args: github -k repo -t ${{ secrets.MY_GITHUB_TOKEN }} https://github.com/SpectralOps/spectral-github-action --include-tags base,audit --ok
macos-ci:
name: Spectral macos CI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install and run Spectral CI
uses: spectralops/spectral-github-action@v2
with:
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
spectral-args: scan --ok
macos-audit:
name: Spectral macos audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install and run Spectral Audit
uses: spectralops/spectral-github-action@v2
with:
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
spectral-args: github -k repo -t ${{ secrets.MY_GITHUB_TOKEN }} https://github.com/SpectralOps/spectral-github-action --include-tags base,audit --ok
windows-ci:
name: Spectral windows CI
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Install Spectral
uses: spectralops/spectral-github-action@v1
- name: Install and run Spectral CI
uses: spectralops/spectral-github-action@v2
with:
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
- name: Spectral Scan
run: spectral scan
windows:
name: Spectral windows
spectral-args: scan --ok
windows-audit:
name: Spectral windows audit
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Install Spectral
uses: spectralops/spectral-github-action@v1
- name: Install and run Spectral Audit
uses: spectralops/spectral-github-action@v2
with:
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
- name: Spectral Scan
run: spectral.exe scan
spectral-args: github -k repo -t ${{ secrets.MY_GITHUB_TOKEN }} https://github.com/SpectralOps/spectral-github-action --include-tags base,audit --ok
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ Spectral Scan is a single self-contained binary, that's easy to get and use. Thi
Include this Action as a step in your workflow:

```
uses: spectral/spectral-action@v1
uses: spectral/spectral-action@v2
with:
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
spectral-dsn: $SPECTRAL_DSN
spectral-args: --ok
```

You can see an example of this Action [here](https://github.com/SpectralOps/spectral-github-action/tree/main/.github/workflows/main.yml)
Expand All @@ -47,13 +48,36 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Install Spectral
uses: spectralops/spectral-github-action@v1
uses: spectralops/spectral-github-action@v2
with:
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
spectral-dsn: $SPECTRAL_DSN
spectral-args: --ok
- name: Spectral Scan
run: spectral scan
```
Spectral provides another scan option to audit your Github/Gitlab organizaion, user or repo.
```yaml
name: Spectral

on: [push]

env:
SPECTRAL_DSN: ${{ secrets.SPECTRAL_DSN }}

jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install and run Spectral Audit
uses: spectralops/spectral-github-action@v2
with:
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
spectral-args: github -k repo -t ${{ secrets.MY_GITHUB_TOKEN }} https://github.com/SpectralOps/spectral-github-action --include-tags base,audit --ok
```
### How to Contribute
We welcome [issues](https://github.com/SpectralOps/spectral-github-action/issues) to and [pull requests](https://github.com/SpectralOps/spectral-github-action/pulls) against this repository!
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ inputs:
spectral-dsn:
description: "Your Spectral DSN"
required: true
spectral-args:
description: "Arguments for Spectral scan"
required: true
branding:
icon: "download"
color: "purple"
Expand Down
16 changes: 14 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const core = require('@actions/core');
const io = require('@actions/io');
const tc = require('@actions/tool-cache');
const exec = require("@actions/exec").exec;

const workspace = process.env.GITHUB_WORKSPACE;
const spectralDsn = core.getInput('spectral-dsn')
const binDir = `${workspace}/bin`;

main().catch(error => {
Expand All @@ -21,14 +23,14 @@ async function main() {
await installZip(binDir, 'mac')
break;
default:
break;
throw new Error(`Platform: ${process.platform} is not supported`);
}

await core.addPath(binDir)
await runSpectral()
}

async function downloadTool(platform) {
const spectralDsn = core.getInput('spectral-dsn')
const url = `${spectralDsn}/latest/dl/${platform}`
return await tc.downloadTool(url);
}
Expand All @@ -43,4 +45,14 @@ async function installExecutable(path) {
await io.mkdirP(path);
const downloadPath = await downloadTool('exe')
await io.mv(downloadPath, `${path}/spectral.exe`)
}

async function runSpectral() {
const scanCommand = getScanCommand()
await exec(scanCommand)
}

function getScanCommand() {
const spectralArgs = core.getInput('spectral-args')
return `${process.platform === 'win32' ? 'spectral.exe' : 'spectral'} ${spectralArgs}`
}
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
"@actions/io": "^1.1.1",
"@actions/tool-cache": "^1.7.1"
}
}
}

0 comments on commit e95d97c

Please sign in to comment.