-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
action.yml
72 lines (66 loc) · 2.23 KB
/
action.yml
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
name: "Extremely Linear Merging"
description: '"Merge" GitHub Pull Requests with git-linearize'
author: "Gustav Westling"
inputs:
token:
required: true
description: GitHub token. The standard GITHUB_TOKEN will do just fine.
runs:
using: "composite"
steps:
# 👍
- name: React to comment
uses: dkershner6/reaction-action@v1
with:
token: ${{ inputs.token }}
# Installation steps
- name: Install lucky_commit
uses: baptiste0928/cargo-install@v1
with:
crate: lucky_commit
args: "--locked --no-default-features"
- name: Install git-linearize
shell: bash
run: |
mkdir -p ~/.bin
curl -o ~/.bin/git-linearize https://raw.githubusercontent.com/zegl/extremely-linear/main/git-linearize
chmod +x ~/.bin/git-linearize
# Clone and fetch PR metadata
- name: Get PR SHA
id: sha
uses: actions/github-script@v6
with:
script: |
const { owner, repo, number } = context.issue;
const pr = await github.rest.pulls.get({
owner,
repo,
pull_number: number,
});
return {
pr_number: number,
pr_head_sha: pr.data.head.sha,
pr_base_ref: pr.data.base.ref,
pr_base_sha: pr.data.base.sha
}
- uses: actions/checkout@v3
with:
fetch-depth: "0"
ref: ${{ fromJSON(steps.sha.outputs.result).pr_head_sha }}
# Rebase, linearize, and "merge"!
- name: "Run git-linearize"
shell: bash
run: |
git fetch origin ${{ fromJSON(steps.sha.outputs.result).pr_base_ref }}
git config user.name github-actions
git config user.email github-actions@github.com
git checkout -b working-branch
git rebase origin/${{ fromJSON(steps.sha.outputs.result).pr_base_ref }}
~/.bin/git-linearize -v
git push -u origin HEAD:${{ fromJSON(steps.sha.outputs.result).pr_base_ref }}
echo "PUSHED_REF=$(git rev-parse HEAD)" >> $GITHUB_ENV
- name: Comment and close PR
uses: peter-evans/close-pull@v2
with:
pull-request-number: ${{ fromJSON(steps.sha.outputs.result).pr_number }}
comment: Landed as ${{ env.PUSHED_REF }}