|
16 | 16 | command: | |
17 | 17 | set -o xtrace |
18 | 18 | UBUNTU_CODE_NAME="noble" |
| 19 | + BASE_OWNER="percona" |
| 20 | + BASE_REPO="percona-server" |
19 | 21 | BASE_BRANCH="8.4" |
20 | 22 | COMPILER_VERSION="19" |
21 | 23 |
|
|
26 | 28 | cd ~/project |
27 | 29 | cmake -B /home/circleci/debug-build -DCMAKE_BUILD_TYPE=Debug -DWITH_SSL=system -DWITH_AUTHENTICATION_LDAP=ON -DWITH_ROCKSDB=ON -DCMAKE_C_COMPILER=clang-${COMPILER_VERSION} -DCMAKE_CXX_COMPILER=clang++-${COMPILER_VERSION} -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DCMAKE_EXE_LINKER_FLAGS="-stdlib=libc++" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DWITH_SYSTEM_LIBS=ON -DWITH_FIDO=bundled -DWITH_ZSTD=bundled -DWITH_LZ4=bundled -DWITH_PROTOBUF=bundled ~/project |
28 | 30 |
|
29 | | - git remote add target "https://github.com/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" |
| 31 | + # Method to fetch JSON from a Github API URL with error handling |
| 32 | + fetch_json() { |
| 33 | + local url="$1" tmp http_code curl_exit body |
| 34 | + tmp=$(mktemp) || return 1 |
| 35 | + # write body to tmp, capture HTTP code on stdout |
| 36 | + http_code=$(curl -sS --location --connect-timeout 10 --max-time 30 -w "%{http_code}" -o "$tmp" "$url" 2>/dev/null) || true |
| 37 | + curl_exit=$? |
| 38 | + body="$(cat "$tmp")" |
| 39 | + rm -f "$tmp" |
| 40 | +
|
| 41 | + if [ $curl_exit -ne 0 ]; then |
| 42 | + echo "curl exit $curl_exit for $url" >&2 |
| 43 | + return 2 |
| 44 | + fi |
| 45 | + if [ -z "$http_code" ] || [ "$http_code" -ge 400 ]; then |
| 46 | + echo "HTTP $http_code from $url" >&2 |
| 47 | + return 3 |
| 48 | + fi |
| 49 | + if [ -z "${body:-}" ]; then |
| 50 | + echo "empty response from $url" >&2 |
| 51 | + return 4 |
| 52 | + fi |
| 53 | + if ! printf '%s' "$body" | jq -e . >/dev/null 2>&1; then |
| 54 | + echo "response from $url is not valid JSON" >&2 |
| 55 | + return 5 |
| 56 | + fi |
| 57 | +
|
| 58 | + printf '%s' "$body" |
| 59 | + } |
| 60 | +
|
| 61 | + PR_DATA="" |
| 62 | + if [[ "$CIRCLE_BRANCH" =~ ^pull/[0-9]+$ ]]; then |
| 63 | + # If the circleCI check is run in the context of the official percona repo. |
| 64 | + PR_API_URL="https://api.github.com/repos/${BASE_OWNER}/${BASE_REPO}/pulls/${CIRCLE_PR_NUMBER}" |
| 65 | + PR_DATA="$(fetch_json "$PR_API_URL")" || PR_DATA="" |
| 66 | + else |
| 67 | + # GitHub API URL to get open PRs matching this fork + branch |
| 68 | + API_URL="https://api.github.com/repos/${BASE_OWNER}/${BASE_REPO}/pulls?head=${CIRCLE_PROJECT_USERNAME}:${CIRCLE_BRANCH}" |
| 69 | + echo "Fetching PRs from: $API_URL" >&2 |
| 70 | +
|
| 71 | + # Fetch PRs |
| 72 | + PRS_JSON="$(fetch_json "$API_URL")" || PRS_JSON="[]" |
| 73 | +
|
| 74 | + # Filter PR whose head.sha matches CIRCLE_SHA1 |
| 75 | + PR_DATA="$(printf '%s' "$PRS_JSON" | jq --arg sha "$CIRCLE_SHA1" '.[] | select(.head.sha == $sha)')" |
| 76 | + fi |
| 77 | +
|
| 78 | + if [[ -z "$PR_DATA" ]]; then |
| 79 | + echo "Failed to find PR data for commit $CIRCLE_SHA1. $BASE_BRANCH will be used as the base branch." |
| 80 | + else |
| 81 | + BASE_BRANCH=$(echo "$PR_DATA" | jq -r '.base.ref') |
| 82 | + PR_NUMBER=$(echo "$PR_DATA" | jq -r '.number') |
| 83 | + echo "Found PR: $PR_NUMBER with base branch: $BASE_BRANCH" |
| 84 | + fi |
| 85 | +
|
| 86 | + echo "$BASE_BRANCH" |
| 87 | + git remote add target "https://github.com/${BASE_OWNER}/${BASE_REPO}" |
30 | 88 | git fetch --no-tags --no-recurse-submodules target $BASE_BRANCH |
31 | 89 |
|
32 | 90 | echo "Checking clang-format results" |
|
0 commit comments