Skip to content

Commit 1298743

Browse files
CCM-13343: Trivy Package and Library Scans
1 parent 3a6c7e5 commit 1298743

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
- [ ] I have added tests to cover my changes
2626
- [ ] I have updated the documentation accordingly
2727
- [ ] This PR is a result of pair or mob programming
28-
28+
- [ ] If I have used the 'skip-trivy-package' label I have done so responsibly and in the knowledge that this is being fixed as part of a separate ticket/PR.
2929
---
3030

3131
## Sensitive Information Declaration

.github/workflows/cicd-1-pull-request.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
is_version_prerelease: ${{ steps.variables.outputs.is_version_prerelease }}
2929
does_pull_request_exist: ${{ steps.pr_exists.outputs.does_pull_request_exist }}
3030
pr_number: ${{ steps.pr_exists.outputs.pr_number }}
31+
skip_trivy_package: ${{ steps.skip_trivy.outputs.skip_trivy_package }}
3132
steps:
3233
- name: "Checkout code"
3334
uses: actions/checkout@v5
@@ -66,6 +67,26 @@ jobs:
6667
echo "does_pull_request_exist=false" >> $GITHUB_OUTPUT
6768
echo "pr_number=" >> $GITHUB_OUTPUT
6869
fi
70+
- name: "Determine if Trivy package scan should be skipped"
71+
id: skip_trivy
72+
env:
73+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74+
PR_NUMBER: ${{ steps.pr_exists.outputs.pr_number }}
75+
run: |
76+
if [[ -z "$PR_NUMBER" ]]; then
77+
echo "No pull request detected; Trivy package scan will run."
78+
echo "skip_trivy_package=false" >> $GITHUB_OUTPUT
79+
exit 0
80+
fi
81+
82+
labels=$(gh pr view "$PR_NUMBER" --json labels --jq '.labels[].name')
83+
echo "Labels on PR #$PR_NUMBER: $labels"
84+
85+
if echo "$labels" | grep -Fxq 'skip-trivy-package'; then
86+
echo "skip_trivy_package=true" >> $GITHUB_OUTPUT
87+
else
88+
echo "skip_trivy_package=false" >> $GITHUB_OUTPUT
89+
fi
6990
- name: "List variables"
7091
run: |
7192
export BUILD_DATETIME_LONDON="${{ steps.variables.outputs.build_datetime_london }}"
@@ -89,6 +110,7 @@ jobs:
89110
build_epoch: "${{ needs.metadata.outputs.build_epoch }}"
90111
nodejs_version: "${{ needs.metadata.outputs.nodejs_version }}"
91112
python_version: "${{ needs.metadata.outputs.python_version }}"
113+
skip_trivy_package: ${{ needs.metadata.outputs.skip_trivy_package == 'true' }}
92114
terraform_version: "${{ needs.metadata.outputs.terraform_version }}"
93115
version: "${{ needs.metadata.outputs.version }}"
94116
secrets: inherit

.github/workflows/stage-1-commit.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ on:
2323
description: "Python version, set by the CI/CD pipeline workflow"
2424
required: true
2525
type: string
26+
skip_trivy_package:
27+
description: "Skip Trivy package scan when true"
28+
type: boolean
29+
default: false
2630
terraform_version:
2731
description: "Terraform version, set by the CI/CD pipeline workflow"
2832
required: true
@@ -172,6 +176,7 @@ jobs:
172176
- name: "Trivy IaC Scan"
173177
uses: ./.github/actions/trivy-iac
174178
trivy-package:
179+
if: ${{ !inputs.skip_trivy_package }}
175180
name: "Trivy Package Scan"
176181
permissions:
177182
contents: read

0 commit comments

Comments
 (0)