2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11 # Scans files for license header violations
13 # This script is meant to be called by a Jenkins job and was not designed to
14 # run standalone refer to the below Inputs for details on optional ENVVAR
17 echo "---> license-check.sh"
21 # Space separated list of file patterns to scan for license headers.
22 file_patterns=("${FILE_PATTERNS:-*.go *.groovy *.java *.py *.sh}")
23 # Version of the License Header Checker to install
24 lhc_version="${LHC_VERSION:-0.2.0}"
25 # Comma-separated list of paths to exclude from license checking
26 license_exclude_paths="${LICENSE_EXCLUDE_PATHS:-}"
27 # Comma-separated list of allowed licenses
28 licenses_allowed="${LICENSES_ALLOWED:-Apache-2.0,EPL-1.0,MIT}"
30 if [[ "${SPDX_DISABLE}" == "true" ]]; then
31 disable_spdx="--disable-spdx"
38 # DO NOT enable -u because LICENSE_EXCLUDE_PATHS is unbound.
39 # Ensure we fail the job if any steps fail.
42 if hash lhc 2>/dev/null; then
43 echo "License Header Checker is installed."
46 echo "License Header Checker is not installed. Installing..."
47 mkdir "$WORKSPACE/bin"
48 wget -nv -O "/tmp/lhc.tar.gz" "https://nexus.opendaylight.org/content/repositories/hosted_installers/org/linuxfoundation/lhc/${lhc_version}/lhc-${lhc_version}.tar.gz"
49 tar -zxvf /tmp/lhc.tar.gz -C "$WORKSPACE/bin"
50 chmod +x "$WORKSPACE/bin/lhc"
51 export PATH="$WORKSPACE/bin:$PATH"
56 set -f # Disable globbing for $file_patterns to pass '*'
57 # Purposely disable SC2068 for $file_patterns
58 # shellcheck disable=SC2068
59 lhc --license "$licenses_allowed" "${disable_spdx}" \
60 --exclude "$license_exclude_paths" \