-
Notifications
You must be signed in to change notification settings - Fork 16
70 lines (67 loc) · 2.73 KB
/
prs_create-cherry-pick-pr.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
name: Cherry pick onto target branches
on:
pull_request_target:
branches:
- 'v*.x'
- 'master'
types: ['closed']
workflow_call:
permissions: {}
jobs:
detect_cherry_pick_targets:
runs-on: ubuntu-latest
name: Detect cherry-pick targets
permissions:
pull-requests: write
contents: write
if: ${{ contains(github.event.pull_request.labels.*.name, 'needs cherry-pick') && github.event.pull_request.merged == true }}
outputs:
targetBranches: ${{ steps.detect.outputs.TARGET_BRANCHES }}
reviewers: ${{ steps.detect.outputs.REVIEWERS }}
labels: ${{ steps.detect.outputs.LABELS }}
steps:
- name: Check out mui-public repo
id: checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
# Check this repository out, otherwise the script won't be available,
# as it otherwise checks out the repository where the workflow caller is located
repository: mui/mui-public
- name: Detect target
id: detect
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const script = require('./.github/workflows/scripts/prs/detectTargetBranch.js');
await script({core, github, context});
open_cherry_pick_pr:
runs-on: ubuntu-latest
name: Open cherry-pick PR with target branch
if: needs.detect_cherry_pick_targets.outputs.targetBranches != ''
strategy:
matrix:
branch: ${{ fromJSON(needs.detect_cherry_pick_targets.outputs.targetBranches) }}
permissions:
pull-requests: write
contents: write
needs: detect_cherry_pick_targets
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: Cherry pick and create the new PR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: carloscastrojumo/github-cherry-pick-action@503773289f4a459069c832dc628826685b75b4b3 # v1.0.10
with:
# the action will run for each value in matrix.branch
branch: ${{ matrix.branch }}
body: 'Cherry-pick of #{old_pull_request_id}'
cherry-pick-branch: ${{ format('cherry-pick-{0}', github.event.number) }}
title: '{old_title} (@${{ github.event.pull_request.user.login }})'
# assigning the original reviewers to the new PR
reviewers: ${{ needs.detect_cherry_pick_targets.outputs.reviewers }}
# instead of inheriting labels (including target branch label, etc.), we filter and set the labels explicitly
inherit_labels: false
labels: ${{ needs.detect_cherry_pick_targets.outputs.labels }}