Skip to content

Commit 3bfac59

Browse files
committed
chore: refactor into re-usable worflow
Signed-off-by: Michael Dawson <[email protected]>
1 parent becab5b commit 3bfac59

File tree

2 files changed

+63
-45
lines changed

2 files changed

+63
-45
lines changed

.github/workflows/check-vulns.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Reusable flow to check for vunls in Depenencies of Node.js branch
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
nodejsStream:
7+
type: string
8+
default: 'main'
9+
secrets:
10+
VULN_CHECK_TOKEN:
11+
required: true
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
check-vulns:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Setup Python 3.9
21+
uses: actions/setup-python@v3
22+
with:
23+
python-version: '3.9'
24+
- name: Checkout node.js repo
25+
uses: actions/checkout@v3
26+
with:
27+
repository: nodejs/node
28+
path: node
29+
ref: ${{ inputs.nodejsStream }}
30+
- name: Installing pre-reqs
31+
run: |
32+
cd ${{ github.workspace }}/node/tools/dep_checker
33+
pip install -r requirements.txt
34+
- name: Run the check
35+
run: |
36+
cd ${{ github.workspace }}/node/tools/dep_checker
37+
(
38+
set -o pipefail
39+
python main.py --gh-token ${{ secrets.VULN_CHECK_TOKEN }} 2>&1 | tee result.log
40+
)
41+
- name: collect error
42+
id: collect_error
43+
if: ${{ failure() }}
44+
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
51+
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 }}"}'

.github/workflows/daily-main.yml

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ name: Check main for vulns daily
22

33
on:
44
workflow_dispatch:
5-
inputs:
6-
nodejsStream:
7-
default: 'main'
85
schedule:
96
- cron: 0 0 * * *
107

@@ -13,45 +10,7 @@ permissions:
1310

1411
jobs:
1512
check-vulns:
16-
runs-on: ubuntu-latest
17-
steps:
18-
- name: Setup Python 3.9
19-
uses: actions/setup-python@v3
20-
with:
21-
python-version: '3.9'
22-
- name: Checkout node.js repo
23-
uses: actions/checkout@v3
24-
with:
25-
repository: nodejs/node
26-
path: node
27-
ref: ${{ github.event.inputs.nodejsStream || 'main' }}
28-
- name: Installing pre-reqs
29-
run: |
30-
cd ${{ github.workspace }}/node/tools/dep_checker
31-
pip install -r requirements.txt
32-
- name: Run the check
33-
run: |
34-
cd ${{ github.workspace }}/node/tools/dep_checker
35-
(
36-
set -o pipefail
37-
python main.py --gh-token ${{ secrets.VULN_CHECK_TOKEN }} 2>&1 | tee result.log
38-
)
39-
- name: collect error
40-
id: collect_error
41-
if: ${{ failure() }}
42-
run: |
43-
cd ${{ github.workspace }}/node/tools/dep_checker
44-
result=`cat result.log`
45-
curdate=`date`
46-
echo "::set-output name=date::$curdate"
47-
echo "::set-output name=result::$result"
48-
- name: check for failure
49-
if: ${{ failure() }}
50-
run: |
51-
curl --request POST \
52-
--url https://api.github.com/repos/${{ github.repository }}/issues \
53-
--header 'Authorization: token ${{ secrets.VULN_CHECK_TOKEN }}' \
54-
--header 'Accept: application/vnd.github+json' \
55-
--data '{
56-
"title": "Vulnerability check reported failure - ${{ steps.collect_error.outputs.date }}",
57-
"body": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} \\\n${{ steps.collect_error.outputs.result }}"}'
13+
uses: ./.github/workflows/check-vulns.yml
14+
with:
15+
nodejsStream: main
16+
secrets: inherit

0 commit comments

Comments
 (0)