Skip to content

Commit ab90f8a

Browse files
Set SPECTRAL_DSN environment from JS instead of end-user workflow file (#12)
* Update index.js * Update README.md * Update main.yml * Update README.md * Update README.md * Update CI.yml * Update main.yml * Update CI.yml
1 parent a5026d7 commit ab90f8a

4 files changed

Lines changed: 30 additions & 39 deletions

File tree

.github/workflows/CI.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
name: CI
1+
name: CI on branch
22

33
# Controls when the workflow will run
44
on: [push, workflow_dispatch, pull_request]
55

6-
env:
7-
SPECTRAL_DSN: ${{ secrets.SPECTRAL_DSN }}
8-
96
jobs:
107
ubuntu-ci:
118
name: Spectral ubuntu CI
@@ -15,7 +12,7 @@ jobs:
1512
- name: Install and run Spectral CI
1613
uses: ./
1714
with:
18-
spectral-dsn: ${{ env.SPECTRAL_DSN }}
15+
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
1916
spectral-args: scan --ok
2017
ubuntu-audit:
2118
name: Spectral ubuntu audit
@@ -25,7 +22,7 @@ jobs:
2522
- name: Install and run Spectral Audit
2623
uses: ./
2724
with:
28-
spectral-dsn: ${{ env.SPECTRAL_DSN }}
25+
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
2926
spectral-args: github -k repo -t ${{ secrets.MY_GITHUB_TOKEN }} https://github.com/SpectralOps/spectral-github-action --include-tags base,audit --ok
3027
macos-ci:
3128
name: Spectral macos CI
@@ -35,7 +32,7 @@ jobs:
3532
- name: Install and run Spectral CI
3633
uses: ./
3734
with:
38-
spectral-dsn: ${{ env.SPECTRAL_DSN }}
35+
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
3936
spectral-args: scan --ok
4037
macos-audit:
4138
name: Spectral macos audit
@@ -45,7 +42,7 @@ jobs:
4542
- name: Install and run Spectral Audit
4643
uses: ./
4744
with:
48-
spectral-dsn: ${{ env.SPECTRAL_DSN }}
45+
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
4946
spectral-args: github -k repo -t ${{ secrets.MY_GITHUB_TOKEN }} https://github.com/SpectralOps/spectral-github-action --include-tags base,audit --ok
5047
windows-ci:
5148
name: Spectral windows CI
@@ -55,7 +52,7 @@ jobs:
5552
- name: Install and run Spectral CI
5653
uses: ./
5754
with:
58-
spectral-dsn: ${{ env.SPECTRAL_DSN }}
55+
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
5956
spectral-args: scan --ok
6057
windows-audit:
6158
name: Spectral windows audit
@@ -65,5 +62,5 @@ jobs:
6562
- name: Install and run Spectral Audit
6663
uses: ./
6764
with:
68-
spectral-dsn: ${{ env.SPECTRAL_DSN }}
65+
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
6966
spectral-args: github -k repo -t ${{ secrets.MY_GITHUB_TOKEN }} https://github.com/SpectralOps/spectral-github-action --include-tags base,audit --ok

.github/workflows/main.yml

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,66 @@
1-
name: CI
1+
name: CI (example)
22

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

6-
env:
7-
SPECTRAL_DSN: ${{ secrets.SPECTRAL_DSN }}
8-
96
jobs:
107
ubuntu-ci:
118
name: Spectral ubuntu CI
129
runs-on: ubuntu-latest
1310
steps:
1411
- uses: actions/checkout@v3
1512
- name: Install and run Spectral CI
16-
uses: spectralops/spectral-github-action@v3
13+
uses: spectralops/spectral-github-action@v4
1714
with:
18-
spectral-dsn: ${{ env.SPECTRAL_DSN }}
15+
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
1916
spectral-args: scan --ok
2017
ubuntu-audit:
2118
name: Spectral ubuntu audit
2219
runs-on: ubuntu-latest
2320
steps:
2421
- uses: actions/checkout@v3
2522
- name: Install and run Spectral Audit
26-
uses: spectralops/spectral-github-action@v3
23+
uses: spectralops/spectral-github-action@v4
2724
with:
28-
spectral-dsn: ${{ env.SPECTRAL_DSN }}
25+
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
2926
spectral-args: github -k repo -t ${{ secrets.MY_GITHUB_TOKEN }} https://github.com/SpectralOps/spectral-github-action --include-tags base,audit --ok
3027
macos-ci:
3128
name: Spectral macos CI
3229
runs-on: ubuntu-latest
3330
steps:
3431
- uses: actions/checkout@v3
3532
- name: Install and run Spectral CI
36-
uses: spectralops/spectral-github-action@v3
33+
uses: spectralops/spectral-github-action@v4
3734
with:
38-
spectral-dsn: ${{ env.SPECTRAL_DSN }}
35+
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
3936
spectral-args: scan --ok
4037
macos-audit:
4138
name: Spectral macos audit
4239
runs-on: ubuntu-latest
4340
steps:
4441
- uses: actions/checkout@v3
4542
- name: Install and run Spectral Audit
46-
uses: spectralops/spectral-github-action@v3
43+
uses: spectralops/spectral-github-action@v4
4744
with:
48-
spectral-dsn: ${{ env.SPECTRAL_DSN }}
45+
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
4946
spectral-args: github -k repo -t ${{ secrets.MY_GITHUB_TOKEN }} https://github.com/SpectralOps/spectral-github-action --include-tags base,audit --ok
5047
windows-ci:
5148
name: Spectral windows CI
5249
runs-on: windows-latest
5350
steps:
5451
- uses: actions/checkout@v3
5552
- name: Install and run Spectral CI
56-
uses: spectralops/spectral-github-action@v3
53+
uses: spectralops/spectral-github-action@v4
5754
with:
58-
spectral-dsn: ${{ env.SPECTRAL_DSN }}
55+
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
5956
spectral-args: scan --ok
6057
windows-audit:
6158
name: Spectral windows audit
6259
runs-on: windows-latest
6360
steps:
6461
- uses: actions/checkout@v3
6562
- name: Install and run Spectral Audit
66-
uses: spectralops/spectral-github-action@v3
63+
uses: spectralops/spectral-github-action@v4
6764
with:
6865
spectral-dsn: ${{ env.SPECTRAL_DSN }}
6966
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: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ 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: spectralops/spectral-github-action@v3
25+
uses: spectralops/spectral-github-action@v4
2626
with:
2727
spectral-dsn: $SPECTRAL_DSN
2828
spectral-args: scan --ok
@@ -32,47 +32,41 @@ You can see an example of this Action [here](https://github.com/SpectralOps/spec
3232

3333
## Configuration
3434

35-
You'll need to provide Spectral dsn. You can do so via the `SPECTRAL_DSN` environment variable. In the below example, the Spectral dsn is retrieved from [GitHub secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets).
35+
You'll need to provide Spectral DSN as an input variable. You should always store your DSN in a secure way, like below in [GitHub secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets).
3636

3737
```yaml
3838
name: Spectral
3939

4040
on: [push]
4141

42-
env:
43-
SPECTRAL_DSN: ${{ secrets.SPECTRAL_DSN }}
44-
4542
jobs:
4643
scan:
4744
runs-on: ubuntu-latest
4845
steps:
4946
- uses: actions/checkout@v3
5047
- name: Install and run Spectral CI
51-
uses: spectralops/spectral-github-action@v3
48+
uses: spectralops/spectral-github-action@v4
5249
with:
53-
spectral-dsn: ${{ env.SPECTRAL_DSN }}
50+
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
5451
spectral-args: scan --ok
5552
```
5653
57-
Spectral provides another scan option to audit your Github/Gitlab organizaion, user or repo.
54+
Spectral provides another scan option to audit your Github/Gitlab organization, user or repo.
5855
5956
```yaml
6057
name: Spectral
6158

6259
on: [push]
6360

64-
env:
65-
SPECTRAL_DSN: ${{ secrets.SPECTRAL_DSN }}
66-
6761
jobs:
6862
scan:
6963
runs-on: ubuntu-latest
7064
steps:
7165
- uses: actions/checkout@v3
7266
- name: Install and run Spectral Audit
73-
uses: spectralops/spectral-github-action@v3
67+
uses: spectralops/spectral-github-action@v4
7468
with:
75-
spectral-dsn: ${{ env.SPECTRAL_DSN }}
69+
spectral-dsn: ${{ secrets.SPECTRAL_DSN }}
7670
spectral-args: github -k repo -t ${{ secrets.MY_GITHUB_TOKEN }} https://github.com/SpectralOps/spectral-github-action --include-tags base,audit --ok
7771
```
7872

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ const workspace = process.env.GITHUB_WORKSPACE;
77
const spectralDsn = core.getInput('spectral-dsn')
88
const binDir = `${workspace}/bin`;
99

10+
// Provide SPECTRAL_DSN to spectral binary through env
11+
core.exportVariable('SPECTRAL_DSN', spectralDsn);
12+
1013
main().catch(error => {
1114
core.setFailed(error)
1215
})
@@ -55,4 +58,4 @@ async function runSpectral() {
5558
function getScanCommand() {
5659
const spectralArgs = core.getInput('spectral-args')
5760
return `${process.platform === 'win32' ? 'spectral.exe' : 'spectral'} ${spectralArgs}`
58-
}
61+
}

0 commit comments

Comments
 (0)