mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Sync CircleCI Orb version
Add sync of the Prometheus CircleCI Orb version to the sync script. * Add `yq` to the repo sync CI job. NOTE: This will re-format the down-stream yaml config, it does not preserve whitespace and enforces some indenting rules. It does preserve comments. Signed-off-by: Ben Kochie <superq@gmail.com>
This commit is contained in:
parent
f0c1d33b3a
commit
e73930e3d5
|
@ -110,6 +110,8 @@ jobs:
|
|||
executor: golang
|
||||
steps:
|
||||
- checkout
|
||||
- run: curl -sL https://github.com/mikefarah/yq/releases/download/v4.6.3/yq_linux_amd64 -O "${PATH%%:*}/yq" && chmod -v +x "${PATH%%:*}/yq"
|
||||
- run: sha256sum -c <(echo "c4343783c3361495c0d6d1eb742bba7432aa65e13e9fb8d7e201d544bcf14247 ${PATH%%:*}/yq")
|
||||
- run: ./scripts/sync_repo_files.sh
|
||||
|
||||
workflows:
|
||||
|
|
|
@ -42,6 +42,13 @@ source_dir="$(pwd)"
|
|||
tmp_dir="$(mktemp -d)"
|
||||
trap 'rm -rf "${tmp_dir}"' EXIT
|
||||
|
||||
prometheus_orb_version="$(yq eval '.orbs.prometheus' .circleci/config.yml)"
|
||||
if [[ -z "${prometheus_orb_version}" ]]; then
|
||||
echo_red '"ERROR: Unable to get CircleCI orb version'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## Internal functions
|
||||
github_api() {
|
||||
local url
|
||||
url="https://api.github.com/${1}"
|
||||
|
@ -84,6 +91,24 @@ check_license() {
|
|||
echo "$1" | grep --quiet --no-messages --ignore-case 'Apache License'
|
||||
}
|
||||
|
||||
check_circleci_orb() {
|
||||
local org_repo
|
||||
local default_branch
|
||||
org_repo="$1"
|
||||
default_branch="$2"
|
||||
local ci_config_url="https://raw.githubusercontent.com/${org_repo}/${default_branch}/.circleci/config.yml"
|
||||
|
||||
orb_version="$(curl -sL --fail "${ci_config_url}" | yq eval '.orbs.prometheus' -)"
|
||||
if [[ -z "${orb_version}" ]]; then
|
||||
echo_red "ERROR: Failed to fetch CirleCI orb version from '${org_repo}'"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ "${orb_version}" != "${prometheus_orb_version}" ]]; then
|
||||
echo "CircleCI-orb"
|
||||
fi
|
||||
}
|
||||
|
||||
process_repo() {
|
||||
local org_repo
|
||||
local default_branch
|
||||
|
@ -101,7 +126,7 @@ process_repo() {
|
|||
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}/${default_branch}/${source_file}")"
|
||||
target_file="$(curl -sL --fail "https://raw.githubusercontent.com/${org_repo}/${default_branch}/${source_file}")"
|
||||
if [[ "${source_file}" == 'LICENSE' ]] && ! check_license "${target_file}" ; then
|
||||
echo "LICENSE in ${org_repo} is not apache, skipping."
|
||||
continue
|
||||
|
@ -125,6 +150,13 @@ process_repo() {
|
|||
needs_update+=("${source_file}")
|
||||
done
|
||||
|
||||
local circleci
|
||||
circleci="$(check_circleci_orb "${org_repo}" "${default_branch}")"
|
||||
if [[ -n "${circleci}" ]]; then
|
||||
echo "${circleci} needs updating."
|
||||
needs_update+=("${circleci}")
|
||||
fi
|
||||
|
||||
if [[ "${#needs_update[@]}" -eq 0 ]] ; then
|
||||
echo "No files need sync."
|
||||
return
|
||||
|
@ -137,7 +169,10 @@ process_repo() {
|
|||
|
||||
# Update the files in target repo by one from prometheus/prometheus.
|
||||
for source_file in "${needs_update[@]}"; do
|
||||
cp -f "${source_dir}/${source_file}" "./${source_file}"
|
||||
case "${source_file}" in
|
||||
CircleCI-orb) yq eval -i ".orbs.prometheus = \"${prometheus_orb_version}\"" .circleci/config.yml ;;
|
||||
*) cp -f "${source_dir}/${source_file}" "./${source_file}" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -n "$(git status --porcelain)" ]]; then
|
||||
|
@ -156,6 +191,7 @@ process_repo() {
|
|||
fi
|
||||
}
|
||||
|
||||
## main
|
||||
for org in ${orgs}; do
|
||||
mkdir -p "${tmp_dir}/${org}"
|
||||
# Iterate over all repositories in ${org}. The GitHub API can return 100 items
|
||||
|
|
Loading…
Reference in a new issue