Skip to content

Commit fa42160

Browse files
authored
Refactor and improve input options (#8)
1 parent f53beac commit fa42160

File tree

15 files changed

+9210
-2636
lines changed

15 files changed

+9210
-2636
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
test-data/java-with-security-standard-tag.sarif
2+
13
# Dependency directory
24
node_modules
35

.prettierrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"printWidth": 80,
2+
"printWidth": 150,
33
"tabWidth": 2,
44
"useTabs": false,
55
"semi": false,

.vscode/launch.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@
1111
"skipFiles": [
1212
"<node_internals>/**"
1313
],
14-
"preLaunchTask": "tsc: build - tsconfig.json",
14+
"preLaunchTask": "Build & remove output SARIF file",
1515
"outFiles": ["${workspaceFolder}/lib/**/*.js"],
1616
"program": "${workspaceFolder}/src/main.ts",
17-
"args": ["--sarifFile", "${workspaceFolder}/testdata/java.sarif", "--cweFile", "${workspaceFolder}/testdata/1344.xml"],
17+
"args": [
18+
"--sarifFile", "${workspaceFolder}/test-data/webgoat.sarif",
19+
"--cweFile", "${workspaceFolder}/security-standards/owasp-top10-2021.xml",
20+
"--securityStandardTag", "owasp-top10-2021",
21+
"--outputFile", "${workspaceFolder}/test-data/webgoat-with-security-standard-tag.sarif"
22+
],
1823
}
1924
]
2025
}

.vscode/tasks.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "Remove output SARIF file",
8+
"type": "shell",
9+
"command": "rm ${workspaceFolder}/test-data/java-with-security-standard-tag.sarif"
10+
},
11+
{
12+
"label": "Build & remove output SARIF file",
13+
"dependsOn": [
14+
"Remove output SARIF file",
15+
"tsc: build - tsconfig.json"
16+
],
17+
}
18+
]
19+
}

README.md

Lines changed: 22 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,29 @@
1-
<p align="center">
2-
<a href="https://github.com/actions/typescript-action/actions"><img alt="typescript-action status" src="https://github.com/actions/typescript-action/workflows/build-test/badge.svg"></a>
3-
</p>
1+
# codeql-sarif-security-standard-annotator
42

5-
# Create a JavaScript Action using TypeScript
3+
Compare a CodeQL SARIF results file to a security standard CWE list and annotate the SARIF rules with a tag to highlight results applicable to the security standard
64

7-
Use this template to bootstrap the creation of a TypeScript action.:rocket:
5+
## Usage in GitHub Actions
86

9-
This template includes compilation support, tests, a validation workflow, publishing, and versioning guidance.
10-
11-
If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action)
12-
13-
## Create an action from this template
14-
15-
Click the `Use this Template` and provide the new repo details for your action
16-
17-
## Code in Main
18-
19-
> First, you'll need to have a reasonably modern version of `node` handy. This won't work with versions older than 9, for instance.
20-
21-
Install the dependencies
22-
```bash
23-
$ npm install
24-
```
25-
26-
Build the typescript and package it for distribution
27-
```bash
28-
$ npm run build && npm run package
29-
```
30-
31-
Run the tests :heavy_check_mark:
32-
```bash
33-
$ npm test
34-
35-
PASS ./index.test.js
36-
✓ throws invalid number (3ms)
37-
wait 500 ms (504ms)
38-
test runs (95ms)
39-
40-
...
41-
```
42-
43-
## Change action.yml
44-
45-
The action.yml defines the inputs and output for your action.
46-
47-
Update the action.yml with your name, description, inputs and outputs for your action.
48-
49-
See the [documentation](https://help.github.com/en/articles/metadata-syntax-for-github-actions)
50-
51-
## Change the Code
52-
53-
Most toolkit and CI/CD operations involve async operations so the action is run in an async function.
54-
55-
```javascript
56-
import * as core from '@actions/core';
57-
...
58-
59-
async function run() {
60-
try {
61-
...
62-
}
63-
catch (error) {
64-
core.setFailed(error.message);
65-
}
66-
}
67-
68-
run()
697
```
70-
71-
See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages.
72-
73-
## Publish to a distribution branch
74-
75-
Actions are run from GitHub repos so we will checkin the packed dist folder.
76-
77-
Then run [ncc](https://github.com/zeit/ncc) and push the results:
78-
```bash
79-
$ npm run package
80-
$ git add dist
81-
$ git commit -a -m "prod dependencies"
82-
$ git push origin releases/v1
8+
- name: Annotate CodeQL SARIF with OWASP Top 10 2021 tag
9+
uses: ctcampbell/codeql-sarif-security-standard-annotator@v1
8310
```
8411

85-
Note: We recommend using the `--license` option for ncc, which will create a license file for all of the production node modules used in your project.
86-
87-
Your action is now published! :rocket:
88-
89-
See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
90-
91-
## Validate
92-
93-
You can now validate the action by referencing `./` in a workflow in your repo (see [test.yml](.github/workflows/test.yml))
94-
95-
```yaml
96-
uses: ./
97-
with:
98-
milliseconds: 1000
9912
```
100-
101-
See the [actions tab](https://github.com/actions/typescript-action/actions) for runs of this action! :rocket:
102-
103-
## Usage:
104-
105-
After testing you can [create a v1 tag](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) to reference the stable and latest V1 action
13+
inputs:
14+
sarifFile:
15+
required: true
16+
description: 'The CodeQL SARIF result file'
17+
cweFile:
18+
required: false
19+
description: 'The CWE list XML file'
20+
default: '${{ github.action_path }}/security-standards/owasp-top10-2021.xml'
21+
securityStandardTag:
22+
required: false
23+
description: 'The security standard tag to add to the SARIF file'
24+
default: 'owasp-top10-2021'
25+
outputFile:
26+
required: false
27+
description: 'The output SARIF file path, defaults to the input SARIF file path'
28+
default: '${{ inputs.sarifFile }}'
29+
```

action.yml

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
1-
name: 'Sarif To Security Standard Report'
2-
description: 'Compare a SARIF results file to a security standard CWE list and produce a report'
1+
name: 'codeql-sarif-security-standard-annotator'
2+
description: 'Compare a CodeQL SARIF results file to a security standard CWE list and annotate the SARIF rules with a tag to highlight results applicable to the security standard'
33
author: 'GitHub, Inc'
44
inputs:
55
sarifFile:
66
required: true
7-
description: 'The SARIF file to compare'
7+
description: 'The CodeQL SARIF result file'
88
cweFile:
9-
required: true
10-
description: 'The CWE file to compare'
9+
required: false
10+
description: 'The CWE list XML file'
11+
default: '${{ github.action_path }}/security-standards/owasp-top10-2021.xml'
12+
securityStandardTag:
13+
required: false
14+
description: 'The security standard tag to add to the SARIF file'
15+
default: 'owasp-top10-2021'
16+
outputFile:
17+
required: false
18+
description: 'The output SARIF file path, defaults to the input SARIF file path'
19+
default: '${{ inputs.sarifFile }}'
1120
runs:
12-
using: 'node16'
13-
main: 'dist/index.js'
21+
using: 'composite'
22+
steps:
23+
- run: |
24+
node '${{ github.action_path }}/dist/index.js' \
25+
--sarifFile '${{ inputs.sarifFile }}' \
26+
--cweFile '${{ inputs.cweFile }}' \
27+
--securityStandardTag '${{ inputs.securityStandardTag }}' \
28+
--outputFile '${{ inputs.outputFile }}'
29+
shell: bash

0 commit comments

Comments
 (0)