-
Notifications
You must be signed in to change notification settings - Fork 115
169 lines (152 loc) · 6.35 KB
/
auto_cherry_pick_merged.yaml
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
### The workflow for retrying/rerunning the merged PRs AutoCherryPick which was missed/failed due to any circumstances
name: Retry Merged PRs AutoCherryPick
# Run on workflow dispatch from CI
on:
workflow_dispatch:
inputs:
parent_pr:
type: string
description: |
An identifier for parent PR to retry it's cherrypick
e.g 12314
branches:
type: string
description: |
Comma separated list of branches where the master PR to be cherrypicked.
e.g: 6.15.z, 6.16.z
env:
number: ${{ github.event.inputs.parent_pr }}
is_dependabot_pr: ''
jobs:
get-parentPR-details:
runs-on: ubuntu-latest
outputs:
labels: ${{ steps.parentPR.outputs.labels }}
state: ${{ steps.parentPR.outputs.state }}
base_ref: ${{ steps.parentPR.outputs.base_ref }}
assignee: ${{ steps.parentPR.outputs.assignee }}
title: ${{ steps.parentPR.outputs.title }}
prt_comment: ${{ steps.fc.outputs.comment-body }}
steps:
- name: Find parent PR details
id: parentPR
uses: actions/github-script@v7
with:
github-token: ${{ secrets.CHERRYPICK_PAT }}
script: |
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: ${{ env.number }},
});
core.setOutput('labels', pr.labels);
core.setOutput('state', pr.state);
core.setOutput('base_ref', pr.base.ref);
core.setOutput('assignee', pr.assignee.login);
core.setOutput('title', pr.title);
- name: Find & Save last PRT comment of Parent PR
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ env.number }}
body-includes: "trigger: test-robottelo"
direction: last
- name: Print PR details
run: |
echo "Labels are ${{ steps.parentPR.outputs.labels }}"
echo "State is ${{ steps.parentPR.outputs.state }}"
echo "Base Ref is ${{ steps.parentPR.outputs.base_ref }}"
echo "Assignee is ${{ steps.parentPR.outputs.assignee }}"
echo "Title is ${{ steps.parentPR.outputs.title }}"
arrayconversion:
needs: get-parentPR-details
if: ${{ needs.get-parentPR-details.outputs.state }} == closed
runs-on: ubuntu-latest
outputs:
branches: ${{ steps.conversion.outputs.branches }}
steps:
- name: Convert String to List
id: conversion
uses: actions/github-script@v7
with:
script: |
const branches = "${{ github.event.inputs.branches }}";
const branchesArray = branches.includes(',') ? branches.split(',').map(item => item.trim()) : [branches.trim()];
core.setOutput('branches', JSON.stringify(branchesArray));
run-the-branch-matrix:
name: Auto Cherry Pick to labeled branches
runs-on: ubuntu-latest
needs: [arrayconversion, get-parentPR-details]
if: ${{ needs.arrayconversion.outputs.branches != '' }}
strategy:
matrix:
branch: ${{ fromJson(needs.arrayconversion.outputs.branches) }}
steps:
- name: Tell me the branch name
run: |
echo "Branch is: ${{ matrix.branch }}"
# Needed to avoid out-of-memory error
- name: Set Swap Space
uses: pierotofy/set-swap-space@master
with:
swap-size-gb: 10
## Robottelo Repo Checkout
- uses: actions/checkout@v4
if: ${{ startsWith(matrix.branch, '6.') && matrix.branch != needs.get-parentPR-details.outputs.base_ref }}
with:
fetch-depth: 0
## Set env var for dependencies label PR
- name: Set env var is_dependabot_pr to `dependencies` to set the label
if: contains(needs.get-parentPR-details.outputs.labels.*.name, 'dependencies')
run: |
echo "is_dependabot_pr=dependencies" >> $GITHUB_ENV
## CherryPicking and AutoMerging
- name: Cherrypicking to zStream branch
id: cherrypick
if: ${{ startsWith(matrix.branch, '6.') && matrix.branch != needs.get-parentPR-details.outputs.base_ref }}
uses: jyejare/github-cherry-pick-action@main
with:
token: ${{ secrets.CHERRYPICK_PAT }}
pull_number: ${{ env.number }}
branch: ${{ matrix.branch }}
labels: |
Auto_Cherry_Picked
${{ matrix.branch }}
No-CherryPick
${{ env.is_dependabot_pr }}
assignees: ${{ needs.get-parentPR-details.outputs.assignee }}
- name: Add Parent PR's PRT comment to Auto_Cherry_Picked PR's
id: add-parent-prt-comment
if: ${{ always() && needs.get-parentPR-details.outputs.prt_comment != '' && steps.cherrypick.outcome == 'success' }}
uses: thollander/actions-comment-pull-request@v3
with:
message: |
${{ needs.get-parentPR-details.outputs.prt_comment }}
pr-number: ${{ steps.cherrypick.outputs.number }}
github-token: ${{ secrets.CHERRYPICK_PAT }}
- name: is autoMerging enabled for Auto CherryPicked PRs ?
if: ${{ always() && steps.cherrypick.outcome == 'success' && contains(needs.get-parentPR-details.outputs.labels.*.name, 'AutoMerge_Cherry_Picked') }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.CHERRYPICK_PAT }}
script: |
github.rest.issues.addLabels({
issue_number: ${{ steps.cherrypick.outputs.number }},
owner: context.repo.owner,
repo: context.repo.repo,
labels: ["AutoMerge_Cherry_Picked"]
})
- name: Check if cherrypick pr is created
id: search_pr
if: always()
run: |
PR_TITLE="[${{ matrix.branch }}] ${{ needs.get-parentPR-details.outputs.title }}"
API_URL="https://api.github.com/repos/${{ github.repository }}/pulls?state=open"
PR_SEARCH_RESULT=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "$API_URL" | jq --arg title "$PR_TITLE" '.[] | select(.title == $title)')
if [ -n "$PR_SEARCH_RESULT" ]; then
echo "pr_found=true" >> $GITHUB_OUTPUT
echo "PR is Found with title $PR_TITLE"
else
echo "pr_found=false" >> $GITHUB_OUTPUT
echo "PR is not Found with title $PR_TITLE"
fi