Skip to content

Commit e95d97c

Browse files
authored
Merge pull request #4 from SpectralOps/install-and-run
Install and run spectral in a single command
2 parents 1f7e8b8 + adcc0f5 commit e95d97c

File tree

6 files changed

+94
-28
lines changed

6 files changed

+94
-28
lines changed

.github/workflows/main.yml

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,69 @@
11
name: CI
22

3-
# Controls when the workflow will run
3+
# Controls when the workflow will run
44
on: [push, workflow_dispatch]
55

66
env:
77
SPECTRAL_DSN: ${{ secrets.SPECTRAL_DSN }}
88

99
jobs:
10-
ubuntu:
11-
name: Spectral ubuntu
10+
ubuntu-ci:
11+
name: Spectral ubuntu CI
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v2
15-
- name: Install Spectral
16-
uses: spectralops/spectral-github-action@v1
15+
- name: Install and run Spectral CI
16+
uses: spectralops/spectral-github-action@v2
1717
with:
1818
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
19-
- name: Spectral Scan
20-
run: spectral scan
21-
macOS:
22-
name: Spectral macOS
23-
runs-on: macos-latest
19+
spectral-args: scan --ok
20+
ubuntu-audit:
21+
name: Spectral ubuntu audit
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v2
25+
- name: Install and run Spectral Audit
26+
uses: spectralops/spectral-github-action@v2
27+
with:
28+
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
29+
spectral-args: github -k repo -t ${{ secrets.MY_GITHUB_TOKEN }} https://github.com/SpectralOps/spectral-github-action --include-tags base,audit --ok
30+
macos-ci:
31+
name: Spectral macos CI
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v2
35+
- name: Install and run Spectral CI
36+
uses: spectralops/spectral-github-action@v2
37+
with:
38+
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
39+
spectral-args: scan --ok
40+
macos-audit:
41+
name: Spectral macos audit
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v2
45+
- name: Install and run Spectral Audit
46+
uses: spectralops/spectral-github-action@v2
47+
with:
48+
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
49+
spectral-args: github -k repo -t ${{ secrets.MY_GITHUB_TOKEN }} https://github.com/SpectralOps/spectral-github-action --include-tags base,audit --ok
50+
windows-ci:
51+
name: Spectral windows CI
52+
runs-on: windows-latest
2453
steps:
2554
- uses: actions/checkout@v2
26-
- name: Install Spectral
27-
uses: spectralops/spectral-github-action@v1
55+
- name: Install and run Spectral CI
56+
uses: spectralops/spectral-github-action@v2
2857
with:
2958
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
30-
- name: Spectral Scan
31-
run: spectral scan
32-
windows:
33-
name: Spectral windows
59+
spectral-args: scan --ok
60+
windows-audit:
61+
name: Spectral windows audit
3462
runs-on: windows-latest
3563
steps:
3664
- uses: actions/checkout@v2
37-
- name: Install Spectral
38-
uses: spectralops/spectral-github-action@v1
65+
- name: Install and run Spectral Audit
66+
uses: spectralops/spectral-github-action@v2
3967
with:
4068
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
41-
- name: Spectral Scan
42-
run: spectral.exe scan
69+
spectral-args: github -k repo -t ${{ secrets.MY_GITHUB_TOKEN }} https://github.com/SpectralOps/spectral-github-action --include-tags base,audit --ok

README.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ Spectral Scan is a single self-contained binary, that's easy to get and use. Thi
2222
Include this Action as a step in your workflow:
2323

2424
```
25-
uses: spectral/spectral-action@v1
25+
uses: spectral/spectral-action@v2
2626
with:
27-
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
27+
spectral-dsn: $SPECTRAL_DSN
28+
spectral-args: --ok
2829
```
2930

3031
You can see an example of this Action [here](https://github.com/SpectralOps/spectral-github-action/tree/main/.github/workflows/main.yml)
@@ -47,13 +48,36 @@ jobs:
4748
steps:
4849
- uses: actions/checkout@v2
4950
- name: Install Spectral
50-
uses: spectralops/spectral-github-action@v1
51+
uses: spectralops/spectral-github-action@v2
5152
with:
52-
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
53+
spectral-dsn: $SPECTRAL_DSN
54+
spectral-args: --ok
5355
- name: Spectral Scan
5456
run: spectral scan
5557
```
5658
59+
Spectral provides another scan option to audit your Github/Gitlab organizaion, user or repo.
60+
61+
```yaml
62+
name: Spectral
63+
64+
on: [push]
65+
66+
env:
67+
SPECTRAL_DSN: ${{ secrets.SPECTRAL_DSN }}
68+
69+
jobs:
70+
scan:
71+
runs-on: ubuntu-latest
72+
steps:
73+
- uses: actions/checkout@v2
74+
- name: Install and run Spectral Audit
75+
uses: spectralops/spectral-github-action@v2
76+
with:
77+
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
78+
spectral-args: github -k repo -t ${{ secrets.MY_GITHUB_TOKEN }} https://github.com/SpectralOps/spectral-github-action --include-tags base,audit --ok
79+
```
80+
5781
### How to Contribute
5882
5983
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!

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ inputs:
44
spectral-dsn:
55
description: "Your Spectral DSN"
66
required: true
7+
spectral-args:
8+
description: "Arguments for Spectral scan"
9+
required: true
710
branding:
811
icon: "download"
912
color: "purple"

index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
const core = require('@actions/core');
22
const io = require('@actions/io');
33
const tc = require('@actions/tool-cache');
4+
const exec = require("@actions/exec").exec;
45

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

810
main().catch(error => {
@@ -21,14 +23,14 @@ async function main() {
2123
await installZip(binDir, 'mac')
2224
break;
2325
default:
24-
break;
26+
throw new Error(`Platform: ${process.platform} is not supported`);
2527
}
2628

2729
await core.addPath(binDir)
30+
await runSpectral()
2831
}
2932

3033
async function downloadTool(platform) {
31-
const spectralDsn = core.getInput('spectral-dsn')
3234
const url = `${spectralDsn}/latest/dl/${platform}`
3335
return await tc.downloadTool(url);
3436
}
@@ -43,4 +45,14 @@ async function installExecutable(path) {
4345
await io.mkdirP(path);
4446
const downloadPath = await downloadTool('exe')
4547
await io.mv(downloadPath, `${path}/spectral.exe`)
48+
}
49+
50+
async function runSpectral() {
51+
const scanCommand = getScanCommand()
52+
await exec(scanCommand)
53+
}
54+
55+
function getScanCommand() {
56+
const spectralArgs = core.getInput('spectral-args')
57+
return `${process.platform === 'win32' ? 'spectral.exe' : 'spectral'} ${spectralArgs}`
4658
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
"@actions/io": "^1.1.1",
2121
"@actions/tool-cache": "^1.7.1"
2222
}
23-
}
23+
}

0 commit comments

Comments
 (0)