Skip to content

Commit 5796bf3

Browse files
add workflow
1 parent 74701f7 commit 5796bf3

File tree

1 file changed

+33
-23
lines changed

1 file changed

+33
-23
lines changed

.github/workflows/pr-security.yml

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,63 @@ name: PR Security & Cost
22
on:
33
pull_request: { branches: [main] }
44
push:
5-
branches: ["feature/**", "bugfix/**", "chore/**"]
5+
branches: ["feature/**", "bugfix/**", "chore/**"] # optional
66

77
concurrency:
88
group: ${{ github.workflow }}-${{ github.ref }}
99
cancel-in-progress: true
1010

11+
# These permissions let Infracost post a PR comment.
12+
permissions:
13+
contents: read
14+
pull-requests: write
15+
1116
jobs:
12-
semgrep-checkov-infracost:
17+
semgrep:
18+
name: Semgrep (SAST)
1319
runs-on: ubuntu-latest
14-
permissions:
15-
contents: read
16-
pull-requests: write
1720
steps:
1821
- uses: actions/checkout@v4
19-
20-
# ----- Semgrep (SAST for Go, etc.) -----
2122
- name: Install Semgrep
2223
run: pipx install semgrep || pip install --user semgrep
23-
- name: Semgrep scan (auto rules)
24-
run: semgrep ci --config auto
24+
- name: Run Semgrep
25+
# If you added SEMGREP_APP_TOKEN, Semgrep will upload to semgrep.dev
2526
env:
2627
SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }} # optional
28+
run: semgrep ci --config auto
2729

28-
# ----- Checkov (IaC: only if infra/terraform/ exists) -----
29-
- name: Checkov on Terraform
30-
if: ${{ hashFiles('infra/terraform/**') != '' }}
31-
run: |
32-
pipx install checkov || pip install --user checkov
33-
checkov -d infra/terraform --quiet
30+
checkov:
31+
name: Checkov (IaC)
32+
if: ${{ hashFiles('infra/terraform/**') != '' }}
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v4
36+
- name: Install Checkov
37+
run: pipx install checkov || pip install --user checkov
38+
- name: Scan Terraform
39+
run: checkov -d infra/terraform --quiet
3440

35-
# ----- Infracost (optional; TF only) -----
41+
infracost:
42+
name: Infracost (Cost)
43+
if: ${{ hashFiles('infra/terraform/**') != '' && secrets.INFRACOST_API_KEY != '' }}
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@v4
3647
- name: Install Infracost
37-
if: ${{ hashFiles('infra/terraform/**') != '' && secrets.INFRACOST_API_KEY != '' }}
3848
run: curl -fsSL https://raw.githubusercontent.com/infracost/infracost/master/scripts/install.sh | sh
39-
- name: Infracost breakdown (artifact + PR comment)
40-
if: ${{ hashFiles('infra/terraform/**') != '' && secrets.INFRACOST_API_KEY != '' }}
49+
- name: Infracost breakdown
50+
env:
51+
INFRACOST_API_KEY: ico-L77peDwqm1ChsL1MazL719JaPlGXC34G
52+
run: infracost breakdown --path infra/terraform --format json --out-file infracost.json
53+
- name: Comment PR with cost diff
4154
env:
42-
INFRACOST_API_KEY: ${{ secrets.INFRACOST_API_KEY }}
55+
INFRACOST_API_KEY: ico-L77peDwqm1ChsL1MazL719JaPlGXC34G
4356
run: |
44-
infracost breakdown --path infra/terraform --format json --out-file infracost.json
45-
echo "Posting PR comment..."
4657
infracost comment github --path infracost.json \
4758
--repo ${{ github.repository }} \
4859
--pull-request ${{ github.event.pull_request.number }} \
4960
--behavior update
5061
- name: Upload Infracost artifact
51-
if: ${{ hashFiles('infra/terraform/**') != '' && secrets.INFRACOST_API_KEY != '' }}
5262
uses: actions/upload-artifact@v4
5363
with:
5464
name: infracost

0 commit comments

Comments
 (0)