From 5703ba01275e7c5425a4eb7905ea8b12164181ac Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Thu, 12 Sep 2024 18:31:01 +0800 Subject: [PATCH] workflows: remove usage of `{owner}` and `{name}` These make `gh` do extra API calls that we don't need. --- .github/workflows/automerge-from-merge-queue.yml | 15 +++++++++------ .github/workflows/automerge.yml | 9 +++++---- .github/workflows/clean-up-closed-prs.yml | 2 +- .github/workflows/create-replacement-pr.yml | 4 ++-- .github/workflows/publish-commit-bottles.yml | 2 +- .github/workflows/recreate-linux-runners.yml | 2 +- .github/workflows/triage-ci.yml | 2 +- .github/workflows/triage.yml | 3 ++- 8 files changed, 22 insertions(+), 17 deletions(-) diff --git a/.github/workflows/automerge-from-merge-queue.yml b/.github/workflows/automerge-from-merge-queue.yml index ec8f4bd2d4e60..f694d9b170568 100644 --- a/.github/workflows/automerge-from-merge-queue.yml +++ b/.github/workflows/automerge-from-merge-queue.yml @@ -113,6 +113,8 @@ jobs: } run: | publishable=true + GITHUB_REPOSITORY_NAME="${GITHUB_REPOSITORY#"${GITHUB_REPOSITORY_OWNER}"/}" + while IFS='' read -r label do if [[ "$label" = "pre-release" ]] || @@ -125,14 +127,14 @@ jobs: gh api \ --header 'Accept: application/vnd.github+json' \ --header 'X-GitHub-Api-Version: 2022-11-28' \ - "repos/{owner}/{repo}/pulls/$PR" \ + "repos/$GITHUB_REPOSITORY/pulls/$PR" \ --jq '.labels[].name' ) removed_from_merge_queue_count="$( gh api graphql \ - --field owner='{owner}' \ - --field name='{repo}' \ + --field owner="$GITHUB_REPOSITORY_OWNER" \ + --field name="$GITHUB_REPOSITORY_NAME" \ --field pr="$PR" \ --raw-field query="$QUERY" \ --jq '.data.repository.pullRequest.timelineItems.totalCount' @@ -180,6 +182,7 @@ jobs: attempt=0 max_attempts=5 timeout=5 + GITHUB_REPOSITORY_NAME="${GITHUB_REPOSITORY#"${GITHUB_REPOSITORY_OWNER}"/}" while [[ "$attempt" -lt "$max_attempts" ]] do @@ -187,8 +190,8 @@ jobs: query_response="$( gh api graphql \ - --field owner='{owner}' \ - --field name='{repo}' \ + --field owner="$GITHUB_REPOSITORY_OWNER" \ + --field name="$GITHUB_REPOSITORY_NAME" \ --field pr="$PR" \ --raw-field query="$QUERY" \ --jq '.data.repository.pullRequest' @@ -208,7 +211,7 @@ jobs: gh api \ --header 'Accept: application/vnd.github+json' \ --header 'X-GitHub-Api-Version: 2022-11-28' \ - "repos/{owner}/{repo}/pulls/$PR" \ + "repos/$GITHUB_REPOSITORY/pulls/$PR" \ --jq '(.mergeable_state == "clean") and (.draft | not)' )" diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index cd7899172e890..81ba319bf722b 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -73,7 +73,7 @@ jobs: gh api \ --header 'Accept: application/vnd.github+json' \ --header 'X-GitHub-Api-Version: 2022-11-28' \ - "repos/{owner}/{repo}/pulls/$PR" \ + "repos/$GITHUB_REPOSITORY/pulls/$PR" \ --jq '.labels[].name' ) echo "publishable=$publishable" >> "$GITHUB_OUTPUT" @@ -112,6 +112,7 @@ jobs: attempt=0 max_attempts=5 timeout=5 + GITHUB_REPOSITORY_NAME="${GITHUB_REPOSITORY#"${GITHUB_REPOSITORY_OWNER}"/}" while [[ "$attempt" -lt "$max_attempts" ]] do @@ -119,8 +120,8 @@ jobs: query_response="$( gh api graphql \ - --field owner='{owner}' \ - --field name='{repo}' \ + --field owner="$GITHUB_REPOSITORY_OWNER" \ + --field name="$GITHUB_REPOSITORY_NAME" \ --field pr="$PR" \ --raw-field query="$QUERY" \ --jq '.data.repository.pullRequest' @@ -140,7 +141,7 @@ jobs: gh api \ --header 'Accept: application/vnd.github+json' \ --header 'X-GitHub-Api-Version: 2022-11-28' \ - "repos/{owner}/{repo}/pulls/$PR" \ + "repos/$GITHUB_REPOSITORY/pulls/$PR" \ --jq '(.mergeable_state == "clean") and (.draft | not)' )" diff --git a/.github/workflows/clean-up-closed-prs.yml b/.github/workflows/clean-up-closed-prs.yml index 03365829eafd1..6abe29ddba237 100644 --- a/.github/workflows/clean-up-closed-prs.yml +++ b/.github/workflows/clean-up-closed-prs.yml @@ -74,4 +74,4 @@ jobs: -X DELETE \ --header 'Accept: application/vnd.github+json' \ --header 'X-GitHub-Api-Version: 2022-11-28' \ - "repos/{owner}/{repo}/git/refs/heads/$BRANCH" + "repos/$GITHUB_REPOSITORY/git/refs/heads/$BRANCH" diff --git a/.github/workflows/create-replacement-pr.yml b/.github/workflows/create-replacement-pr.yml index 93c518c93a29a..fb97ed3ed3fad 100644 --- a/.github/workflows/create-replacement-pr.yml +++ b/.github/workflows/create-replacement-pr.yml @@ -86,7 +86,7 @@ jobs: gh api \ --header 'Accept: application/vnd.github+json' \ --header 'X-GitHub-Api-Version: 2022-11-28' \ - "repos/{owner}/{repo}/pulls/$PR/reviews" + "repos/$GITHUB_REPOSITORY/pulls/$PR/reviews" )" reviewers="$(jq --compact-output '[.[].user.login]' <<< "$review_data")" @@ -97,7 +97,7 @@ jobs: gh api \ --header 'Accept: application/vnd.github+json' \ --header 'X-GitHub-Api-Version: 2022-11-28' \ - "repos/{owner}/{repo}/pulls/$PR" \ + "repos/$GITHUB_REPOSITORY/pulls/$PR" \ --jq '(.mergeable_state == "clean") and (.draft | not)' )" diff --git a/.github/workflows/publish-commit-bottles.yml b/.github/workflows/publish-commit-bottles.yml index c44fdb5a0fc85..75074509f61a4 100644 --- a/.github/workflows/publish-commit-bottles.yml +++ b/.github/workflows/publish-commit-bottles.yml @@ -80,7 +80,7 @@ jobs: --header 'Accept: application/vnd.github+json' \ --header 'X-GitHub-Api-Version: 2022-11-28' \ --paginate \ - "repos/{owner}/{repo}/pulls/$PR/reviews" + "repos/$GITHUB_REPOSITORY/pulls/$PR/reviews" ) - name: Check PR branch for mergeability diff --git a/.github/workflows/recreate-linux-runners.yml b/.github/workflows/recreate-linux-runners.yml index 993361ef27fbb..2d7674aa2429d 100644 --- a/.github/workflows/recreate-linux-runners.yml +++ b/.github/workflows/recreate-linux-runners.yml @@ -64,7 +64,7 @@ jobs: gh api \ --header 'Accept: application/vnd.github+json' \ --header 'X-GitHub-Api-Version: 2022-11-28' \ - "repos/{owner}/{repo}/pulls/$PR" \ + "repos/$GITHUB_REPOSITORY/pulls/$PR" \ --jq 'any(.labels[].name; .== "CI-linux-self-hosted")' )" fi diff --git a/.github/workflows/triage-ci.yml b/.github/workflows/triage-ci.yml index 3f63498829110..2e45dbce5dddd 100644 --- a/.github/workflows/triage-ci.yml +++ b/.github/workflows/triage-ci.yml @@ -66,7 +66,7 @@ jobs: gh api \ --header 'Accept: application/vnd.github+json' \ --header 'X-GitHub-Api-Version: 2022-11-28' \ - "repos/{owner}/{repo}/pulls/$PR" + "repos/$GITHUB_REPOSITORY/pulls/$PR" )" comments_api_url="$(jq --raw-output '.comments_url' <<< "$response")" diff --git a/.github/workflows/triage.yml b/.github/workflows/triage.yml index f69a19937fad6..20b5bedbb16ad 100644 --- a/.github/workflows/triage.yml +++ b/.github/workflows/triage.yml @@ -35,12 +35,13 @@ jobs: id: files env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR: ${{ github.event.number }} run: | workflow_modified="$( gh api \ --header 'Accept: application/vnd.github+json' \ --header 'X-GitHub-Api-Version: 2022-11-28' \ - 'repos/{owner}/{repo}/pulls/${{ github.event.number }}/files' \ + "repos/$GITHUB_REPOSITORY/pulls/$PR/files" \ --jq 'any(.[].filename; startswith(".github/workflows"))' )" # Fail closed.