|
| 1 | +name: MergeApproved |
| 2 | +run-name: "Merge Approved for PR ${{github.event.number}}" |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + types: [labeled] |
| 6 | + |
| 7 | +env: |
| 8 | + PR_NUMBER: ${{ github.event.number }} |
| 9 | + BASE_BRANCH: ${{github.event.pull_request.base.ref}} |
| 10 | + MODULES_BLACKLIST: ${{ vars.GATETEST_MODULES_BLACKLIST }} ${{ vars.UNITTEST_MODULES_BLACKLIST }} |
| 11 | + FORCE: ${{ endsWith(github.event.label.name, '-force') }} |
| 12 | + |
| 13 | +jobs: |
| 14 | + IdentifyBranches: |
| 15 | + if: contains(fromJSON(vars.MERGE_APPROVED_LABELS), github.event.label.name) |
| 16 | + outputs: |
| 17 | + branches: ${{ steps.getbranches.outputs.branches }} |
| 18 | + all_branches: ${{ steps.checkbranches.outputs.all_branches }} |
| 19 | + branch_count: ${{ steps.getbranches.outputs.branch_count }} |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - name: Clean up labels |
| 23 | + env: |
| 24 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 25 | + run: | |
| 26 | + gh pr edit --repo ${{github.repository}} \ |
| 27 | + --remove-label ${{github.event.label.name}} \ |
| 28 | + --remove-label ${{vars.PRE_MERGE_CHECKS_PASSED_LABEL}} \ |
| 29 | + --remove-label ${{vars.PRE_MERGE_CHECKS_FAILED_LABEL}} \ |
| 30 | + --remove-label ${{vars.PRE_MERGE_GATES_PASSED_LABEL}} \ |
| 31 | + --remove-label ${{vars.PRE_MERGE_GATES_FAILED_LABEL}} \ |
| 32 | + --remove-label ${{vars.PRE_MERGE_TESTING_IN_PROGRESS}} \ |
| 33 | + ${{env.PR_NUMBER}} || : |
| 34 | +
|
| 35 | + - name: Get cherry-pick branches |
| 36 | + uses: asterisk/asterisk-ci-actions/GetCherryPickBranchesFromPR@main |
| 37 | + id: getbranches |
| 38 | + with: |
| 39 | + repo: ${{github.repository}} |
| 40 | + pr_number: ${{env.PR_NUMBER}} |
| 41 | + cherry_pick_regex: ${{vars.CHERRY_PICK_REGEX}} |
| 42 | + github_token: ${{secrets.GITHUB_TOKEN}} |
| 43 | + |
| 44 | + - name: Check Branch Count |
| 45 | + id: checkbranches |
| 46 | + env: |
| 47 | + BRANCH_COUNT: ${{ steps.getbranches.outputs.branch_count }} |
| 48 | + BRANCHES: ${{ steps.getbranches.outputs.branches }} |
| 49 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 50 | + run: | |
| 51 | + gh pr edit --repo ${{github.repository}} \ |
| 52 | + --add-label ${{vars.PRE_MERGE_TESTING_IN_PROGRESS}} \ |
| 53 | + ${{env.PR_NUMBER}} || : |
| 54 | + all_branches=$(echo "$BRANCHES" | jq -c "[ \"$BASE_BRANCH\" ] + .") |
| 55 | + echo "all_branches=${all_branches}" >>${GITHUB_OUTPUT} |
| 56 | +
|
| 57 | + - name: Pre Check Cherry-Picks |
| 58 | + if: ${{ steps.getbranches.outputs.branch_count > 0 }} |
| 59 | + uses: asterisk/asterisk-ci-actions/CherryPick@main |
| 60 | + with: |
| 61 | + repo: ${{github.repository}} |
| 62 | + pr_number: ${{env.PR_NUMBER}} |
| 63 | + branches: ${{steps.getbranches.outputs.branches}} |
| 64 | + github_token: ${{secrets.GITHUB_TOKEN}} |
| 65 | + push: false |
| 66 | + |
| 67 | + PreMergeUnitTestMatrix: |
| 68 | + needs: [ IdentifyBranches ] |
| 69 | + if: success() |
| 70 | + continue-on-error: false |
| 71 | + strategy: |
| 72 | + fail-fast: false |
| 73 | + matrix: |
| 74 | + branch: ${{ fromJSON(needs.IdentifyBranches.outputs.all_branches) }} |
| 75 | + runs-on: ubuntu-latest |
| 76 | + steps: |
| 77 | + - name: Run Unit Tests for branch ${{matrix.branch}} |
| 78 | + uses: asterisk/asterisk-ci-actions/TestsuiteUnitComposite@main |
| 79 | + with: |
| 80 | + testsuite_repo: ${{github.repository}} |
| 81 | + asterisk_repo: ${{vars.ASTERISK_REPO}} |
| 82 | + pr_number: ${{env.PR_NUMBER}} |
| 83 | + base_branch: ${{matrix.branch}} |
| 84 | + is_cherry_pick: true |
| 85 | + modules_blacklist: ${{env.MODULES_BLACKLIST}} |
| 86 | + github_token: ${{secrets.GITHUB_TOKEN}} |
| 87 | + unittest_command: ${{vars.UNITTEST_COMMAND}} |
| 88 | + |
| 89 | + PreMergeUnitTests: |
| 90 | + needs: [ IdentifyBranches, PreMergeUnitTestMatrix ] |
| 91 | + runs-on: ubuntu-latest |
| 92 | + steps: |
| 93 | + - name: Check unit test matrix status |
| 94 | + env: |
| 95 | + RESULT: ${{needs.PreMergeUnitTestMatrix.result}} |
| 96 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 97 | + run: | |
| 98 | + case $RESULT in |
| 99 | + success) |
| 100 | + gh pr edit --repo ${{github.repository}} \ |
| 101 | + --remove-label ${{vars.PRE_MERGE_TESTING_IN_PROGRESS}} \ |
| 102 | + --add-label ${{vars.PRE_MERGE_CHECKS_PASSED_LABEL}} \ |
| 103 | + ${{env.PR_NUMBER}} || : |
| 104 | + echo "::notice::All tests passed" |
| 105 | + exit 0 |
| 106 | + ;; |
| 107 | + skipped) |
| 108 | + gh pr edit --repo ${{github.repository}} \ |
| 109 | + --remove-label ${{vars.PRE_MERGE_TESTING_IN_PROGRESS}} \ |
| 110 | + --add-label ${{vars.PRE_MERGE_CHECKS_FAILED_LABEL}} \ |
| 111 | + ${{env.PR_NUMBER}} || : |
| 112 | + echo "::notice::Unit tests were skipped because of an earlier failure" |
| 113 | + exit 1 |
| 114 | + ;; |
| 115 | + *) |
| 116 | + gh pr edit --repo ${{github.repository}} \ |
| 117 | + --remove-label ${{vars.PRE_MERGE_TESTING_IN_PROGRESS}} \ |
| 118 | + --add-label ${{vars.PRE_MERGE_CHECKS_FAILED_LABEL}} \ |
| 119 | + ${{env.PR_NUMBER}} || : |
| 120 | + echo "::error::One or more tests failed ($RESULT)" |
| 121 | + exit 1 |
| 122 | + esac |
| 123 | +
|
| 124 | + MergeAndCherryPick: |
| 125 | + needs: [ IdentifyBranches, PreMergeUnitTests ] |
| 126 | + if: success() |
| 127 | + concurrency: |
| 128 | + group: MergeAndCherryPick |
| 129 | + cancel-in-progress: false |
| 130 | + runs-on: ubuntu-latest |
| 131 | + steps: |
| 132 | + - name: Start Merge |
| 133 | + env: |
| 134 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 135 | + run: | |
| 136 | + gh pr edit --repo ${{github.repository}} \ |
| 137 | + --add-label ${{vars.MERGE_IN_PROGRESS_LABEL}} \ |
| 138 | + ${{env.PR_NUMBER}} || : |
| 139 | +
|
| 140 | + - name: Get Token needed to push cherry-picks |
| 141 | + id: get_workflow_token |
| 142 | + uses: peter-murray/workflow-application-token-action@v1 |
| 143 | + with: |
| 144 | + application_id: ${{secrets.ASTERISK_ORG_ACCESS_APP_ID}} |
| 145 | + application_private_key: ${{secrets.ASTERISK_ORG_ACCESS_APP_PRIV_KEY}} |
| 146 | + organization: asterisk |
| 147 | + |
| 148 | + - name: Merge and Cherry Pick to ${{needs.IdentifyBranches.outputs.branches}} |
| 149 | + id: mergecp |
| 150 | + uses: asterisk/asterisk-ci-actions/MergeAndCherryPickComposite@main |
| 151 | + with: |
| 152 | + repo: ${{github.repository}} |
| 153 | + pr_number: ${{env.PR_NUMBER}} |
| 154 | + branches: ${{needs.IdentifyBranches.outputs.branches}} |
| 155 | + force: ${{env.FORCE}} |
| 156 | + github_token: ${{steps.get_workflow_token.outputs.token}} |
| 157 | + |
| 158 | + - name: Merge Cleanup |
| 159 | + if: always() |
| 160 | + env: |
| 161 | + RESULT: ${{ steps.mergecp.outcome }} |
| 162 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 163 | + BRANCH_COUNT: ${{ needs.IdentifyBranches.outputs.branch_count }} |
| 164 | + BRANCHES: ${{ needs.IdentifyBranches.outputs.branches }} |
| 165 | + |
| 166 | + run: | |
| 167 | + case $RESULT in |
| 168 | + success) |
| 169 | + gh pr edit --repo ${{github.repository}} \ |
| 170 | + --remove-label ${{vars.MERGE_IN_PROGRESS_LABEL}} \ |
| 171 | + ${{env.PR_NUMBER}} || : |
| 172 | + if [ $BRANCH_COUNT -eq 0 ] ; then |
| 173 | + gh pr comment --repo ${{github.repository}} \ |
| 174 | + -b "Successfully merged to branch $BASE_BRANCH." \ |
| 175 | + ${{env.PR_NUMBER}} || : |
| 176 | + else |
| 177 | + gh pr comment --repo ${{github.repository}} \ |
| 178 | + -b "Successfully merged to branch $BASE_BRANCH and cherry-picked to $BRANCHES" \ |
| 179 | + ${{env.PR_NUMBER}} || : |
| 180 | + fi |
| 181 | + exit 0 |
| 182 | + ;; |
| 183 | + failure) |
| 184 | + gh pr edit --repo ${{github.repository}} \ |
| 185 | + --remove-label ${{vars.MERGE_IN_PROGRESS_LABEL}} \ |
| 186 | + --add-label ${{vars.MERGE_FAILED_LABEL}} \ |
| 187 | + ${{env.PR_NUMBER}} || : |
| 188 | + exit 1 |
| 189 | + ;; |
| 190 | + *) |
| 191 | + esac |
0 commit comments