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/appsmithorg/appsmith/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/appsmithorg/appsmith/statuses/${{github.event.client_payload.pull_request.head.sha}}" echo "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/appsmithorg/appsmith/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 "status1=`echo $check_run_result | jq -r '[[.check_runs[]|select(.name | contains("Test Plan Approved"))][0] | select( .conclusion | contains("success") | not)] | length'`" >> $GITHUB_OUTPUT echo "status2=`echo $check_run_result | jq -r '[.check_runs[] | select(.name | contains("ci-test-result"))] | length'`" >> $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-Test is failed. Contact perf team to get their confirmation. Can't Merge" >> $GITHUB_OUTPUT exit 1 fi elif [ ${{ steps.suite_status_check.outputs.status2 }} == 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.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.status1 }} == 1 ]; then echo "msg=Either get 'Test Plan Approved' or 'skip-testPlan' added and try again!" >> $GITHUB_OUTPUT exit 1 elif [ ${{ steps.suite_status_check.outputs.status1 }} == 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: "pascalgn/automerge-action@v0.15.5" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} PULL_REQUEST: ${{ github.event.client_payload.pull_request.number }} MERGE_REQUIRED_APPROVALS: 1 - 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: | Please try /ci-merge-check after at-least 1 peer approval. Can't merge this now.