|
24 | 24 | today="$(date +"%Y-%m-%d")" |
25 | 25 | repo_url="https://github.com/google/gvisor.git" |
26 | 26 | pgo_branch_name="pgo/update-${today}" |
| 27 | + |
| 28 | +# If the remote branch already exists, do nothing. |
27 | 29 | existing_remote="$(git ls-remote --heads "$repo_url" "refs/heads/${pgo_branch_name}" || true)" |
28 | 30 | if [[ -n "$existing_remote" ]]; then |
29 | 31 | echo "Remote branch '$pgo_branch_name' already exists, skipping." >&2 |
30 | 32 | exit 0 |
31 | 33 | 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. |
32 | 48 | git stash |
33 | 49 | git pull --rebase=true "$repo_url" master |
34 | 50 | git checkout -b "$pgo_branch_name" |
35 | 51 | git stash pop |
36 | 52 | git add runsc/profiles |
37 | 53 | 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. |
41 | 56 | export GIT_AUTHOR_NAME=gvisor-bot |
42 | 57 | export GIT_AUTHOR_EMAIL=gvisor-bot@google.com |
43 | 58 | export GIT_COMMITTER_NAME=gvisor-bot |
44 | 59 | export GIT_COMMITTER_EMAIL=gvisor-bot@google.com |
45 | 60 | git commit -m "Update runsc profiles for PGO (profile-guided optimizations), $today." |
46 | 61 | git push --set-upstream "$repo_url" "$pgo_branch_name" |
47 | 62 |
|
| 63 | +# Send PR. |
48 | 64 | # The 'yes' command will fail when the `gh` command closes its stdin, |
49 | 65 | # which the `pipefail` option treats as a total failure. |
50 | 66 | # So disable this option for this particular command. |
51 | 67 | set +o pipefail |
52 | | -yes '' | gh pr create \ |
| 68 | +yes '' | gh pr --repo="$repo_url" create \ |
53 | 69 | --title="Update runsc profiles for PGO (profile-guided optimizations), $today." \ |
54 | 70 | --body='This PR updates the runsc profiles for PGO (profile-guided optimizations).' \ |
55 | 71 | --label=pgo-update --label='ready to pull' \ |
|
0 commit comments