Skip to content

Commit

Permalink
workflows: remove usage of {owner} and {name}
Browse files Browse the repository at this point in the history
These make `gh` do extra API calls that we don't need.
  • Loading branch information
carlocab committed Sep 12, 2024
1 parent c829b3d commit 5703ba0
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 17 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/automerge-from-merge-queue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]] ||
Expand All @@ -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'
Expand Down Expand Up @@ -180,15 +182,16 @@ jobs:
attempt=0
max_attempts=5
timeout=5
GITHUB_REPOSITORY_NAME="${GITHUB_REPOSITORY#"${GITHUB_REPOSITORY_OWNER}"/}"
while [[ "$attempt" -lt "$max_attempts" ]]
do
attempt=$(( attempt + 1 ))
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'
Expand All @@ -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)'
)"
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/automerge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -112,15 +112,16 @@ jobs:
attempt=0
max_attempts=5
timeout=5
GITHUB_REPOSITORY_NAME="${GITHUB_REPOSITORY#"${GITHUB_REPOSITORY_OWNER}"/}"
while [[ "$attempt" -lt "$max_attempts" ]]
do
attempt=$(( attempt + 1 ))
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'
Expand All @@ -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)'
)"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/clean-up-closed-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions .github/workflows/create-replacement-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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")"
Expand All @@ -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)'
)"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-commit-bottles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/recreate-linux-runners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/triage-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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")"
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 5703ba0

Please sign in to comment.