forked from fybrik/fybrik
-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (77 loc) · 3.36 KB
/
cherry-pick-command.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: cherry-pick-command
on:
workflow_dispatch:
inputs:
comment-id:
description: "The comment-id of the slash command"
required: false
pull-request:
description: "The PR number to cherry pick from"
required: true
branch:
description: "The branch name to cherry pick to"
required: true
jobs:
cherry-pick:
runs-on: ubuntu-latest
steps:
- name: Generate bot token
uses: tibdex/github-app-token@v1
id: generate-token
with:
app_id: ${{ secrets.FYBRIK_BOT_APP_ID }}
private_key: ${{ secrets.FYBRIK_BOT_PRIVATE_KEY }}
repository: ${{ github.repository }}
- uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.branch }}
token: ${{ steps.generate-token.outputs.token }}
- name: Setup git
run: |
git config user.name "GitHub Actions Bot"
git config user.email "[email protected]"
- name: Create Pull Request branch name
id: temp_branch
run: echo "::set-output name=branch::cherry-pick-${{ github.event.inputs.pull-request }}-${{ github.event.inputs.branch }}"
- name: Get Pull Request branch
run: git fetch origin pull/${{ github.event.inputs.pull-request }}/head:${{ steps.temp_branch.outputs.branch }}
- name: Cherry-pick commits
shell: pwsh
run: |
$pullId = "${{ github.event.inputs.pull-request }}"
$url = $("${{ github.event.repository.pulls_url}}".Replace("{/number}", "/$pullId")) + "/commits"
$headers = @{ "Authorization" = "token ${{ secrets.GITHUB_TOKEN }}"; "User-Agent" = "GitHub Actions Bot"; "Accept" = "application/vnd.github.v3+json" }
$response = Invoke-RestMethod -Uri $url -Headers $headers
$response | ForEach-Object {
git cherry-pick $_.sha
}
- name: Push
run: git push origin ${{ steps.temp_branch.outputs.branch }}
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ steps.generate-token.outputs.token }}
title: "cherry-pick from #${{ github.event.inputs.pull-request }} into ${{ github.event.inputs.branch }}"
body: "cherry-pick from #${{ github.event.inputs.pull-request }} into ${{ github.event.inputs.branch }}"
branch: ${{ steps.temp_branch.outputs.branch }}
delete-branch: true
- name: Add reaction
if: ${{ github.event.inputs.comment-id }}
uses: peter-evans/create-or-update-comment@v2
with:
token: ${{ steps.generate-token.outputs.token }}
repository: ${{ github.repository }}
issue-number: ${{ github.event.inputs.pull-request }}
comment-id: ${{ github.event.inputs.comment-id }}
reaction-type: hooray
- name: Add failure reaction
if: ${{ failure() && github.event.inputs.comment-id }}
uses: peter-evans/create-or-update-comment@v2
with:
token: ${{ steps.generate-token.outputs.token }}
repository: ${{ github.repository }}
issue-number: ${{ github.event.inputs.pull-request }}
comment-id: ${{ github.event.inputs.comment-id }}
reaction-type: "-1"
body: |
> Failed - see https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}