-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (123 loc) · 5.36 KB
/
ghstack_land.yml
File metadata and controls
132 lines (123 loc) · 5.36 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
name: ghstack land
on:
issue_comment:
types: [created]
jobs:
ghstack_land:
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/land') }}
runs-on: ubuntu-latest
steps:
- name: Show Environment Variables
run: env
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}
- name: Add reaction to comment
run: |
COMMENT_ID=$(echo "${{ github.event.comment.id }}")
REPO="${{ github.repository }}"
curl -X POST \
-H "Authorization: token ${{ steps.app-token.outputs.token }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/$REPO/issues/comments/$COMMENT_ID/reactions" \
-d '{"content":"rocket"}'
- name: Show Github Object
run: |
cat <<'EOF'
${{ toJson(github) }}
EOF
- name: Show Github Event Path Json
run: 'cat $GITHUB_EVENT_PATH || true'
- name: Check if force flag is present and has reason
id: check-force
run: |
if [[ "$COMMENT" == *"--force"* ]]; then
echo "Force flag detected, checking for reason..."
# Extract text after --force (trim leading/trailing whitespace)
REASON=$(echo "$COMMENT" | sed -n 's/.*--force\s*\(.*\)/\1/p' | xargs)
if [[ -z "$REASON" ]]; then
echo "::error::Force flag requires a reason. Please use format: /land --force <reason>"
gh pr comment "${{ github.event.issue.html_url }}" --body "⚠️ Force landing failed: You must provide a reason when using --force. Please use the format: \`/land --force <reason>\`"
exit 1
else
echo "Force reason provided: $REASON"
echo "force_flag=--force" >> $GITHUB_OUTPUT
echo "force_reason=$REASON" >> $GITHUB_OUTPUT
fi
else
echo "No force flag detected"
echo "force_flag=" >> $GITHUB_OUTPUT
echo "force_reason=" >> $GITHUB_OUTPUT
fi
env:
COMMENT: ${{ github.event.comment.body }}
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: "0.6.9"
- name: Get PR details
id: get-pr
run: |
PR_NUMBER=${{ github.event.issue.number }}
echo "PR number is $PR_NUMBER"
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
# Get PR details using GitHub API
PR_DATA=$(curl -s \
-H "Authorization: token ${{ steps.app-token.outputs.token }}" \
-H "Accept: application/vnd.github.v3+json" \
"${{ github.api_url }}/repos/${{ github.repository }}/pulls/$PR_NUMBER")
# Extract useful information
PR_HEAD_REF=$(echo "$PR_DATA" | jq -r .head.ref)
PR_HEAD_SHA=$(echo "$PR_DATA" | jq -r .head.sha)
PR_URL="${{ github.server_url }}/${{ github.repository }}/pull/$PR_NUMBER"
echo "pr_branch=$PR_HEAD_REF" >> $GITHUB_OUTPUT
echo "pr_sha=$PR_HEAD_SHA" >> $GITHUB_OUTPUT
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
echo "pr_branch=$PR_HEAD_REF"
echo "pr_sha=$PR_HEAD_SHA"
echo "pr_url=$PR_URL"
- uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
fetch-depth: '0'
- uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Check Current CI Status
if: ${{ steps.check-force.outputs.force_flag == '' }}
run: |
uv pip install --system requests
echo ${{ github.event.issue.number }}
.github/workflows/scripts/ghstack-perm-check.py ${{ github.event.issue.number }} ${{steps.get-pr.outputs.pr_branch}} ${{ github.repository }}
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Log Force Landing
if: ${{ steps.check-force.outputs.force_flag != '' }}
run: |
echo "Force landing PR #${{ steps.get-pr.outputs.pr_number }}"
echo "Reason: ${{ steps.check-force.outputs.force_reason }}"
# Post a comment to the PR with the force reason
gh pr comment "${{ steps.get-pr.outputs.pr_url }}" --body "⚠️ **Force landing** initiated by @${{ github.event.comment.user.login }} with reason: ${{ steps.check-force.outputs.force_reason }}"
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Land It!
run: |
uv pip install --system ghstack
git config --global user.email "bot@thinkingmachines.ai"
git config --global user.name "ghstack bot"
cat <<EOF > ~/.ghstackrc
[ghstack]
github_url = github.com
github_oauth = $GITHUB_TOKEN
github_username = foo
remote_name = origin
EOF
if ! ghstack land "${{ steps.get-pr.outputs.pr_url }}"; then
gh pr comment "${{ steps.get-pr.outputs.pr_url }}" --body "Failed to land PR using ghstack. See workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
exit 1
fi
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}