mirror of
https://github.com/google/nomulus.git
synced 2025-06-24 21:40:57 +02:00
130 lines
3.5 KiB
Bash
130 lines
3.5 KiB
Bash
#!/bin/bash
|
|
# Copyright 2019 The Nomulus Authors. All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
#
|
|
# This script runs the following workflow:
|
|
#
|
|
# 1. Generate the dependency lock file.
|
|
# 2. Run a build against the generated lock file and save the lock file if the
|
|
# build succeeds.
|
|
# 3. Upload dependency JARs to a private Maven repository.
|
|
# 4. Generate the metadata file for each third party dependency and
|
|
# publish the file to a Git-on-Borg repo where the Vomit system can scan.
|
|
|
|
set -e
|
|
|
|
ALL_SUBPROJECTS="core proxy util"
|
|
SUBPROJECTS=
|
|
GCS_REPO_URL=
|
|
GOB_REPO_URL=
|
|
NOMULUS_LOCAL_DIR=$(pwd)
|
|
COMMAND=all
|
|
|
|
function usage() {
|
|
echo "Usage: $0 [SUBPROJECT] [--command COMMAND] [--nomulus_local_dir DIR] \\
|
|
--gcs_repo_url URL --gob_repo_url URL"
|
|
exit 1
|
|
}
|
|
|
|
function update_dependency_and_upload_to_gcs() {
|
|
local project
|
|
|
|
for project in ${ALL_SUBPROJECTS}; do
|
|
${GRADLEW} ":${project}:generateLock"
|
|
${GRADLEW} -PdependencyLock.useGeneratedLock=true ":${project}:build"
|
|
${GRADLEW} ":${project}:saveLock"
|
|
${GRADLEW} -PrepositoryUrl="${GCS_REPO_URL}" ":${project}:publish"
|
|
done
|
|
}
|
|
|
|
function generate_dependency_metadata() {
|
|
local project
|
|
local gob_repo_dir="$(mktemp -d)"
|
|
|
|
git clone ${GOB_REPO_URL} ${gob_repo_dir}
|
|
for project in ${ALL_SUBPROJECTS}; do
|
|
${GRADLEW} -PprivateRepository="${gob_repo_dir}" \
|
|
":${project}:generateDependencyMetadata"
|
|
done
|
|
cd "${gob_repo_dir}"
|
|
git add -A
|
|
git diff-index --quiet HEAD \
|
|
|| git commit -m "Update dependency metadata file" && git push
|
|
rm -rf "${gob_repo_dir}"
|
|
}
|
|
|
|
# TODO: Use gbash.sh to parse command-line parameter
|
|
while [[ $# -gt 0 ]]; do
|
|
KEY="$1"
|
|
case ${KEY} in
|
|
--command)
|
|
shift
|
|
COMMAND="$1"
|
|
;;
|
|
--gcs_repo_url)
|
|
shift
|
|
GCS_REPO_URL="$1"
|
|
;;
|
|
--gob_repo_url)
|
|
shift
|
|
GOB_REPO_URL="$1"
|
|
;;
|
|
--nomulus_local_dir)
|
|
shift
|
|
NOMULUS_LOCAL_DIR="$1"
|
|
;;
|
|
*)
|
|
SUBPROJECTS="${SUBPROJECTS} ${KEY}"
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
if [[ -z ${SUBPROJECTS} ]]; then
|
|
SUBPROJECTS="${ALL_SUBPROJECTS}"
|
|
fi
|
|
|
|
GRADLEW="${NOMULUS_LOCAL_DIR}/gradle/gradlew"
|
|
if [[ ! -f ${GRADLEW} || ! -x ${GRADLEW} ]]; then
|
|
echo "${GRADLEW} doesn't exist or is not executable"
|
|
usage
|
|
fi
|
|
GRADLEW="${GRADLEW} --project-dir ${NOMULUS_LOCAL_DIR}/gradle"
|
|
|
|
if [[ "all" != "${COMMAND}" && \
|
|
"update_dependency" != "${COMMAND}" && \
|
|
"generate_report" != "${COMMAND}" ]]; then
|
|
echo "--command must be one of [all, update_dependency, generate_report]"
|
|
usage
|
|
fi
|
|
|
|
if [[ ("all" == "${COMMAND}" || "update_dependency" == "${COMMAND}") && \
|
|
-z ${GCS_REPO_URL} ]]; then
|
|
echo "--gcs_repo_url must be specified"
|
|
usage
|
|
fi
|
|
|
|
if [[ ("all" == "${COMMAND}" || "generate_report" == "${COMMAND}") && \
|
|
-z ${GOB_REPO_URL} ]]; then
|
|
echo "--gob_repo_url must be specified"
|
|
usage
|
|
fi
|
|
|
|
if [[ "all" == "${COMMAND}" || "update_dependency" == "${COMMAND}" ]]; then
|
|
update_dependency_and_upload_to_gcs
|
|
fi
|
|
|
|
if [[ "all" == "${COMMAND}" || "generate_report" == "${COMMAND}" ]]; then
|
|
generate_dependency_metadata
|
|
fi
|