perf: optimize classic-only histogram observe path #125
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| name: Detect API Changes | |
| on: | |
| # pull_request_target is used so the workflow can update labels and comments | |
| # without checking out or executing code from the PR branch. | |
| # zizmor: ignore[dangerous-triggers] -- this workflow only reads PR metadata | |
| # via the GitHub API and never checks out or executes code from the PR branch. | |
| pull_request_target: | |
| types: | |
| - opened | |
| - synchronize | |
| - reopened | |
| - ready_for_review | |
| permissions: {} | |
| jobs: | |
| detect-api-changes: | |
| if: github.repository == 'prometheus/client_java' | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| issues: write | |
| pull-requests: write | |
| steps: | |
| - name: Check for API changes and update PR | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| REPO: ${{ github.repository }} | |
| run: | | |
| MARKER="<!-- api-change-detector -->" | |
| BREAKING_LABEL="breaking-api-change" | |
| api_files=$(gh api "repos/${REPO}/pulls/${PR_NUMBER}/files" --paginate \ | |
| --jq '.[] | select(.filename | startswith("docs/apidiffs/current_vs_latest/")) | .filename') | |
| comment_id=$(gh api "repos/${REPO}/issues/${PR_NUMBER}/comments" --paginate \ | |
| --jq ".[] | select(.body | startswith(\"${MARKER}\")) | .id" | head -1) | |
| if [[ -z "$api_files" ]]; then | |
| echo "No API diff files changed." | |
| gh pr edit "$PR_NUMBER" --repo "$REPO" --remove-label "api-change" 2>/dev/null || true | |
| gh pr edit "$PR_NUMBER" --repo "$REPO" --remove-label "$BREAKING_LABEL" 2>/dev/null || true | |
| if [[ -n "$comment_id" ]]; then | |
| gh api --method DELETE "repos/${REPO}/issues/comments/${comment_id}" | |
| fi | |
| exit 0 | |
| fi | |
| echo "API diff files changed:" | |
| echo "$api_files" | |
| gh pr edit "$PR_NUMBER" --repo "$REPO" --add-label "api-change" | |
| modules=$(echo "$api_files" \ | |
| | sed 's|docs/apidiffs/current_vs_latest/||' \ | |
| | sed 's|\.txt$||' \ | |
| | sort \ | |
| | sed 's/^/- /') | |
| HEAD_SHA=$(gh api "repos/${REPO}/pulls/${PR_NUMBER}" --jq .head.sha) | |
| breaking_files=() | |
| while IFS= read -r file; do | |
| [[ -z "$file" ]] && continue | |
| content=$(gh api \ | |
| -H "Accept: application/vnd.github.raw" \ | |
| "repos/${REPO}/contents/${file}?ref=${HEAD_SHA}") | |
| if grep -Eq '^[[:space:]]*(\*\*\*!|---!|\+\+\+!)' <<<"$content"; then | |
| breaking_files+=("$file") | |
| fi | |
| done <<<"$api_files" | |
| if [[ ${#breaking_files[@]} -gt 0 ]]; then | |
| gh pr edit "$PR_NUMBER" --repo "$REPO" --add-label "$BREAKING_LABEL" | |
| breaking_modules=$(printf '%s\n' "${breaking_files[@]}" \ | |
| | sed 's|docs/apidiffs/current_vs_latest/||' \ | |
| | sed 's|\.txt$||' \ | |
| | sort \ | |
| | sed 's/^/- /') | |
| body=$(cat <<EOF | |
| ${MARKER} | |
| ## :warning: Breaking API changes detected — maintainer review required | |
| This PR modifies the published API diff for the following module(s): | |
| ${modules} | |
| The committed API diff contains breaking-change markers for: | |
| ${breaking_modules} | |
| Please review the changes in \`docs/apidiffs/current_vs_latest/\` carefully before approving. | |
| EOF | |
| ) | |
| else | |
| gh pr edit "$PR_NUMBER" --repo "$REPO" --remove-label "$BREAKING_LABEL" 2>/dev/null || true | |
| body=$(cat <<EOF | |
| ${MARKER} | |
| ## :warning: API changes detected — maintainer review required | |
| This PR modifies the published API diff for the following module(s): | |
| ${modules} | |
| Please review the changes in \`docs/apidiffs/current_vs_latest/\` carefully before approving. | |
| EOF | |
| ) | |
| fi | |
| if [[ -n "$comment_id" ]]; then | |
| gh api --method PATCH "repos/${REPO}/issues/comments/${comment_id}" \ | |
| --field body="$body" | |
| else | |
| gh pr comment "$PR_NUMBER" --repo "$REPO" --body "$body" | |
| fi |