Skip to content

Commit

Permalink
The ACP is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
jyejare committed Jun 25, 2024
1 parent 8f4aaca commit e01c2d4
Showing 1 changed file with 105 additions and 118 deletions.
223 changes: 105 additions & 118 deletions .github/workflows/auto_cherry_pick_merged.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@ on:
type: string
description: Comma separated list of branches where the master PR to be cherrypicked


env:
number: ${{ github.event.inputs.parentPR }}
to_branches: ${{ github.event.inputs.branches }}
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
Expand All @@ -39,9 +42,17 @@ jobs:
core.setOutput('labels', pr.labels);
core.setOutput('state', pr.state);
core.setOutput('base_ref', pr.base.ref);
core.setOutput('assignee', pr.assignee);
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 }}"
Expand All @@ -51,6 +62,8 @@ jobs:
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 }}
Expand All @@ -64,10 +77,12 @@ jobs:
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
needs: [arrayconversion, get-parentPR-details]
if: ${{ needs.arrayconversion.outputs.branches != '' }}
strategy:
matrix:
branch: ${{ fromJson(needs.arrayconversion.outputs.branches) }}
Expand All @@ -76,117 +91,89 @@ jobs:
run: |
echo "Branch is: ${{ matrix.branch }}"
# # Pre-Requisites for Auto Cherrypicking
# find-the-parent-prt-comment:
# if: steps.parentPR.outputs.state == close
# name: Find & Save last PRT comment of Parent PR
# runs-on: ubuntu-latest
# outputs:
# prt_comment: ${{steps.fc.outputs.comment-body}}
# steps:
# - name: Find Comment
# uses: peter-evans/find-comment@v3
# id: fc
# with:
# issue-number: ${{ env.number }}
# body-includes: "trigger: test-robottelo"
# direction: last
#
# # Auto CherryPicking and Failure Recording
# auto-cherry-pick:
# if: steps.parentPR.outputs.state == close
# name: Auto Cherry Pick to labeled branches
# needs: find-the-parent-prt-comment
# runs-on: ubuntu-latest
# strategy:
# matrix:
# label: ${{ env.to_branches }}
#
# steps:
# # 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.label, '6.') && matrix.label != steps.parentPR.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(steps.parentPR.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.label, '6.') && matrix.label != steps.parentPR.outputs.base_ref }}
# uses: jyejare/github-cherry-pick-action@main
# with:
# token: ${{ secrets.CHERRYPICK_PAT }}
# branch: ${{ matrix.label }}
# labels: |
# Auto_Cherry_Picked
# ${{ matrix.label }}
# No-CherryPick
# ${{ env.is_dependabot_pr }}
# assignees: ${{ steps.parentPR.outputs.assignee }}
#
# - name: Add Parent PR's PRT comment to Auto_Cherry_Picked PR's
# id: add-parent-prt-comment
# if: ${{ always() && needs.find-the-parent-prt-comment.outputs.prt_comment != '' && steps.cherrypick.outcome == 'success' }}
# uses: thollander/actions-comment-pull-request@v2
# with:
# message: |
# ${{ needs.find-the-parent-prt-comment.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(steps.parentPR.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.label }}] ${{ steps.parentPR.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
#
# ## Failure Logging to issues
# - name: Create Github issue on cherrypick failure
# id: create-issue
# if: ${{ always() && steps.search_pr.outputs.pr_found == 'false' && steps.cherrypick.outcome != 'success' && startsWith(matrix.label, '6.') && matrix.label != steps.parentPR.outputs.base_ref }}
# uses: dacbd/create-issue-action@main
# with:
# token: ${{ secrets.CHERRYPICK_PAT }}
# title: "[Failed-AutoCherryPick] - ${{ steps.parentPR.outputs.title }}"
# body: |
# #### Auto-Cherry-Pick WorkFlow Failure:
# - To Branch: ${{ matrix.label }}
# - [Failed Cherrypick Action](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
# - [Parent Pull Request](https://github.com/${{ github.repository }}/pull/${{ env.number }})
# labels: Failed_AutoCherryPick,${{ matrix.label }}
# assignees: ${{ steps.parentPR.outputs.assignee }}
# 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 }}
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@v2
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
## Failure Logging to issues
- name: Create Github issue on cherrypick failure
id: create-issue
if: ${{ always() && steps.search_pr.outputs.pr_found == 'false' && steps.cherrypick.outcome != 'success' && startsWith(matrix.branch, '6.') && matrix.branch != needs.get-parentPR-details.outputs.base_ref }}
uses: dacbd/create-issue-action@main
with:
token: ${{ secrets.CHERRYPICK_PAT }}
title: "[Failed-AutoCherryPick] - ${{ needs.get-parentPR-details.outputs.title }}"
body: |
#### Auto-Cherry-Pick WorkFlow Failure:
- To Branch: ${{ matrix.branch }}
- [Failed Cherrypick Action](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
- [Parent Pull Request](https://github.com/${{ github.repository }}/pull/${{ env.number }})
labels: Failed_AutoCherryPick,${{ matrix.branch }}
assignees: ${{ needs.get-parentPR-details.outputs.assignee }}

0 comments on commit e01c2d4

Please sign in to comment.