Skip to content

Commit 0de7906

Browse files
author
Kevin Formsma
authored
Update Github Action (#581)
* Refactor primary Github Action - Support writing the output to a file - Add a test for uploading sarif to GH code scanning * Updated action readme example
1 parent f4b78de commit 0de7906

File tree

5 files changed

+47
-7
lines changed

5 files changed

+47
-7
lines changed

.github/workflows/github-action.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ on:
1212

1313
jobs:
1414
e2e:
15-
name: E2E test
15+
name: Action E2E test
1616
runs-on: ubuntu-latest
17+
permissions:
18+
security-events: write
1719

1820
steps:
1921
- uses: actions/checkout@master
@@ -36,3 +38,13 @@ jobs:
3638
with:
3739
input_path: github-action/tests
3840
extra_args: -o json --template-pattern clean
41+
- name: Test with SARIF output
42+
id: sarif
43+
uses: stelligent/cfn_nag@master
44+
with:
45+
input_path: github-action/tests
46+
extra_args: -o sarif
47+
output_path: cfn_nag.sarif
48+
- uses: github/codeql-action/upload-sarif@v1
49+
with:
50+
sarif_file: cfn_nag.sarif

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ inputs:
1111
extra_args:
1212
description: 'Additional arguments to pass to cfn_nag_scan, separated by space (default: "--print-suppression").'
1313
default: '--print-suppression'
14+
output_path:
15+
description: 'Destination file path for cfn_nag_scan output'
16+
default: 'cfn_nag.out'
1417
runs:
1518
using: docker
1619
image: github-action/Dockerfile

github-action/Dockerfile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
FROM stelligent/cfn_nag:latest
22

3-
ARG INPUT_EXTRA_ARGS=''
4-
ENV INPUT_EXTRA_ARGS="${INPUT_EXTRA_ARGS}"
3+
COPY entrypoint.sh /entrypoint.sh
54

6-
ARG INPUT_INPUT_PATH=''
7-
ENV INPUT_INPUT_PATH="${INPUT_INPUT_PATH}"
8-
9-
ENTRYPOINT ["sh", "-c", "cfn_nag_scan $INPUT_EXTRA_ARGS --input-path $INPUT_INPUT_PATH"]
5+
ENTRYPOINT [ "/entrypoint.sh" ]

github-action/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ The directory of the repo to search for violations. Default: `$GITHUB_WORKSPACE`
2020

2121
Additional arguments to pass to `cfn_nag_scan`. See the [usage for `cfn_nag_scan`](https://github.com/stelligent/cfn_nag#usage) for more options. Default: `--print-suppression`
2222

23+
### `output_path`
24+
25+
Destination file path for cfn_nag_scan output. Default: `cfn_nag.out`
2326
## Example Usages
2427

2528
### Basic
@@ -62,6 +65,21 @@ Search the `templates` directory within the GitHub runner's workspace and remove
6265
extra_args: ''
6366
```
6467

68+
### Define path to search and upload to code scanning
69+
70+
Search the `templates` directory and upload the results to GitHub's Code Scanning.
71+
72+
```
73+
- uses: stelligent/cfn_nag@master
74+
with:
75+
input_path: templates
76+
extra_args: -o sarif
77+
output_path: cfn_nag.sarif
78+
- uses: github/codeql-action/upload-sarif@v1
79+
with:
80+
sarif_file: cfn_nag.sarif
81+
```
82+
6583
## Support
6684

6785
To report a bug or request a feature, submit an issue through the GitHub repository via: https://github.com/stelligent/cfn_nag/issues/new

github-action/entrypoint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
echo "::debug::Using input path: ${INPUT_INPUT_PATH}"
4+
echo "::debug::Using output path: ${INPUT_OUTPUT_PATH}"
5+
6+
if [ -n "${INPUT_EXTRA_ARGS}" ]; then
7+
echo "::debug::Using specified extra args: ${INPUT_EXTRA_ARGS}"
8+
EXTRA_ARGS="${INPUT_EXTRA_ARGS}"
9+
fi
10+
11+
cfn_nag_scan ${EXTRA_ARGS} --input-path "${INPUT_INPUT_PATH}" | tee "${INPUT_OUTPUT_PATH}"

0 commit comments

Comments
 (0)