This repository has been archived by the owner on Apr 18, 2024. It is now read-only.
forked from gitleaks/gitleaks-action
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentrypoint.sh
executable file
·41 lines (35 loc) · 1.55 KB
/
entrypoint.sh
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
#!/bin/bash
INPUT_CONFIG_PATH="$1"
CONFIG=" --config-path=/gitleaks.toml"
# generate empty report file with `null` content
echo null > $GITHUB_WORKSPACE/gitleaks-output.json
# check if a custom config have been provided
if [ -f "$GITHUB_WORKSPACE/$INPUT_CONFIG_PATH" ]; then
CONFIG="$CONFIG --additional-config=$GITHUB_WORKSPACE/$INPUT_CONFIG_PATH"
fi
echo running gitleaks "$(gitleaks --version) with the following command👇"
if [ "$GITHUB_EVENT_NAME" = "pull_request" ]
then
git --git-dir="$GITHUB_WORKSPACE/.git" log --left-right --cherry-pick --pretty=format:"%H" remotes/origin/$GITHUB_BASE_REF... > commit_list.txt
echo gitleaks --path=$GITHUB_WORKSPACE --verbose --redact --commits-file=commit_list.txt $CONFIG
CAPTURE_OUTPUT=$(gitleaks --path=$GITHUB_WORKSPACE --verbose --redact --commits-file=commit_list.txt $CONFIG)
else
echo gitleaks --path=$GITHUB_WORKSPACE --verbose --report=gitleaks-output.json --redact $CONFIG
CAPTURE_OUTPUT=$(gitleaks --path=$GITHUB_WORKSPACE --verbose --report=gitleaks-output.json --redact $CONFIG)
fi
if [ $? -eq 1 ]
then
GITLEAKS_RESULT=$(echo -e "\e[31m🛑 STOP! Gitleaks encountered leaks")
echo "$GITLEAKS_RESULT"
echo "::set-output name=exitcode::1"
echo "----------------------------------"
echo "$CAPTURE_OUTPUT"
echo "::set-output name=result::$CAPTURE_OUTPUT"
echo "----------------------------------"
exit 1
else
GITLEAKS_RESULT=$(echo -e "\e[32m✅ SUCCESS! Your code is good to go!")
echo "$GITLEAKS_RESULT"
echo "::set-output name=exitcode::0"
echo "------------------------------------"
fi