forked from foundation-model-stack/foundation-model-stack
-
Notifications
You must be signed in to change notification settings - Fork 0
133 lines (122 loc) 路 5.04 KB
/
Copy pathghstack_rebase.yaml
File metadata and controls
133 lines (122 loc) 路 5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# The rebase-command workflow runs rebase + ghstack submit on the PR
#
# This workflow is triggered by leaving a "/rebase" comment on
# a pull request. If the required preconditions are met, it will
# rebase a stack of PRs that includes the current one as well as
# all the PRs underneath it in the stack.
#
# Conditions are checked through the "ghstack-perm-check.py"
# python script defined in the .github/workflows/scripts folder.
#
# Condition for the "/rebase" command are:
# - the current PR is in the format generated by ghstack
# - either the issuer is the author of the PR
# - or the issuer is a maintainer
#
# The PRs are rebased by a bot account "fms-cibot" which has push
# permissions on the repo.
#
# When a rebase is executed successfully, the horray emoji is added
# When a rebase execution fails, a comment is added with a link to the logs
name: Rebase ghstack PRs
on:
repository_dispatch:
types: [rebase-command]
jobs:
ghstack_rebase:
name: ghstack Rebase
runs-on: ubuntu-latest
steps:
- name: Show Environment Variables
run: env
- name: Show Github Object
run: |
cat <<'EOF'
${{ toJson(github) }}
EOF
- name: Show Github Event Path Json
run: 'cat "$GITHUB_EVENT_PATH" || true'
- uses: actions/checkout@v4
with:
token: ${{ secrets.LAND_TOKEN }}
fetch-depth: '0'
- uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Check Rebase Preconditions
run: |
pip install requests ghstack
# Check prerequisites and set environment variables
# IS_GHSTACK, REPO, PR_NUMBER, PR_REF, PR_URL, PR_FROM_FORK
.github/workflows/scripts/ghstack-perm-check.py rebase <<'EOF'
${{ toJson(github) }}
EOF
env:
GITHUB_TOKEN: ${{ secrets.LAND_TOKEN }}
- name: Rebase It!
id: rebaseStack
run: |
# Configure Git and GHStack
# TODO: update the bot e-mail once a correct e-mail is available
git config --global user.email "foundation-model-stack@googlegroups.com"
git config --global user.name "Foundation Model Stack CI Bot"
if [[ "${IS_GHSTACK}" == "True" ]]; then
# Configure ghstack
cat <<EOF > ~/.ghstackrc
[ghstack]
github_url = github.com
github_oauth = $GITHUB_TOKEN
github_username = afrittoli
remote_name = origin
EOF
# Checkout the */orig committer branch for rebase
# See https://github.com/ezyang/ghstack?tab=readme-ov-file#structure-of-submitted-pull-requests
# This is equivalent to "ghstack checkout <pr>", but it doesn't require
# extra API calls to GitHub
git checkout -b rebase-branch "origin/${PR_REF}"
else
gh pr checkout --repo "${REPO}" "${PR_NUMBER}"
fi
# Do the actual rebase. Git rebase will exit with 1 in case or merge conflicts
# The rebase command is the same for GHStack and GitHub PRs
git rebase origin/main
if [[ "${IS_GHSTACK}" == "True" ]]; then
# Submit the rebased stack to updated the PRs
ghstack submit
else
# Force-push is the only way to have a rebased branch upstream
# In case of failure, check if the PR is from a fork. Depending
# on how the PR is configured, push might not be possible for the bot
# See https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork
if ! git push --force; then
if [[ "${PR_FROM_FORK}" == "true" ]]; then
echo "The PR has been created from a fork."
echo "Please rebase your PR manually and push the updates to the branch on your fork."
exit 1
fi
fi
fi
env:
GITHUB_TOKEN: ${{ secrets.LAND_TOKEN }}
- name: Create URL to the run output
if: ${{ failure() && steps.rebaseStack.outcome == 'failure' }}
id: vars
run: echo "run-url=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_OUTPUT
- name: Create comment
if: ${{ failure() && steps.rebaseStack.outcome == 'failure' }}
uses: peter-evans/create-or-update-comment@v2
with:
token: ${{ secrets.LAND_TOKEN }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
issue-number: ${{ github.event.client_payload.github.payload.issue.number }}
body: |
Something went wrong with your `/${{ github.event.client_payload.slash_command.command }}` command: [please check the logs][1].
[1]: ${{ steps.vars.outputs.run-url }}
- name: Add reaction
if: ${{ success() }}
uses: peter-evans/create-or-update-comment@v2
with:
token: ${{ secrets.LAND_TOKEN }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
reaction-type: hooray