From 9932ff648a249ca67a2dfcb2684ff1629d056127 Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Mon, 22 Jun 2020 12:35:04 +0200 Subject: [PATCH] Update repo sync policies * Don't try and sync non-apache license files. * Force create CODE_OF_CONDUCT.md. * Switch to using an array of files to update. Signed-off-by: Ben Kochie --- scripts/sync_repo_files.sh | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/scripts/sync_repo_files.sh b/scripts/sync_repo_files.sh index 38bb89152..560ad812b 100755 --- a/scripts/sync_repo_files.sh +++ b/scripts/sync_repo_files.sh @@ -53,17 +53,30 @@ post_pull_request() { "https://api.github.com/repos/${1}/pulls" } +check_license() { + # Check to see if the input is an Apache license of some kind + echo "$1" | grep --quiet --no-messages --ignore-case 'Apache License' +} + process_repo() { local org_repo="$1" echo -e "\e[32mAnalyzing '${org_repo}'\e[0m" - local needs_update=0 + local needs_update=() for source_file in ${SYNC_FILES}; do source_checksum="$(sha256sum "${source_dir}/${source_file}" | cut -d' ' -f1)" target_file="$(curl -s --fail "https://raw.githubusercontent.com/${org_repo}/master/${source_file}")" + if [[ "${source_file}" == 'LICENSE' ]] && ! check_license "${target_file}" ; then + echo "LICENSE in ${org_repo} is not apache, skipping." + continue + fi if [[ -z "${target_file}" ]]; then echo "${source_file} doesn't exist in ${org_repo}" + if [[ "${source_file}" == 'CODE_OF_CONDUCT.md' ]] ; then + echo "CODE_OF_CONDUCT.md missing in ${org_repo}, force updating." + needs_update+=('CODE_OF_CONDUCT.md') + fi continue fi target_checksum="$(echo "${target_file}" | sha256sum | cut -d' ' -f1)" @@ -71,10 +84,10 @@ process_repo() { echo "${source_file} is already in sync." continue fi - needs_update=1 + needs_update+=("${source_file}") done - if [[ "${needs_update}" -eq 0 ]] ; then + if [[ "${#needs_update[@]}" -eq 0 ]] ; then echo "No files need sync." return fi @@ -85,7 +98,7 @@ process_repo() { git checkout -b "${branch}" || return 1 # Update the files in target repo by one from prometheus/prometheus. - for source_file in ${SYNC_FILES}; do + for source_file in ${needs_update[@]}; do cp -f "${source_dir}/${source_file}" "./${source_file}" done