Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for auto-merge in nailgun repo #878

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions .github/workflows/auto_cherry_pick.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,25 @@ env:

jobs:

# Pre-Requisites for Auto Cherrypicking
find-the-parent-prt-comment:
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@v2
id: fc
with:
issue-number: ${{ env.number }}
body-includes: "trigger: test-robottelo"

# Auto CherryPicking and Failure Recording
auto-cherry-pick:
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CherryPick')
name: Auto Cherry Pick to labeled branches
needs: find-the-parent-prt-comment
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -40,10 +55,32 @@ jobs:
branch: ${{ matrix.label }}
labels: |
Auto_Cherry_Picked
No-CherryPick
${{ matrix.label }}
No-CherryPick
assignees: ${{ env.assignee }}

- name: Add Parent PR's PRT comment to Auto_Cherry_Picked PR's
id: add-parent-prt-comment
if: ${{ always() && steps.cherrypick.outcome == 'success' }}
uses: mshick/add-pr-comment@v2
with:
issue: ${{ steps.cherrypick.outputs.number }}
message: ${{ needs.find-the-parent-prt-comment.outputs.prt_comment }}
repo-token: ${{ secrets.CHERRYPICK_PAT }}

- name: is autoMerging enabled for Auto CherryPicked PRs ?
if: ${{ always() && steps.cherrypick.outcome == 'success' && contains(github.event.pull_request.labels.*.name, 'AutoMerge_Cherry_Picked') }}
uses: actions/github-script@v6
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"]
})
## Failure Logging to issues and GChat Group
- name: Create Github issue on cherrypick failure
id: create-issue
Expand All @@ -56,7 +93,7 @@ jobs:
#### 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 }})
- [Parent Pull Request](https://github.com/${{ github.repository }}/pull/${{ github.event.number }})
labels: Failed_AutoCherryPick,${{ matrix.label }}
assignees: ${{ env.assignee }}
- name: Send Google Chat notification on cherrypick failure
Expand Down
123 changes: 123 additions & 0 deletions .github/workflows/automerge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: automerge auto-cherry-picked pr's
on:
pull_request_target:
types:
- labeled
- unlabeled
- edited
- ready_for_review
branches-ignore:
- master
pull_request_review:
types:
- submitted
branches-ignore:
- master
check_suite:
types:
- completed
branches-ignore:
- master


jobs:
automerge:
name: Automerge auto-cherry-picked pr
jyejare marked this conversation as resolved.
Show resolved Hide resolved
if: contains(github.event.pull_request.labels.*.name, 'AutoMerge_Cherry_Picked') && contains(github.event.pull_request.labels.*.name, 'Auto_Cherry_Picked')
runs-on: ubuntu-latest
steps:
- id: find-prt-comment
name: Find the prt comment
uses: peter-evans/find-comment@v2
with:
issue-number: ${{ github.event.number }}
body-includes: "trigger: test-robottelo"
direction: last

- name: Fail automerge if PRT was not initiated
if: steps.find-prt-comment.outputs.comment-body == ''
run: |
echo "::error PRT comment not added the PR"

- name: Wait for PRT checks to get initiated
run: |
echo "Waiting for ~ 10 mins, PRT to be initiated." && sleep 600

- name: Wait for other status checks to Pass
id: waitforstatuschecks
uses: lewagon/[email protected]
with:
ref: ${{ github.head_ref }}
repo-token: ${{ secrets.CHERRYPICK_PAT }}
wait-interval: 60
running-workflow-name: 'Automerge auto-cherry-picked pr'
allowed-conclusions: success,skipped

- name: is PRT check Passed ?
run: |
api_endpoint="https://api.github.com/repos/${{github.repository}}/statuses/${{ github.head_ref }}"

function get_status() {
curl -s "$api_endpoint" | jq '[.[] | .state] | .[0]'
}

function get_context() {
curl -s "$api_endpoint" | jq '[.[] | .context] | .[0]'
}

statuses_length=$(curl -s $api_endpoint | jq 'length')
if [ $statuses_length -eq 0 ]; then
echo "PRT failed to start ! Stopping."
exit 1
fi

status=$(get_status)
context=$(get_context)

if [ "$context" != "Robottelo-Runner" ]; then
echo "::error Failed to get Robottelo-Runner status"
exit 1
fi

counter=0
echo "Waiting for PRT to complete....."
while [ "$status" != "success" ] && [ "$status" != "failure" ]; do
if [ $counter -gt 20 ]; then
echo "PRT Timeout"
exit 1
fi
sleep 300
status=$(get_status)
echo "Robottelo-Runner : $status"
counter=$((counter+1))
done

if [ "$status" == "success" ]; then
echo "PRT Passed Successfully!"
else
echo "Robottelo-Runner : $status"
echo "::error PRT failed"
exit 1
fi


- id: automerge
name: Auto merge of cherry-picked PRs.
uses: "pascalgn/[email protected]"
if: steps.waitforstatuschecks.outputs.status == 'success'
env:
GITHUB_TOKEN: "${{ secrets.CHERRYPICK_PAT }}"
MERGE_LABELS: "AutoMerge_Cherry_Picked, Auto_Cherry_Picked"
MERGE_METHOD: "squash"
MERGE_RETRIES: 5
MERGE_RETRY_SLEEP: 900000
BASE_BRANCHES: "master" # avoid automerge branch

- name: Auto Merge Status
run: |
if [ "${{ steps.automerge.outputs.mergeResult }}" == 'merged' ]; then
echo "Pull request ${{ steps.automerge.outputs.pullRequestNumber }} is Auto Merged !"
else
echo "::error Auto Merge for Pull request failed !"
exit 1
fi