Skip to content

Commit f3b7c13

Browse files
appleboykashifkhan0771nabeelalam
authored
chore(actions): check to install jq if it is not already (#4000)
- Change single quotes to double quotes for consistency - Add a check to install `jq` if it is not already installed Signed-off-by: Bo-Yi Wu <[email protected]> Co-authored-by: Kashif Khan <[email protected]> Co-authored-by: Nabeel Alam <[email protected]>
1 parent 45655e9 commit f3b7c13

File tree

1 file changed

+73
-66
lines changed

1 file changed

+73
-66
lines changed

action.yml

Lines changed: 73 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ inputs:
1010
base:
1111
description: Start scanning from here (usually main branch).
1212
required: false
13-
default: ''
13+
default: ""
1414
head:
1515
description: Scan commits until here (usually dev branch).
1616
required: false
1717
extra_args:
18-
default: ''
18+
default: ""
1919
description: Extra args to be passed to the trufflehog cli.
2020
required: false
2121
version:
22-
default: 'latest'
22+
default: "latest"
2323
description: Scan with this trufflehog cli version.
2424
required: false
2525
branding:
@@ -29,71 +29,78 @@ branding:
2929
runs:
3030
using: "composite"
3131
steps:
32-
- shell: bash
33-
working-directory: ${{ inputs.path }}
34-
env:
35-
BASE: ${{ inputs.base }}
36-
HEAD: ${{ inputs.head }}
37-
ARGS: ${{ inputs.extra_args }}
38-
COMMIT_IDS: ${{ toJson(github.event.commits.*.id) }}
39-
VERSION: ${{ inputs.version }}
40-
run: |
41-
##########################################
42-
## ADVANCED USAGE ##
43-
## Scan by BASE & HEAD user inputs ##
44-
## If BASE == HEAD, exit with error ##
45-
##########################################
46-
git status >/dev/null # make sure we are in a git repository
47-
if [ -n "$BASE" ] || [ -n "$HEAD" ]; then
48-
if [ -n "$BASE" ]; then
49-
base_commit=$(git rev-parse "$BASE" 2>/dev/null) || true
50-
else
51-
base_commit=""
52-
fi
53-
if [ -n "$HEAD" ]; then
54-
head_commit=$(git rev-parse "$HEAD" 2>/dev/null) || true
55-
else
56-
head_commit=""
32+
- shell: bash
33+
working-directory: ${{ inputs.path }}
34+
env:
35+
BASE: ${{ inputs.base }}
36+
HEAD: ${{ inputs.head }}
37+
ARGS: ${{ inputs.extra_args }}
38+
COMMIT_IDS: ${{ toJson(github.event.commits.*.id) }}
39+
VERSION: ${{ inputs.version }}
40+
run: |
41+
##########################################
42+
## ADVANCED USAGE ##
43+
## Scan by BASE & HEAD user inputs ##
44+
## If BASE == HEAD, exit with error ##
45+
##########################################
46+
# Check if jq is installed, if not, install it
47+
if ! command -v jq &> /dev/null
48+
then
49+
echo "jq could not be found, installing..."
50+
apt-get -y update && apt-get install -y jq
5751
fi
58-
if [ "$base_commit" == "$head_commit" ] ; then
59-
echo "::error::BASE and HEAD commits are the same. TruffleHog won't scan anything. Please see documentation (https://github.com/trufflesecurity/trufflehog#octocat-trufflehog-github-action)."
60-
exit 1
61-
fi
62-
##########################################
63-
## Scan commits based on event type ##
64-
##########################################
65-
else
66-
if [ "${{ github.event_name }}" == "push" ]; then
67-
COMMIT_LENGTH=$(printenv COMMIT_IDS | jq length)
68-
if [ $COMMIT_LENGTH == "0" ]; then
69-
echo "No commits to scan"
70-
exit 0
52+
53+
git status >/dev/null # make sure we are in a git repository
54+
if [ -n "$BASE" ] || [ -n "$HEAD" ]; then
55+
if [ -n "$BASE" ]; then
56+
base_commit=$(git rev-parse "$BASE" 2>/dev/null) || true
57+
else
58+
base_commit=""
7159
fi
72-
HEAD=${{ github.event.after }}
73-
if [ ${{ github.event.before }} == "0000000000000000000000000000000000000000" ]; then
74-
BASE=""
60+
if [ -n "$HEAD" ]; then
61+
head_commit=$(git rev-parse "$HEAD" 2>/dev/null) || true
7562
else
76-
BASE=${{ github.event.before }}
63+
head_commit=""
64+
fi
65+
if [ "$base_commit" == "$head_commit" ] ; then
66+
echo "::error::BASE and HEAD commits are the same. TruffleHog won't scan anything. Please see documentation (https://github.com/trufflesecurity/trufflehog#octocat-trufflehog-github-action)."
67+
exit 1
68+
fi
69+
##########################################
70+
## Scan commits based on event type ##
71+
##########################################
72+
else
73+
if [ "${{ github.event_name }}" == "push" ]; then
74+
COMMIT_LENGTH=$(printenv COMMIT_IDS | jq length)
75+
if [ $COMMIT_LENGTH == "0" ]; then
76+
echo "No commits to scan"
77+
exit 0
78+
fi
79+
HEAD=${{ github.event.after }}
80+
if [ ${{ github.event.before }} == "0000000000000000000000000000000000000000" ]; then
81+
BASE=""
82+
else
83+
BASE=${{ github.event.before }}
84+
fi
85+
elif [ "${{ github.event_name }}" == "workflow_dispatch" ] || [ "${{ github.event_name }}" == "schedule" ]; then
86+
BASE=""
87+
HEAD=""
88+
elif [ "${{ github.event_name }}" == "pull_request" ]; then
89+
BASE=${{github.event.pull_request.base.sha}}
90+
HEAD=${{github.event.pull_request.head.sha}}
7791
fi
78-
elif [ "${{ github.event_name }}" == "workflow_dispatch" ] || [ "${{ github.event_name }}" == "schedule" ]; then
79-
BASE=""
80-
HEAD=""
81-
elif [ "${{ github.event_name }}" == "pull_request" ]; then
82-
BASE=${{github.event.pull_request.base.sha}}
83-
HEAD=${{github.event.pull_request.head.sha}}
8492
fi
85-
fi
86-
##########################################
87-
## Run TruffleHog ##
88-
##########################################
89-
docker run --rm -v .:/tmp -w /tmp \
90-
ghcr.io/trufflesecurity/trufflehog:${VERSION} \
91-
git file:///tmp/ \
92-
--since-commit \
93-
${BASE:-''} \
94-
--branch \
95-
${HEAD:-''} \
96-
--fail \
97-
--no-update \
98-
--github-actions \
99-
${ARGS:-''}
93+
##########################################
94+
## Run TruffleHog ##
95+
##########################################
96+
docker run --rm -v .:/tmp -w /tmp \
97+
ghcr.io/trufflesecurity/trufflehog:${VERSION} \
98+
git file:///tmp/ \
99+
--since-commit \
100+
${BASE:-''} \
101+
--branch \
102+
${HEAD:-''} \
103+
--fail \
104+
--no-update \
105+
--github-actions \
106+
${ARGS:-''}

0 commit comments

Comments
 (0)