Combine dependency update scripts

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=230958523
This commit is contained in:
shicong 2019-01-25 13:28:46 -08:00 committed by Ben McIlwain
parent 5b0c61dad3
commit 9cd37189c2
3 changed files with 130 additions and 96 deletions

View file

@ -1,38 +0,0 @@
#!/bin/bash
# Copyright 2018 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 a workflow to clone a git repository to local, generate
# a metadata file for each dependency artifact and check in the file to remote
# repository.
set -e
ALL_SUBPROJECTS="core proxy util"
USAGE="Usage: ${0} REPO_URL"
REPO_URL=${1:?${USAGE}}
REPO_DIR="$(mktemp -d)"
git clone ${REPO_URL} ${REPO_DIR}
for PROJECT in ${ALL_SUBPROJECTS}; do
$(dirname $0)/gradlew -PprivateRepository="${REPO_DIR}" \
":${PROJECT}:generateDependencyMetadata"
done
cd "${REPO_DIR}"
git add -A
git diff-index --quiet HEAD \
|| git commit -m "Update dependency metadata file" && git push
rm -rf "${REPO_DIR}"

130
gradle/update_dependency Normal file
View file

@ -0,0 +1,130 @@
#!/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

View file

@ -1,58 +0,0 @@
#!/bin/bash
# Copyright 2018 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 a workflow to generate dependency lock file, run a build against
# the generated lock file, save the lock file and upload dependency JARs to a private
# Maven repository if the build succeeds.
set -e
ALL_SUBPROJECTS="core proxy util"
SUBPROJECTS=
REPOSITORY_URL=
while [[ $# -gt 0 ]]; do
KEY="$1"
case ${KEY} in
--repositoryUrl)
shift
REPOSITORY_URL="$1"
;;
*)
SUBPROJECTS="${SUBPROJECTS} ${KEY}"
;;
esac
shift
done
if [[ -z ${SUBPROJECTS} ]]; then
SUBPROJECTS="${ALL_SUBPROJECTS}"
fi
if [[ -z ${REPOSITORY_URL} ]]; then
echo "--repositoryUrl must be specified"
exit 1
fi
WORKING_DIR=$(dirname $0)
for PROJECT in ${SUBPROJECTS}; do
${WORKING_DIR}/gradlew ":${PROJECT}:generateLock"
${WORKING_DIR}/gradlew -PdependencyLock.useGeneratedLock=true \
":${PROJECT}:build"
${WORKING_DIR}/gradlew ":${PROJECT}:saveLock"
${WORKING_DIR}/gradlew -PrepositoryUrl="${REPOSITORY_URL}" \
":${PROJECT}:publish"
done