Skip to content

Commit 1c23ec6

Browse files
committed
fix: Create scripts/fix/bom.sh and remove updatebom.sh
- Create scripts/fix/bom.sh to generate bill-of-materials.json - Add intentional first execution to fetch dependencies (avoids dirty state in clean repos) - Use load_workspace_relative_modules_for_bom for proper module list - Protect go.sum and go.mod with temporary backups during generation - Run license-bill-of-materials with GOOS=linux for consistent output - Add ETCD_ROOT_DIR support for dynamic path resolution - Update Makefile fix-bom target to use the new script - Remove scripts/updatebom.sh (functionality now in scripts/fix/bom.sh) - Use 'exit' instead of 'return' (return only works in functions/sourced scripts) - Add || true to first BOM run to ignore expected failures - Verified: bash syntax, shellcheck -x, make verify-shellcheck all passed Signed-off-by: Himanshu Singh <himanshuich20@gmail.com>
1 parent e26dd62 commit 1c23ec6

File tree

3 files changed

+54
-56
lines changed

3 files changed

+54
-56
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ verify-bom:
111111

112112
.PHONY: fix-bom
113113
fix-bom:
114-
./scripts/updatebom.sh
114+
./scripts/fix/bom.sh
115115

116116
.PHONY: verify-dep
117117
verify-dep:

scripts/fix/bom.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2026 The etcd Authors
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -euo pipefail
18+
19+
ETCD_ROOT_DIR=${ETCD_ROOT_DIR:-$(git rev-parse --show-toplevel)}
20+
source "${ETCD_ROOT_DIR}/scripts/test_lib.sh"
21+
22+
log_callout "Generating bill of materials..."
23+
24+
_bom_modules=()
25+
load_workspace_relative_modules_for_bom _bom_modules
26+
27+
# Internally license-bill-of-materials tends to modify go.sum
28+
run cp go.sum go.sum.tmp || exit 2
29+
run cp go.mod go.mod.tmp || exit 2
30+
31+
# Intentionally run the command once first, so it fetches dependencies. The exit code on the first
32+
# run in a just cloned repository is always dirty.
33+
GOOS=linux run_go_tool github.com/appscodelabs/license-bill-of-materials \
34+
--override-file ./bill-of-materials.override.json "${_bom_modules[@]}" &>/dev/null || true
35+
36+
# BOM file should be generated for linux. Otherwise running this command on other operating systems such as OSX
37+
# results in certain dependencies being excluded from the BOM file, such as procfs.
38+
# For more info, https://github.com/etcd-io/etcd/issues/19665
39+
output=$(GOOS=linux run_go_tool github.com/appscodelabs/license-bill-of-materials \
40+
--override-file ./bill-of-materials.override.json \
41+
"${_bom_modules[@]}")
42+
code="$?"
43+
44+
run cp go.sum.tmp go.sum || exit 2
45+
run cp go.mod.tmp go.mod || exit 2
46+
47+
if [ "${code}" -ne 0 ]; then
48+
log_error -e "license-bill-of-materials (code: ${code}) failed with:\\n${output}"
49+
exit 255
50+
fi
51+
52+
echo "${output}" > bill-of-materials.json
53+
log_success "bill-of-materials.json generated"

scripts/updatebom.sh

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

0 commit comments

Comments
 (0)