Merge pull request #7411 from prometheus/superq/sync_changes

Improve repo sync script
This commit is contained in:
Ben Kochie 2020-06-18 15:25:30 +02:00 committed by GitHub
commit 7b4f81b397
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 19 deletions

View file

@ -87,11 +87,11 @@ jobs:
- setup_remote_docker - setup_remote_docker
- run: ./fuzzit.sh fuzzing - run: ./fuzzit.sh fuzzing
makefile_sync: repo_sync:
executor: golang executor: golang
steps: steps:
- checkout - checkout
- run: ./scripts/sync_makefiles.sh - run: ./scripts/sync_repo_files.sh
workflows: workflows:
version: 2 version: 2
@ -143,7 +143,7 @@ workflows:
only: only:
- master - master
jobs: jobs:
- makefile_sync: - repo_sync:
context: org-context context: org-context
- fuzzit_fuzzing: - fuzzit_fuzzing:
context: org-context context: org-context

View file

@ -7,10 +7,10 @@ set -uo pipefail
git_mail="prometheus-team@googlegroups.com" git_mail="prometheus-team@googlegroups.com"
git_user="prombot" git_user="prombot"
branch="makefile_common" branch="repo_sync"
commit_msg="makefile: update Makefile.common with newer version" commit_msg="Update common Prometheus files"
pr_title="Synchronize Makefile.common from prometheus/prometheus" pr_title="Synchronize common files from prometheus/prometheus"
pr_msg="Propagating changes from master Makefile.common located in prometheus/prometheus." pr_msg="Propagating changes from prometheus/prometheus default branch."
orgs="prometheus prometheus-community" orgs="prometheus prometheus-community"
GITHUB_TOKEN="${GITHUB_TOKEN:-}" GITHUB_TOKEN="${GITHUB_TOKEN:-}"
@ -19,11 +19,13 @@ if [ -z "${GITHUB_TOKEN}" ]; then
exit 1 exit 1
fi fi
# List of files that should be synced.
SYNC_FILES="CODE_OF_CONDUCT.md LICENSE Makefile.common"
# Go to the root of the repo # Go to the root of the repo
cd "$(git rev-parse --show-cdup)" || exit 1 cd "$(git rev-parse --show-cdup)" || exit 1
source_makefile="$(pwd)/Makefile.common" source_dir="$(pwd)"
source_checksum="$(sha256sum Makefile.common | cut -d' ' -f1)"
tmp_dir="$(mktemp -d)" tmp_dir="$(mktemp -d)"
trap 'rm -rf "${tmp_dir}"' EXIT trap 'rm -rf "${tmp_dir}"' EXIT
@ -55,14 +57,25 @@ process_repo() {
local org_repo="$1" local org_repo="$1"
echo -e "\e[32mAnalyzing '${org_repo}'\e[0m" echo -e "\e[32mAnalyzing '${org_repo}'\e[0m"
target_makefile="$(curl -s --fail "https://raw.githubusercontent.com/${org_repo}/master/Makefile.common")" local needs_update=0
if [ -z "${target_makefile}" ]; then for source_file in ${SYNC_FILES}; do
echo "Makefile.common doesn't exist in ${org_repo}" source_checksum="$(sha256sum "${souce_dir}/${source_file}" | cut -d' ' -f1)"
return
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 fi
target_checksum="$(echo "${target_makefile}" | sha256sum | cut -d' ' -f1)" target_checksum="$(echo "${target_file}" | sha256sum | cut -d' ' -f1)"
if [ "${source_checksum}" == "${target_checksum}" ]; then if [ "${source_checksum}" == "${target_checksum}" ]; then
echo "Makefile.common is already in sync." 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 return
fi fi
@ -71,8 +84,11 @@ process_repo() {
cd "${tmp_dir}/${org_repo}" || return 1 cd "${tmp_dir}/${org_repo}" || return 1
git checkout -b "${branch}" || return 1 git checkout -b "${branch}" || return 1
# Replace Makefile.common in target repo by one from prometheus/prometheus # Update the files in target repo by one from prometheus/prometheus.
cp -f "${source_makefile}" ./ for source_file in ${SYNC_FILES}; do
cp -f "${source_dir}/${source_file}" "./${source_file}"
done
if [ -n "$(git status --porcelain)" ]; then if [ -n "$(git status --porcelain)" ]; then
git config user.email "${git_mail}" git config user.email "${git_mail}"
git config user.name "${git_user}" git config user.name "${git_user}"