Skip to content

Commit cd82f03

Browse files
author
Francois Leroux
committed
feat: add support for checkov
1 parent f2578d9 commit cd82f03

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

action.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ inputs:
5656
upload-plan-destination:
5757
description: Destination to upload the plan to. gcp and github are currently supported
5858
required: false
59+
setup-checkov:
60+
description: Setup Checkov
61+
required: false
62+
default: 'false'
63+
checkov-version:
64+
description: Checkov version
65+
required: false
66+
default: '2.3.245'
5967

6068
outputs:
6169
output:
@@ -126,11 +134,22 @@ runs:
126134
terragrunt_version: ${{ inputs.terragrunt-version }}
127135
if: inputs.setup-terragrunt == 'true'
128136

137+
- name: Setup Checkov
138+
run: |
139+
python3 -m venv python_venv
140+
source python_venv/bin/activate
141+
pip3 install --upgrade pip
142+
pip3 install --upgrade setuptools
143+
pip3 install -U checkov==${{ inputs.checkov-version }}
144+
shell: bash
145+
if: inputs.setup-checkov == 'true'
146+
129147
- name: build and run digger
130148
if: ${{ !startsWith(github.action_ref, 'v') }}
131149
shell: bash
132150
env:
133151
PLAN_UPLOAD_DESTINATION: ${{ inputs.upload-plan-destination }}
152+
SETUP_CHECKOV: ${{ inputs.checkov-version }}
134153
run: |
135154
cd ${{ github.action_path }}
136155
go build -o digger ./cmd/digger

pkg/digger/digger.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func RunCommandsPerProject(commandsPerProject []ProjectCommand, repoOwner string
8585
diggerExecutor := DiggerExecutor{
8686
repoOwner,
8787
repoName,
88+
workingDir,
8889
projectCommands.ProjectName,
8990
projectPath,
9091
projectCommands.StateEnvVars,
@@ -344,6 +345,7 @@ func parseProjectName(comment string) string {
344345
type DiggerExecutor struct {
345346
RepoOwner string
346347
RepoName string
348+
RepoPath string
347349
ProjectName string
348350
ProjectPath string
349351
StateEnvVars map[string]string
@@ -418,6 +420,12 @@ func (d DiggerExecutor) Plan(prNumber int) error {
418420
},
419421
}
420422
}
423+
if os.Getenv("SETUP_CHECKOV") == "true" && len(planSteps) > 0 {
424+
_, _, err := d.CommandRunner.Run(d.RepoPath, planSteps[0].Shell, "source python_venv/bin/activate")
425+
if err != nil {
426+
return fmt.Errorf("error sourcing python venv for checkov: %v", err)
427+
}
428+
}
421429
for _, step := range planSteps {
422430
if step.Action == "init" {
423431
_, _, err := d.TerraformExecutor.Init(step.ExtraArgs, d.StateEnvVars)
@@ -489,6 +497,12 @@ func (d DiggerExecutor) Apply(prNumber int) error {
489497
}
490498
}
491499

500+
if os.Getenv("SETUP_CHECKOV") == "true" && len(applySteps) > 0 {
501+
_, _, err := d.CommandRunner.Run(d.RepoPath, applySteps[0].Shell, "source python_venv/bin/activate")
502+
if err != nil {
503+
return fmt.Errorf("error sourcing python venv for checkov: %v", err)
504+
}
505+
}
492506
for _, step := range applySteps {
493507
if step.Action == "init" {
494508
_, _, err := d.TerraformExecutor.Init(step.ExtraArgs, d.StateEnvVars)

pkg/gitlab/gitlab.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ func RunCommandsPerProject(commandsPerProject []digger.ProjectCommand, gitLabCon
349349
diggerExecutor := digger.DiggerExecutor{
350350
gitLabContext.ProjectNamespace,
351351
gitLabContext.ProjectName,
352+
workingDir,
352353
projectCommands.ProjectName,
353354
projectPath,
354355
projectCommands.StateEnvVars,

0 commit comments

Comments
 (0)