Skip to content

Commit 17f7ed6

Browse files
committed
refactor: simplify and fix action that checks for vulns
This commit changes the following: - Allow to manually trigger the action from the GH web UI (via workflow_dispatch) - Fix the output of the script being truncated to a single line - Use the automatically generated GITHUB_TOKEN instead of providing a personal token - Use `working-directory:` instead of calling `cd` - Create issues using the `create-an-issue` action, instead of using the GitHub API
1 parent 3bfac59 commit 17f7ed6

File tree

2 files changed

+40
-23
lines changed

2 files changed

+40
-23
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: Vulnerability check reported failure on {{ env.NODEJS_STREAM }} - {{ date | date('YYYY-MM-DD') }}
3+
asignees:
4+
labels:
5+
---
6+
Failed run: {{ env.ACTION_URL }}
7+
8+
Output:
9+
--------------------
10+
```
11+
{{ env.ERROR_MSG }}
12+
```

.github/workflows/check-vulns.yml

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
name: Reusable flow to check for vunls in Depenencies of Node.js branch
1+
name: Reusable flow to check for vulns in dependencies of a Node.js branch
22

33
on:
44
workflow_call:
55
inputs:
66
nodejsStream:
77
type: string
88
default: 'main'
9-
secrets:
10-
VULN_CHECK_TOKEN:
11-
required: true
9+
workflow_dispatch:
10+
inputs:
11+
nodejsStream:
12+
type: string
13+
default: 'main'
14+
1215

1316
permissions:
1417
contents: read
18+
issues: write
1519

1620
jobs:
1721
check-vulns:
@@ -28,32 +32,33 @@ jobs:
2832
path: node
2933
ref: ${{ inputs.nodejsStream }}
3034
- name: Installing pre-reqs
31-
run: |
32-
cd ${{ github.workspace }}/node/tools/dep_checker
33-
pip install -r requirements.txt
35+
working-directory: ./node/tools/dep_checker
36+
run: pip install -r requirements.txt
3437
- name: Run the check
38+
working-directory: ./node/tools/dep_checker
3539
run: |
36-
cd ${{ github.workspace }}/node/tools/dep_checker
3740
(
3841
set -o pipefail
39-
python main.py --gh-token ${{ secrets.VULN_CHECK_TOKEN }} 2>&1 | tee result.log
42+
python main.py --gh-token ${{ secrets.GITHUB_TOKEN }} 2>&1 | tee result.log
4043
)
4144
- name: collect error
4245
id: collect_error
4346
if: ${{ failure() }}
47+
working-directory: ./node/tools/dep_checker
4448
run: |
45-
cd ${{ github.workspace }}/node/tools/dep_checker
46-
result=`cat result.log`
47-
curdate=`date`
48-
echo "::set-output name=date::$curdate"
49-
echo "::set-output name=result::$result"
50-
- name: check for failure
49+
content=$(cat result.log)
50+
# New lines must be escaped since outputs cannot be multi-line
51+
content="${content//'%'/'%25'}"
52+
content="${content//$'\n'/'%0A'}"
53+
content="${content//$'\r'/'%0D'}"
54+
echo "::set-output name=result::$content"
55+
- uses: actions/checkout@v3
5156
if: ${{ failure() }}
52-
run: |
53-
curl --request POST \
54-
--url https://api.github.com/repos/${{ github.repository }}/issues \
55-
--header 'Authorization: token ${{ secrets.VULN_CHECK_TOKEN }}' \
56-
--header 'Accept: application/vnd.github+json' \
57-
--data '{
58-
"title": "Vulnerability check reported failure on ${{inputs.nodejsStream}} - ${{ steps.collect_error.outputs.date }}",
59-
"body": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} \\\n${{ steps.collect_error.outputs.result }}"}'
57+
- uses: JasonEtco/create-an-issue@v2
58+
if: ${{ failure() }}
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
ERROR_MSG: ${{ steps.collect_error.outputs.result }}
62+
NODEJS_STREAM: ${{ inputs.nodejsStream }}
63+
ACTION_URL: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
64+

0 commit comments

Comments
 (0)