|
| 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" |
0 commit comments