File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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@v3
36+ with :
37+ terraform_version : ${{ env.TF_VERSION }}
38+
39+ - uses : terraform-linters/setup-tflint@v5
40+ name : Setup TFLint
41+ with :
42+ tflint_version : v0.58.0
43+
44+ - name : Set architecture variable
45+ id : os-arch
46+ run : |
47+ case "${{ runner.arch }}" in
48+ X64) ARCH="amd64" ;;
49+ ARM64) ARCH="arm64" ;;
50+ esac
51+ echo "arch=${ARCH}" >> $GITHUB_OUTPUT
52+
53+ - name : Download and setup Syft
54+ run : |
55+ 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"
56+ echo "Downloading: ${DOWNLOAD_URL}"
57+
58+ curl -L -o syft.tar.gz "${DOWNLOAD_URL}"
59+ tar -xzf syft.tar.gz
60+ chmod +x syft
61+
62+ # Add to PATH for subsequent steps
63+ echo "$(pwd)" >> $GITHUB_PATH
64+
65+ - name : Create SBOM
66+ run : bash scripts/create-sbom.sh terraform python tflint
67+
68+ - name : Upload SBOM as artifact
69+ uses : actions/upload-artifact@v4
70+ with :
71+ name : sbom
72+ 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