-
Notifications
You must be signed in to change notification settings - Fork 0
70 lines (61 loc) · 2.08 KB
/
secrets-scan.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
name: Secrets Scan with Trivy
on:
pull_request:
jobs:
filter:
runs-on: ubuntu-latest
if: ${{ !contains(github.actor, '[bot]') }} # [bot]を含む場合は除外する
outputs:
workdirs: ${{ steps.dirs.outputs.workdirs }}
steps:
- name: Checkout
uses: actions/[email protected]
with:
ref: ${{ github.head_ref }}
- name: Fetch PR base ref
run: |
git fetch --depth=1 origin ${{ github.base_ref }}:${{ github.base_ref }}
# 変更の入ったディレクトリのみ取得する
- name: Get changed directories
id: dirs
run: |
workdirs=$(git diff --name-only ${{ github.base_ref }} ${{ github.head_ref }} | xargs -I {} dirname {} | sort | uniq | jq -R -s -c 'split("\n")[:-1]')
echo "workdirs=$workdirs" >> $GITHUB_OUTPUT
scan:
needs: filter
runs-on: ubuntu-latest
if: ${{ !contains(github.actor, '[bot]') }} # [bot]を含む場合は除外する
strategy:
matrix:
workdir: ${{ fromJSON(needs.filter.outputs.workdirs) }}
steps:
- name: Checkout
uses: actions/[email protected]
with:
ref: ${{ github.head_ref }}
- name: Check if workdir exists
id: check
run: |
if [ -d "${{ matrix.workdir }}" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Run Aqua Security Trivy
uses: aquasecurity/[email protected]
with:
scan-type: fs
scan-ref: ${{ matrix.workdir }}
severity: UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL # default
scanners: secret
output: trivy.txt
exit-code: 1
if: steps.check.outputs.exists == 'true'
- name: Post PR comments
if: failure()
env:
GITHUB_TOKEN: ${{ github.token }}
URL: ${{ github.event.pull_request.html_url }}
run: |
sed -i -e '1i ```' -e '$a ```\nこのactionについては [Notion](https://www.notion.so/globisorg/GitHub-dcb884f8df2646df8d8e686bd6290d46) を参照。' trivy.txt
gh pr comment -F ./trivy.txt "${URL}"