Skip to content

Commit c63bd8d

Browse files
EtiennePerotgvisor-bot
authored andcommitted
PGO: Do not create PR if an open PR for PGO update exists already.
PiperOrigin-RevId: 772622618
1 parent e52b895 commit c63bd8d

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

.buildkite/scripts/pgo/commit-update.sh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,48 @@ fi
2424
today="$(date +"%Y-%m-%d")"
2525
repo_url="https://github.com/google/gvisor.git"
2626
pgo_branch_name="pgo/update-${today}"
27+
28+
# If the remote branch already exists, do nothing.
2729
existing_remote="$(git ls-remote --heads "$repo_url" "refs/heads/${pgo_branch_name}" || true)"
2830
if [[ -n "$existing_remote" ]]; then
2931
echo "Remote branch '$pgo_branch_name' already exists, skipping." >&2
3032
exit 0
3133
fi
34+
35+
# GitHub CLI authentication.
36+
gh --version
37+
gh auth login --with-token < "$HOME/.github-token"
38+
gh auth setup-git
39+
40+
# If there is already an open PR for PGO update, do nothing.
41+
if [[ "$(gh pr --repo="$repo_url" list --label pgo-update --state open --json title --jq length)" -gt 0 ]]; then
42+
echo "There is already an open PR for PGO update, skipping." >&2
43+
PAGER=cat gh pr --repo="$repo_url" list --label pgo-update --state open
44+
exit 0
45+
fi
46+
47+
# Create new branch for the PR and stages changes in it.
3248
git stash
3349
git pull --rebase=true "$repo_url" master
3450
git checkout -b "$pgo_branch_name"
3551
git stash pop
3652
git add runsc/profiles
3753
git status
38-
gh --version
39-
gh auth login --with-token < "$HOME/.github-token"
40-
gh auth setup-git
54+
55+
# Commit and push PR branch.
4156
export GIT_AUTHOR_NAME=gvisor-bot
4257
export GIT_AUTHOR_EMAIL=gvisor-bot@google.com
4358
export GIT_COMMITTER_NAME=gvisor-bot
4459
export GIT_COMMITTER_EMAIL=gvisor-bot@google.com
4560
git commit -m "Update runsc profiles for PGO (profile-guided optimizations), $today."
4661
git push --set-upstream "$repo_url" "$pgo_branch_name"
4762

63+
# Send PR.
4864
# The 'yes' command will fail when the `gh` command closes its stdin,
4965
# which the `pipefail` option treats as a total failure.
5066
# So disable this option for this particular command.
5167
set +o pipefail
52-
yes '' | gh pr create \
68+
yes '' | gh pr --repo="$repo_url" create \
5369
--title="Update runsc profiles for PGO (profile-guided optimizations), $today." \
5470
--body='This PR updates the runsc profiles for PGO (profile-guided optimizations).' \
5571
--label=pgo-update --label='ready to pull' \

0 commit comments

Comments
 (0)