-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
63 lines (58 loc) · 2.39 KB
/
action.yml
File metadata and controls
63 lines (58 loc) · 2.39 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
name: 'Stacked PR Update Action'
description: 'Automatically fixes stacked PRs after a base PR is squash-merged'
author: 'GitHub Actions'
inputs:
github-token:
description: >
Token for git push and GitHub API calls. The default GITHUB_TOKEN will NOT
trigger CI on upstack PRs (GitHub deliberately suppresses workflow runs from
pushes made with that token). Use a GitHub App installation token if you need
checks to run on the updated PRs.
required: true
default: ${{ github.token }}
runs:
using: 'composite'
steps:
- name: Check if action should run
id: check
shell: bash
env:
EVENT_ACTION: ${{ github.event.action }}
PR_LABELS: ${{ join(github.event.pull_request.labels.*.name, ',') }}
PR_MERGED: ${{ github.event.pull_request.merged }}
MERGE_COMMIT_SHA: ${{ github.event.pull_request.merge_commit_sha }}
run: |
if [[ "$EVENT_ACTION" == "closed" && "$PR_MERGED" == "true" && -n "$MERGE_COMMIT_SHA" ]]; then
echo "mode=squash-merge" >> $GITHUB_OUTPUT
elif [[ "$EVENT_ACTION" == "synchronize" && "$PR_LABELS" == *autorestack-needs-conflict-resolution* ]]; then
echo "mode=conflict-resolved" >> $GITHUB_OUTPUT
else
echo "Event does not match any action trigger (action=$EVENT_ACTION, merged=$PR_MERGED, labels=$PR_LABELS)"
echo "mode=skip" >> $GITHUB_OUTPUT
fi
- name: Checkout repository
if: steps.check.outputs.mode != 'skip'
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ inputs.github-token }}
- name: Update PR stack
if: steps.check.outputs.mode != 'skip'
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
GIT_AUTHOR_NAME: github-actions
GIT_AUTHOR_EMAIL: github-actions@github.com
GIT_COMMITTER_NAME: github-actions
GIT_COMMITTER_EMAIL: github-actions@github.com
ACTION_MODE: ${{ steps.check.outputs.mode }}
SQUASH_COMMIT: ${{ github.event.pull_request.merge_commit_sha }}
MERGED_BRANCH: ${{ github.event.pull_request.head.ref }}
TARGET_BRANCH: ${{ github.event.pull_request.base.ref }}
PR_BRANCH: ${{ github.event.pull_request.head.ref }}
run: |
echo "Running in $ACTION_MODE mode"
${{ github.action_path }}/update-pr-stack.sh
branding:
icon: 'git-pull-request'
color: 'blue'