File tree Expand file tree Collapse file tree 3 files changed +108
-0
lines changed
Expand file tree Collapse file tree 3 files changed +108
-0
lines changed Original file line number Diff line number Diff line change 1+ name : SBOM Check
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ environment :
7+ description : " Run SBOM check"
8+ required : true
9+ type : choice
10+ options :
11+ - yes
12+ - no
13+
14+ env :
15+ SYFT_VERSION : " 1.27.1"
16+ TF_VERSION : " 1.12.2"
17+
18+ jobs :
19+ deploy :
20+ name : Software Bill of Materials
21+ runs-on : ubuntu-latest
22+ permissions :
23+ actions : read
24+ contents : write
25+ steps :
26+ - name : Checkout
27+ uses : actions/checkout@v5
28+
29+ - name : Setup Python 3.13
30+ uses : actions/setup-python@v5
31+ with :
32+ python-version : " 3.13"
33+
34+ - name : Setup Terraform
35+ uses : hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd
36+
37+ - uses : terraform-linters/setup-tflint@ae78205cfffec9e8d93fd2b3115c7e9d3166d4b6
38+ name : Setup TFLint
39+
40+ - name : Set architecture variable
41+ id : os-arch
42+ run : |
43+ case "${{ runner.arch }}" in
44+ X64) ARCH="amd64" ;;
45+ ARM64) ARCH="arm64" ;;
46+ esac
47+ echo "arch=${ARCH}" >> $GITHUB_OUTPUT
48+
49+ - name : Download and setup Syft
50+ run : |
51+ DOWNLOAD_URL="https://github.com/anchore/syft/releases/download/v${{ env.SYFT_VERSION }}/syft_${{ env.SYFT_VERSION }}_linux_${{ steps.os-arch.outputs.arch }}.tar.gz"
52+ echo "Downloading: ${DOWNLOAD_URL}"
53+
54+ curl -L -o syft.tar.gz "${DOWNLOAD_URL}"
55+ tar -xzf syft.tar.gz
56+ chmod +x syft
57+
58+ # Add to PATH for subsequent steps
59+ echo "$(pwd)" >> $GITHUB_PATH
60+
61+ - name : Create SBOM
62+ run : bash scripts/create-sbom.sh terraform python tflint
63+
64+ - name : Upload SBOM as artifact
65+ uses : actions/upload-artifact@v4
66+ with :
67+ name : sbom
68+ path : sbom.json
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ set -euo pipefail
3+ IFS=$' \n\t '
4+
5+ REPO_ROOT=$( git rev-parse --show-toplevel)
6+
7+ # Generate SBOM for current directory
8+ syft -o spdx-json . > " $REPO_ROOT /sbom.json"
9+
10+ # Generate and merge SBOMs for each tool passed as argument
11+ for tool in " $@ " ; do
12+ echo " Creating SBOM for $tool and merging"
13+ tool_path=$( command -v " $tool " )
14+ if [[ -z " $tool_path " ]]; then
15+ echo " Warning: '$tool ' not found in PATH. Skipping." >&2
16+ continue
17+ fi
18+ syft -q -o spdx-json " $tool_path " | python " $REPO_ROOT /scripts/update-sbom.py"
19+ done
Original file line number Diff line number Diff line change 1+ import json
2+ import sys
3+ from pathlib import Path
4+
5+
6+ def main () -> None :
7+ with Path ("sbom.json" ).open ("r" ) as f :
8+ sbom = json .load (f )
9+
10+ tool = json .loads (sys .stdin .read ())
11+
12+ sbom .setdefault ("packages" , []).extend (tool .setdefault ("packages" , []))
13+ sbom .setdefault ("files" , []).extend (tool .setdefault ("files" , []))
14+ sbom .setdefault ("relationships" , []).extend (tool .setdefault ("relationships" , []))
15+
16+ with Path ("sbom.json" ).open ("w" ) as f :
17+ json .dump (sbom , f )
18+
19+
20+ if __name__ == "__main__" :
21+ main ()
You can’t perform that action at this time.
0 commit comments