Skip to content

Commit 72be23d

Browse files
Combine to single action
1 parent 21f381f commit 72be23d

File tree

3 files changed

+113
-152
lines changed

3 files changed

+113
-152
lines changed

.github/workflows/endor_labs_pr_scan.yml

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: Generate SBOM
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "master"
7+
- "releases/v*"
8+
- "debian/*"
9+
paths:
10+
- "**/CMakeLists.txt"
11+
- "**/*.cmake"
12+
push:
13+
branches:
14+
- "master"
15+
- "releases/v*"
16+
- "debian/*"
17+
paths:
18+
- "**/CMakeLists.txt"
19+
- "**/*.cmake"
20+
21+
jobs:
22+
endor_scan_and_generate_sbom:
23+
permissions:
24+
id-token: write # Required to request a json web token (JWT) for keyless authentication with Endor Labs
25+
contents: write # Required for commit
26+
pull-requests: write # Required for PR
27+
runs-on: ubuntu-latest
28+
env:
29+
PR_SCAN: ${{ github.event_name == 'pull_request' }}
30+
steps:
31+
- name: Checkout Repository
32+
uses: actions/checkout@v6
33+
with:
34+
fetch-tags: true
35+
submodules: recursive
36+
37+
- name: Configure CMake and fetch dependency sources
38+
env:
39+
BUILD_TYPE: Release
40+
BUILD: ${{github.workspace}}/build
41+
CXX_STANDARD: 17
42+
working-directory: ${{env.BUILD}}
43+
run: |
44+
cmake .. -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_STANDARD=${{env.CXX_STANDARD}} -DENABLE_TESTS=ON
45+
git rm .gitignore # prevent exclusion of build/_deps from endorctl scan
46+
47+
- name: Endor Labs Scan (PR or Monitoring)
48+
uses: endorlabs/github-action@519df81de5f68536c84ae05ebb2986d0bb1d19fc # v1.1.8
49+
env:
50+
ENDOR_SCAN_EMBEDDINGS: true
51+
with:
52+
additional_args: '--languages=c --include-path="build/_deps/**"'
53+
enable_pr_comments: ${{ env.PR_SCAN }}
54+
github_token: ${{ secrets.GITHUB_TOKEN }} # Required for endorctl to write pr comments
55+
log_level: info
56+
log_verbose: false
57+
namespace: mongodb.${{github.repository_owner}}
58+
pr: ${{ env.PR_SCAN }}
59+
scan_dependencies: true
60+
scan_summary_output_type: "table"
61+
tags: github_action
62+
63+
# - name: Set up Python
64+
# if: env.PR_SCAN == false
65+
# uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
66+
# with:
67+
# python-version: "3.10"
68+
69+
- name: Install uv
70+
if: env.PR_SCAN == false
71+
uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7.1.4
72+
with:
73+
python-version: "3.10"
74+
activate-environment: true
75+
enable-cache: true
76+
77+
- name: Stash existing SBOM, generate new SBOM
78+
if: env.PR_SCAN == false
79+
run: |
80+
# Existing SBOM: Strip out nondeterministic SBOM fields and save to temp file
81+
jq 'del(.version, .metadata.timestamp, .metadata.tools.services[].version)' sbom.json > ${{runner.temp}}/sbom.existing.cdx.json
82+
# etc/sbom/generate_sbom.py
83+
uv run --group generate_sbom etc/sbom/generate_sbom.py --enable-github-action-token --target=branch --sbom-metadata=etc/sbom/metadata.cdx.json --save-warnings=${{runner.temp}}/warnings.txt
84+
# Generated SBOM: Strip out nondeterministic SBOM fields and save to temp file
85+
jq 'del(.version, .metadata.timestamp, .metadata.tools.services[].version)' sbom.json > ${{runner.temp}}/sbom.generated.cdx.json
86+
87+
- name: Check for SBOM changes
88+
if: env.PR_SCAN == false
89+
id: sbom_diff
90+
run: |
91+
# diff the temp SBOM files, save output to variable, supress exit code
92+
RESULT=$(diff --brief ${{runner.temp}}/sbom.existing.cdx.json ${{runner.temp}}/sbom.generated.cdx.json)
93+
# Set the output variable
94+
echo "result=$RESULT" | tee -a $GITHUB_OUTPUT
95+
96+
- name: Generate pull request content and notice message, if SBOM has changed
97+
if: env.PR_SCAN == false && steps.sbom_diff.outputs.result
98+
run: |
99+
printf "SBOM updated after commit ${{ github.sha }}.\n\n" | cat - ${{runner.temp}}/warnings.txt > ${{runner.temp}}/pr_body.txt
100+
echo "::notice title=SBOM-Diff::SBOM has changed"
101+
102+
- name: Open Pull Request, if SBOM has changed
103+
if: env.PR_SCAN == false && steps.sbom_diff.outputs.result
104+
uses: peter-evans/create-pull-request@84ae59a2cdc2258d6fa0732dd66352dddae2a412 # v7.0.9
105+
env:
106+
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
107+
with:
108+
add-paths: sbom.json
109+
body-path: ${{runner.temp}}/pr_body.txt
110+
branch: cxx-sbom-update-${{ env.BRANCH_NAME }}
111+
commit-message: Update SBOM file(s)
112+
delete-branch: true
113+
title: CXX Update SBOM action - ${{ env.BRANCH_NAME }}

.github/workflows/generate_sbom.yml

Lines changed: 0 additions & 102 deletions
This file was deleted.

0 commit comments

Comments
 (0)