diff --git a/.circleci/config.yml b/.circleci/config.yml index 53669bf72..6ad8cb842 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -87,11 +87,11 @@ jobs: - setup_remote_docker - run: ./fuzzit.sh fuzzing - makefile_sync: + repo_sync: executor: golang steps: - checkout - - run: ./scripts/sync_makefiles.sh + - run: ./scripts/sync_repo_files.sh workflows: version: 2 @@ -143,7 +143,7 @@ workflows: only: - master jobs: - - makefile_sync: + - repo_sync: context: org-context - fuzzit_fuzzing: context: org-context diff --git a/code-of-conduct.md b/CODE_OF_CONDUCT.md similarity index 100% rename from code-of-conduct.md rename to CODE_OF_CONDUCT.md diff --git a/scripts/sync_makefiles.sh b/scripts/sync_repo_files.sh similarity index 66% rename from scripts/sync_makefiles.sh rename to scripts/sync_repo_files.sh index 8def333b3..f2630b555 100755 --- a/scripts/sync_makefiles.sh +++ b/scripts/sync_repo_files.sh @@ -7,10 +7,10 @@ set -uo pipefail git_mail="prometheus-team@googlegroups.com" git_user="prombot" -branch="makefile_common" -commit_msg="makefile: update Makefile.common with newer version" -pr_title="Synchronize Makefile.common from prometheus/prometheus" -pr_msg="Propagating changes from master Makefile.common located in prometheus/prometheus." +branch="repo_sync" +commit_msg="Update common Prometheus files" +pr_title="Synchronize common files from prometheus/prometheus" +pr_msg="Propagating changes from prometheus/prometheus default branch." orgs="prometheus prometheus-community" GITHUB_TOKEN="${GITHUB_TOKEN:-}" @@ -19,11 +19,13 @@ if [ -z "${GITHUB_TOKEN}" ]; then exit 1 fi +# List of files that should be synced. +SYNC_FILES="CODE_OF_CONDUCT.md LICENSE Makefile.common" + # Go to the root of the repo cd "$(git rev-parse --show-cdup)" || exit 1 -source_makefile="$(pwd)/Makefile.common" -source_checksum="$(sha256sum Makefile.common | cut -d' ' -f1)" +source_dir="$(pwd)" tmp_dir="$(mktemp -d)" trap 'rm -rf "${tmp_dir}"' EXIT @@ -55,14 +57,25 @@ process_repo() { local org_repo="$1" echo -e "\e[32mAnalyzing '${org_repo}'\e[0m" - target_makefile="$(curl -s --fail "https://raw.githubusercontent.com/${org_repo}/master/Makefile.common")" - if [ -z "${target_makefile}" ]; then - echo "Makefile.common doesn't exist in ${org_repo}" - return - fi - target_checksum="$(echo "${target_makefile}" | sha256sum | cut -d' ' -f1)" - if [ "${source_checksum}" == "${target_checksum}" ]; then - echo "Makefile.common is already in sync." + local needs_update=0 + for source_file in ${SYNC_FILES}; do + source_checksum="$(sha256sum "${souce_dir}/${source_file}" | cut -d' ' -f1)" + + target_file="$(curl -s --fail "https://raw.githubusercontent.com/${org_repo}/master/${source_file}")" + if [[ -z "${target_makefile}" ]]; then + echo "${source_file} doesn't exist in ${org_repo}" + continue + fi + target_checksum="$(echo "${target_file}" | sha256sum | cut -d' ' -f1)" + if [ "${source_checksum}" == "${target_checksum}" ]; then + echo "${source_file} is already in sync." + continue + fi + needs_update=1 + done + + if [[ "${needs_update}" -eq 0 ]] ; then + echo "No files need sync." return fi @@ -71,8 +84,11 @@ process_repo() { cd "${tmp_dir}/${org_repo}" || return 1 git checkout -b "${branch}" || return 1 - # Replace Makefile.common in target repo by one from prometheus/prometheus - cp -f "${source_makefile}" ./ + # Update the files in target repo by one from prometheus/prometheus. + for source_file in ${SYNC_FILES}; do + cp -f "${source_dir}/${source_file}" "./${source_file}" + done + if [ -n "$(git status --porcelain)" ]; then git config user.email "${git_mail}" git config user.name "${git_user}"