-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.yml
72 lines (63 loc) · 2.82 KB
/
config.yml
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
71
72
# Set $GH_USER and $GH_TOKEN as CircleCI Project Environment Variables
version: 2.1
jobs:
packj-audit:
docker:
- image: circleci/python:3.8
steps:
- checkout
- run: python -m venv venv
- run: source venv/bin/activate
- run: git clone https://github.com/ossillate-inc/packj
- run: /usr/local/bin/python -m pip install --upgrade pip
- run: pip install -r ./packj/requirements.txt
- run:
name: Audit dependency files with Packj
command: |
input=$(echo $DEPENDENCY_FILES | sed 's/,/ /g')
input_files=()
for item in $input
do
if [[ $item == *":"* ]]; then
pm_name=$(echo $item | cut -f1 -d:)
dep_file=$(echo $item | cut -f2 -d:)
input_files+=$pm_name":"$dep_file,
fi
done
if [ ! -z input_files ]; then
input=$(echo $input_files | sed 's/,/ /g')
python ./packj/main.py audit -f $input
fi
- run:
name: Comment on GitHub pull request
command: |
ls /tmp/packj_audit_*/*.html -al
if [ -f /tmp/packj_audit_*/*.html ]; then
html_report=$(ls /tmp/packj_audit_*/*.html)
cat $html_report |head -n -2 |tail -n +10 |sed 's/^[\s\t\r]*//g' > GITHUB_COMMENT.md
else
echo "<h4>Failed to perform Packj audit! Refer to workflow run for details</h4>" > GITHUB_COMMENT.md
fi
sudo apt-get install jq
# Install gh CLI
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh -y
pr_response=$(curl --location --request GET "https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/pulls?base=$CIRCLE_BRANCH&state=open" -u $GH_USER:$GH_TOKEN)
if [ $(echo $pr_response |jq length) -eq 0 ]; then
echo "No PR found to update"
else
pr_number=$(echo $pr_response |jq -r ".[].number")
gh pr comment $pr_number --body-file GITHUB_COMMENT.md
fi
environment:
DEPENDENCY_FILES: pypi:requirements.txt,npm:package.json,rubygems:Gemfile
workflows:
test:
jobs:
- packj-audit:
filters:
branches:
only: main