Skip to content

Commit 7f575ec

Browse files
authored
Merge pull request #17 from homoluctus/feature/support_env_var
Support IMAGE_NAME environment variable
2 parents 2c31990 + c6e18f2 commit 7f575ec

File tree

6 files changed

+54
-7
lines changed

6 files changed

+54
-7
lines changed

.github/workflows/test.yml

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ name: Test my typescript action
22

33
on: pull_request
44

5+
env:
6+
IMAGE_NAME: alpine:3.10.1
7+
58
jobs:
6-
test:
7-
name: Test
9+
test1:
10+
name: Test for with parameter
811
runs-on: ubuntu-18.04
912
steps:
1013
- uses: actions/checkout@v1
@@ -36,3 +39,36 @@ jobs:
3639
job_name: ':ts: *test gitrivy*'
3740
channel: '#develop'
3841
url: ${{ secrets.SLACK_WEBHOOK }}
42+
43+
test2:
44+
name: Test for getting image name from enviroment variable
45+
runs-on: ubuntu-18.04
46+
steps:
47+
- uses: actions/checkout@v1
48+
49+
- name: Install dependencies
50+
run: npm install
51+
52+
# - name: Test
53+
# run: npm run test
54+
55+
- name: Build
56+
run: npm run build
57+
58+
- name: Pull docker image
59+
run: docker pull alpine:3.10.3
60+
61+
- uses: ./
62+
with:
63+
token: ${{ secrets.GITHUB_TOKEN }}
64+
issue_label: trivy,vulnerability,test
65+
issue_title: Security Alert Test
66+
issue_assignee: homoluctus
67+
68+
- uses: homoluctus/[email protected]
69+
if: always()
70+
with:
71+
type: ${{ job.status }}
72+
job_name: ':ts: *test gitrivy*'
73+
channel: '#develop'
74+
url: ${{ secrets.SLACK_WEBHOOK }}

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
![GitHub](https://img.shields.io/github/license/homoluctus/gitrivy?color=brightgreen)
55

66
This is a GitHub Actions to scan vulnerability using [Trivy](https://github.com/aquasecurity/trivy).<br>
7+
If vulnerabilities are found by Trivy, it creates the following GitHub Issue.
8+
9+
![image](https://github.com/homoluctus/gitrivy/blob/master/issue.png)
710

811
## Usage
912

@@ -13,7 +16,7 @@ This is a GitHub Actions to scan vulnerability using [Trivy](https://github.com/
1316
|:--:|:--:|:--:|:--|
1417
|token|True|N/A|GitHub access token<br>${{ secrets.GITHUB_TOKEN }} is recommended|
1518
|trivy_version|False|latest|Trivy version|
16-
|image|True|N/A|The target image name to scan the vulnerability|
19+
|image|True|N/A|The target image name to scan the vulnerability<br>Specify this parameter or `IMAGE_NAME` environment variable|
1720
|severity|False|HIGH,CRITICAL|Sevirities of vulunerabilities (separeted by commma)|
1821
|vuln_type|False|os,library|Scan target are os and / or library (separeted by commma)|
1922
|ignore_unfixed|False|false|Ignore unfixed vulnerabilities<br>Specify true or false|

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ inputs:
1010
default: 'latest'
1111
required: false
1212
image:
13-
description: 'The target image name of vulnerability scan'
14-
required: true
13+
description: 'The target image name of vulnerability scan (specify this parameter or "IMAGE_NAME" environment variable'
14+
required: false
1515
severity:
1616
description: 'sevirities of vulunerabilities (separeted by commma)'
1717
default: 'HIGH,CRITICAL'

dist/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6659,7 +6659,10 @@ function run() {
66596659
try {
66606660
const token = core.getInput('token', { required: true });
66616661
const trivyVersion = core.getInput('trivy_version').replace(/^v/, '');
6662-
const image = core.getInput('image', { required: true });
6662+
const image = core.getInput('image') || process.env.IMAGE_NAME;
6663+
if (image === undefined || image === '') {
6664+
throw new Error('Please specify scan target image name');
6665+
}
66636666
const trivyOptions = {
66646667
severity: core.getInput('severity').replace(/\s+/g, ''),
66656668
vulnType: core.getInput('vuln_type').replace(/\s+/g, ''),

issue.png

64.3 KB
Loading

src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ async function run() {
99
try {
1010
const token: string = core.getInput('token', { required: true })
1111
const trivyVersion: string = core.getInput('trivy_version').replace(/^v/, '')
12-
const image: string = core.getInput('image', { required: true })
12+
const image: string | undefined = core.getInput('image') || process.env.IMAGE_NAME
13+
14+
if (image === undefined || image === '') {
15+
throw new Error('Please specify scan target image name')
16+
}
17+
1318
const trivyOptions: TrivyOption = {
1419
severity: core.getInput('severity').replace(/\s+/g, ''),
1520
vulnType: core.getInput('vuln_type').replace(/\s+/g, ''),

0 commit comments

Comments
 (0)