|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Run whitesource for components which need versioning |
| 4 | +set -e |
| 5 | +set -o pipefail |
| 6 | + |
| 7 | +THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 8 | + |
| 9 | +[[ -z "$WHITESOURCE_API_KEY" ]] && echo "[WARNING] No WHITESOURCE_API_KEY is set. No WhiteSource scan will occur." && exit 0 |
| 10 | + |
| 11 | +if [[ -z "$VIRTUAL_ENV" ]]; then |
| 12 | + PY= |
| 13 | + TMP_VENV=$(mktemp -d) |
| 14 | + if which python3 >& /dev/null; then |
| 15 | + PY=python3 |
| 16 | + elif which python3.7 >& /dev/null; then |
| 17 | + PY=python3.7 |
| 18 | + elif which python3.6 >& /dev/null; then |
| 19 | + PY=python3.6 |
| 20 | + elif which python3.5 >& /dev/null; then |
| 21 | + PY=python3.5 |
| 22 | + elif which python >& /dev/null; then |
| 23 | + if [[ "$(python -c 'import sys; print(sys.version_info.major)')" == "3" ]]; then |
| 24 | + PY=python |
| 25 | + fi |
| 26 | + fi |
| 27 | + [[ -z "$PY" ]] && echo "[ERROR] Failed to find Python3" && exit 1 |
| 28 | + |
| 29 | + echo "[INFO] Installing Python Virtualenv" |
| 30 | + $PY -m venv $TMP_VENV >& /dev/null |
| 31 | + source $TMP_VENV/bin/activate |
| 32 | + IS_IN_CUSTOM_VENV=true |
| 33 | +else |
| 34 | + echo "[INFO] Using Python Virtualenv $VIRTUAL_ENV" |
| 35 | +fi |
| 36 | +pip install -U pip virtualenv >& /dev/null |
| 37 | + |
| 38 | +export PRODUCT_NAME=SQLAlchemy |
| 39 | +export PROJECT_NAME=SQLAlchemy |
| 40 | + |
| 41 | +DATE=$(date +'%m-%d-%Y') |
| 42 | + |
| 43 | +SCAN_DIRECTORIES=$(cd $THIS_DIR/.. && pwd) |
| 44 | + |
| 45 | +rm -f wss-unified-agent.jar |
| 46 | +curl -LO https://github.com/whitesource/unified-agent-distribution/releases/latest/download/wss-unified-agent.jar |
| 47 | + |
| 48 | +# whitesource will scan the folder and detect the corresponding configuration |
| 49 | +# configuration file wss-generated-file.config will be generated under ${SCAN_DIRECTORIES} |
| 50 | +# java -jar wss-unified-agent.jar -detect -d ${SCAN_DIRECTORIES} |
| 51 | +# SCAN_CONFIG="${SCAN_DIRECTORIES}/wss-generated-file.config" |
| 52 | + |
| 53 | +# SCAN_CONFIG is the path to your whitesource configuration file |
| 54 | +SCAN_CONFIG=wss-agent.config |
| 55 | +cat > $SCAN_CONFIG <<CONFIG |
| 56 | +############################################################### |
| 57 | +# WhiteSource Unified-Agent configuration file |
| 58 | +############################################################### |
| 59 | +# PYTHON SCAN MODE: setup.py |
| 60 | +############################################################### |
| 61 | +
|
| 62 | +apiKey= |
| 63 | +#userKey is required if WhiteSource administrator has enabled "Enforce user level access" option |
| 64 | +#userKey= |
| 65 | + |
| 66 | +
|
| 67 | +projectName= |
| 68 | +projectVersion= |
| 69 | +projectToken= |
| 70 | +#projectTag= key:value |
| 71 | +
|
| 72 | +productName= |
| 73 | +productVersion= |
| 74 | +productToken= |
| 75 | +
|
| 76 | +#projectPerFolder=true |
| 77 | +#projectPerFolderIncludes= |
| 78 | +#projectPerFolderExcludes= |
| 79 | +
|
| 80 | +#wss.connectionTimeoutMinutes=60 |
| 81 | +wss.url=https://saas.whitesourcesoftware.com/agent |
| 82 | +
|
| 83 | +############ |
| 84 | +# Policies # |
| 85 | +############ |
| 86 | +checkPolicies=true |
| 87 | +forceCheckAllDependencies=false |
| 88 | +forceUpdate=false |
| 89 | +forceUpdate.failBuildOnPolicyViolation=false |
| 90 | +#updateInventory=false |
| 91 | +
|
| 92 | +########### |
| 93 | +# General # |
| 94 | +########### |
| 95 | +#offline=false |
| 96 | +#updateType=APPEND |
| 97 | +#ignoreSourceFiles=true |
| 98 | +#scanComment= |
| 99 | +#failErrorLevel=ALL |
| 100 | +#requireKnownSha1=false |
| 101 | +
|
| 102 | +#generateProjectDetailsJson=true |
| 103 | +#generateScanReport=true |
| 104 | +#scanReportTimeoutMinutes=10 |
| 105 | +#scanReportFilenameFormat= |
| 106 | +
|
| 107 | +#analyzeFrameworks=true |
| 108 | +#analyzeFrameworksReference= |
| 109 | +
|
| 110 | +#updateEmptyProject=false |
| 111 | +
|
| 112 | +#log.files.level= |
| 113 | +#log.files.maxFileSize= |
| 114 | +#log.files.maxFilesCount= |
| 115 | +#log.files.path= |
| 116 | +
|
| 117 | +######################################## |
| 118 | +# Package Manager Dependency resolvers # |
| 119 | +######################################## |
| 120 | +resolveAllDependencies=false |
| 121 | +
|
| 122 | +python.resolveDependencies=true |
| 123 | +python.ignoreSourceFiles=false |
| 124 | +python.ignorePipInstallErrors=true |
| 125 | +python.installVirtualenv=false # set this parameter to true if using virtualenv to build the project |
| 126 | +python.resolveHierarchyTree=false |
| 127 | +python.resolveSetupPyFiles=true |
| 128 | +python.runPipenvPreStep=false |
| 129 | +#python.IgnorePipenvInstallErrors=true |
| 130 | +python.resolveGlobalPackages=false |
| 131 | +
|
| 132 | +########################################################################################### |
| 133 | +# Includes/Excludes Glob patterns - Please use only one exclude line and one include line # |
| 134 | +########################################################################################### |
| 135 | +includes=**/*.egg **/*.whl **/*.py |
| 136 | +
|
| 137 | +#Exclude file extensions or specific directories by adding **/*.<extension> or **/<excluded_dir>/** |
| 138 | +excludes=**/*sources.jar **/*javadoc.jar |
| 139 | +
|
| 140 | +case.sensitive.glob=false |
| 141 | +followSymbolicLinks=true |
| 142 | +CONFIG |
| 143 | + |
| 144 | +echo "[INFO] Running wss.sh for ${PROJECT_NAME}-${PRODUCT_NAME} under ${SCAN_DIRECTORIES}" |
| 145 | +java -jar wss-unified-agent.jar -apiKey ${WHITESOURCE_API_KEY} \ |
| 146 | + -c ${SCAN_CONFIG} \ |
| 147 | + -project ${PROJECT_NAME} \ |
| 148 | + -product ${PRODUCT_NAME} \ |
| 149 | + -d ${SCAN_DIRECTORIES} \ |
| 150 | + -wss.url https://saas.whitesourcesoftware.com/agent \ |
| 151 | + -offline true |
| 152 | + |
| 153 | +if java -jar wss-unified-agent.jar -apiKey ${WHITESOURCE_API_KEY} \ |
| 154 | + -c ${SCAN_CONFIG} \ |
| 155 | + -project ${PROJECT_NAME} \ |
| 156 | + -product ${PRODUCT_NAME} \ |
| 157 | + -projectVersion baseline \ |
| 158 | + -requestFiles whitesource/update-request.txt \ |
| 159 | + -wss.url https://saas.whitesourcesoftware.com/agent ; then |
| 160 | + echo "checkPolicies=false" >> ${SCAN_CONFIG} |
| 161 | + java -jar wss-unified-agent.jar -apiKey ${WHITESOURCE_API_KEY} \ |
| 162 | + -c ${SCAN_CONFIG} \ |
| 163 | + -project ${PROJECT_NAME} \ |
| 164 | + -product ${PRODUCT_NAME} \ |
| 165 | + -projectVersion ${DATE} \ |
| 166 | + -requestFiles whitesource/update-request.txt \ |
| 167 | + -wss.url https://saas.whitesourcesoftware.com/agent |
| 168 | +fi |
| 169 | +[[ -n "$IS_IN_CUSTOM_VENV" ]] && deactivate || true |
0 commit comments