forked from appsmithorg/appsmith
-
Notifications
You must be signed in to change notification settings - Fork 2
132 lines (118 loc) · 7.26 KB
/
ci-merge-check.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
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
on:
#This workflow is only triggered by the ok to test command dispatch
repository_dispatch:
types: [ ci-merge-check-command ]
jobs:
ci-merge-check:
runs-on: ubuntu-latest
steps:
# This step creates a comment on the PR with a link to this workflow run.
- name: Add a comment on the PR with link to workflow run
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ github.event.client_payload.pull_request.number }}
body: |
Merge check is running at: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}>
PR: ${{ github.event.client_payload.pull_request.number }}
- name: Find the latest workflow run comment
uses: peter-evans/find-comment@v2
id: find-comment
with:
issue-number: ${{ github.event.client_payload.pull_request.number }}
body-includes: 'Appsmith External Integration Test Workflow'
comment-author: github-actions[bot]
direction: last
- name: Get the workflow run_id
id: workflow
run: |
echo "run_id=$(echo '${{ steps.find-comment.outputs.comment-body }}' | grep -o 'runs/[0-9]\+' | cut -d/ -f2)" >> $GITHUB_OUTPUT
- name: Get ci-test-result status from the run_id
id: ci_test_result_status
run: |
run_status=`curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{github.repository}}/actions/runs/${{steps.workflow.outputs.run_id}}/jobs?per_page=100`
echo "ci_test_result=`echo $run_status | jq -r '[ .jobs[] | select (select(.name | contains("ci-test-result")) | .conclusion | contains("failure"))] | length'`" >> $GITHUB_OUTPUT
echo "ci_test_status=`echo $run_status | jq -r '[ .jobs[] | select (select(.name | contains("ci-test ")) | .conclusion | contains("failure"))] | length'`" >> $GITHUB_OUTPUT
echo "perf_test_status=`echo $run_status | jq -r '[ .jobs[] | select (select(.name | contains("perf-test")) | .conclusion | contains("failure"))] | length'`" >> $GITHUB_OUTPUT
- name: get status-checks from pr
id: pr_status_check
run: |
status_link="https://api.github.com/repos/${{github.repository}}/statuses/${{github.event.client_payload.pull_request.head.sha}}"
echo "merge_freeze_status=`curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" $status_link | jq -r '[.[] | select( select( .context | contains("mergefreeze")) | .state | contains("success") | not)] | length'`" >> $GITHUB_OUTPUT
- name: get status-checks from check suite
id: suite_status_check
run: |
check_runs_link="https://api.github.com/repos/${{github.repository}}/commits/${{github.event.client_payload.pull_request.head.sha}}/check-runs"
check_run_result=`curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" $check_runs_link`
echo "test_plan_approval_status=`echo $check_run_result | jq -r '[[.check_runs[]|select(.name | contains("Test Plan Approved"))][0] | select( .conclusion | contains("success") | not)] | length'`" >> $GITHUB_OUTPUT
echo "ci_test_available=`echo $check_run_result | jq -r '[.check_runs[] | select(.name | contains("ci-test-result"))] | length'`" >> $GITHUB_OUTPUT
- name: get pr approval status
id: pr_approval_status
run: |
pr_reviews_link="https://api.github.com/repos/${{github.repository}}/pulls/${{github.event.client_payload.pull_request.number}}/reviews"
pr_reviews=`curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" $pr_reviews_link`
echo "approved_pr_reviews=`echo $pr_reviews | jq -r 'if length > 0 then [.[]|select(.state | contains ("APPROVED"))]|length else 0 end'`" >> $GITHUB_OUTPUT
- name: Verify all the checks
id: verify_checks
run: |
if [ ${{ steps.ci_test_result_status.outputs.ci_test_result }} == 1 ]; then
if [ ${{ steps.ci_test_result_status.outputs.ci_test_status }} -gt 0 ]; then
echo "msg=Looks like there are some Cypress failures. Can't Merge." >> $GITHUB_OUTPUT
exit 1
elif [ ${{ steps.ci_test_result_status.outputs.perf_test_status }} -gt 0 ]; then
echo "msg=Looks like Perf-Tests failed. Contact perf team to get their confirmation. Can't Merge." >> $GITHUB_OUTPUT
exit 1
fi
elif [ ${{ steps.suite_status_check.outputs.ci_test_available }} == 0 ]; then
echo "msg=Looks like you forgot to run /ok-to-test on the latest commit. Can't Merge." >> $GITHUB_OUTPUT
exit 1
elif [ ${{ steps.pr_status_check.outputs.merge_freeze_status }} != 0 ]; then
echo "msg=There's merge freeze. Can't Merge, please try after merge-freeze is lifted." >> $GITHUB_OUTPUT
exit 1
elif [ ${{ steps.suite_status_check.outputs.test_plan_approval_status }} == 1 ]; then
echo "msg=Either get 'Test Plan Approved' or 'skip-testPlan' added and try again!" >> $GITHUB_OUTPUT
exit 1
elif [ ${{ steps.pr_approval_status.outputs.approved_pr_reviews }} == 0 ]; then
echo "msg=Minimum 1 approval needed to merge this PR, please get it reviewed by your peer and try again!" >> $GITHUB_OUTPUT
exit 1
elif [ ${{ steps.suite_status_check.outputs.test_plan_approval_status }} == 0 ]; then
echo "msg=Hurray!🎉 Proceeding to Merge!!!" >> $GITHUB_OUTPUT
exit 0
else
echo "msg=Some checks have failed. Can't merge." >> $GITHUB_OUTPUT
exit 1
fi
- name: Add a comment on the PR after all checks
if: always()
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ github.event.client_payload.pull_request.number }}
body: |
${{steps.verify_checks.outputs.msg}}
- name: Auto merge if above checks are success and have 1 approval
if: success()
id: automerge
uses: juliangruber/merge-pull-request-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
number: ${{ github.event.client_payload.pull_request.number }}
method: merge
repo: ${{ github.repository }}
- run : |
echo ${{ steps.automerge.outputs }}
# - name: Add comment once merge is success-full
# if: steps.automerge.outputs.mergeResult == 'merged'
# uses: peter-evans/create-or-update-comment@v2
# with:
# issue-number: ${{ github.event.client_payload.pull_request.number }}
# body: |
# Pull request ${{ steps.automerge.outputs.pullRequestNumber }} Auto-merged!
# - name: Comment if it is not merged
# if: steps.automerge.outputs.mergeResult != 'merged'
# uses: peter-evans/create-or-update-comment@v2
# with:
# issue-number: ${{ github.event.client_payload.pull_request.number }}
# body: |
# Auto merge has been failed. Probably for the following reasons:
# 2. There might be some merge conflicts.
# 3. There are some failed checks.
# Please ask someone with merge access to review and merge.