-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
55 lines (44 loc) · 1.94 KB
/
action.yml
File metadata and controls
55 lines (44 loc) · 1.94 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
name: GHerrit – Rebase Stack
description: 'Automatically rebase the next PR in a GHerrit stack.'
inputs:
token:
description: '`GITHUB_TOKEN` to allow rebase and push'
required: true
pr_body:
description: 'The body/description of the PR that was just merged. Used to extract the child PR ID from the GHerrit metadata.'
required: true
runs:
using: "composite"
steps:
- shell: bash
env:
GH_TOKEN: ${{ inputs.token }}
MERGED_PR_BODY: ${{ inputs.pr_body }}
run: |
# Extract the Child ID from the merged PR's metadata by parsing the
# JSON inside the HTML comment.
CHILD_ID=$(echo "$MERGED_PR_BODY" | grep -oP '(?<=gherrit-meta: ).*?(?= -->)' | jq -r .child)
if [ -z "$CHILD_ID" ] || [ "$CHILD_ID" == "null" ]; then
echo "Merged PR has no child defined in metadata. Reached top of stack."
exit 0
fi
echo "Merged PR indicates next child is ID: $CHILD_ID"
# Find the PR associated with that ID. Since GHerrit branches are
# named exactly after the ID (e.g. refs/heads/G...), we can lookup
# the PR by branch name (--head).
CHILD_PR=$(gh pr list --head "$CHILD_ID" --json number --jq '.[0].number')
if [ -z "$CHILD_PR" ]; then
echo "Error: Metadata says child is $CHILD_ID, but no open PR exists for branch '$CHILD_ID'."
echo "The chain might be broken or the child was deleted."
exit 1
fi
echo "Identified Child PR: #$CHILD_PR"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
gh pr checkout "$CHILD_PR"
gh pr edit "$CHILD_PR" --base main
if ! git rebase origin/main; then
echo "::error::Rebase conflict for PR #$CHILD_PR. Manual intervention required."
exit 1
fi
git push --force-with-lease