]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
.github: Rework for merge approval
authorGeorge Joseph <gjoseph@sangoma.com>
Tue, 6 Jun 2023 12:08:34 +0000 (06:08 -0600)
committerGeorge Joseph <gjoseph@sangoma.com>
Thu, 8 Jun 2023 19:33:53 +0000 (13:33 -0600)
.github/workflows/CherryPickTest.yml
.github/workflows/MergeApproved.yml [new file with mode: 0644]
.github/workflows/PRMerged.yml
.github/workflows/PROpenedOrUpdated.yml

index 88c0bc4029fc71a8624165028fdb8713dfc44604..ffdf71ec9a81746d7b67c98fae4efef58fba919e 100644 (file)
@@ -21,11 +21,6 @@ jobs:
       branch_count: ${{ steps.getbranches.outputs.branch_count }}
     runs-on: ubuntu-latest
     steps:
-      - name: DumpEnvironment
-        uses: asterisk/asterisk-ci-actions/DumpEnvironmentAction@main
-        with:
-          action-vars: ${{toJSON(vars)}}
-
       - name: Remove Trigger Label, Add InProgress Label
         env:
           GH_TOKEN:          ${{ secrets.GITHUB_TOKEN }}
@@ -57,7 +52,7 @@ jobs:
           --add-label ${{vars.CHERRY_PICK_TESTING_IN_PROGRESS}} \
           ${{env.PR_NUMBER}} || :
 
-  AsteriskUnitTestMatrix:
+  CherryPickUnitTestMatrix:
     needs: [ IdentifyBranches ]
     if: ${{ needs.IdentifyBranches.outputs.branch_count > 0 && ( success() || failure() ) }}
     continue-on-error: false
@@ -78,14 +73,14 @@ jobs:
           github_token:      ${{secrets.GITHUB_TOKEN}}
           unittest_command:  ${{vars.UNITTEST_COMMAND}}
 
-  AsteriskUnitTests:
-    needs: [ IdentifyBranches, AsteriskUnitTestMatrix ]
+  CherryPickUnitTests:
+    needs: [ IdentifyBranches, CherryPickUnitTestMatrix ]
     if: ${{ needs.IdentifyBranches.outputs.branch_count > 0 && ( success() || failure() ) }}
     runs-on: ubuntu-latest
     steps:
       - name: Check unit test matrix status
         env:
-          RESULT:    ${{needs.AsteriskUnitTestMatrix.result}}
+          RESULT:    ${{needs.CherryPickUnitTestMatrix.result}}
           GH_TOKEN:  ${{ secrets.GITHUB_TOKEN }}
         run: |
           case $RESULT in
@@ -113,8 +108,8 @@ jobs:
               exit 1
           esac
 
-  AsteriskGateTestMatrix:
-    needs: [ IdentifyBranches, AsteriskUnitTests ]
+  CherryPickGateTestMatrix:
+    needs: [ IdentifyBranches, CherryPickUnitTests ]
     if: ${{ success() }}
     continue-on-error: false
     strategy:
@@ -138,14 +133,14 @@ jobs:
           gatetest_group:    ${{matrix.group}}
           gatetest_commands: ${{vars.GATETEST_COMMANDS}}
 
-  AsteriskGateTests:
-    needs: [ IdentifyBranches, AsteriskGateTestMatrix ]
+  CherryPickGateTests:
+    needs: [ IdentifyBranches, CherryPickGateTestMatrix ]
     if: ${{ success() || failure() }}
     runs-on: ubuntu-latest
     steps:
       - name: Check test matrix status
         env:
-          RESULT:    ${{needs.AsteriskGateTestMatrix.result}}
+          RESULT:    ${{needs.CherryPickGateTestMatrix.result}}
           GH_TOKEN:  ${{ secrets.GITHUB_TOKEN }}
         run: |
           gh pr edit --repo ${{github.repository}} \
diff --git a/.github/workflows/MergeApproved.yml b/.github/workflows/MergeApproved.yml
new file mode 100644 (file)
index 0000000..344c45b
--- /dev/null
@@ -0,0 +1,190 @@
+name: MergeApproved
+run-name: "Merge Approved for PR ${{github.event.number}}"
+on:
+  pull_request_target:
+    types: [labeled]
+
+env:
+  PR_NUMBER:          ${{ github.event.number }}
+  BASE_BRANCH:        ${{github.event.pull_request.base.ref}}
+  MODULES_BLACKLIST:  ${{ vars.GATETEST_MODULES_BLACKLIST }} ${{ vars.UNITTEST_MODULES_BLACKLIST }}
+  FORCE:              ${{ endsWith(github.event.label.name, '-force') }}
+
+jobs:
+  IdentifyBranches:
+    if: contains(fromJSON(vars.MERGE_APPROVED_LABELS), github.event.label.name)
+    outputs:
+      branches:     ${{ steps.getbranches.outputs.branches }}
+      all_branches: ${{ steps.checkbranches.outputs.all_branches }}
+      branch_count: ${{ steps.getbranches.outputs.branch_count }}
+    runs-on: ubuntu-latest
+    steps:
+      - name: Clean up labels
+        env:
+          GH_TOKEN:          ${{ secrets.GITHUB_TOKEN }}
+        run: |
+          gh pr edit --repo ${{github.repository}} \
+            --remove-label ${{github.event.label.name}} \
+            --remove-label ${{vars.PRE_MERGE_CHECKS_PASSED_LABEL}} \
+            --remove-label ${{vars.PRE_MERGE_CHECKS_FAILED_LABEL}} \
+            --remove-label ${{vars.PRE_MERGE_GATES_PASSED_LABEL}} \
+            --remove-label ${{vars.PRE_MERGE_GATES_FAILED_LABEL}} \
+            --remove-label ${{vars.PRE_MERGE_TESTING_IN_PROGRESS}} \
+            ${{env.PR_NUMBER}} || :
+
+      - name: Get cherry-pick branches
+        uses: asterisk/asterisk-ci-actions/GetCherryPickBranchesFromPR@main
+        id: getbranches
+        with:
+          repo:                   ${{github.repository}}
+          pr_number:              ${{env.PR_NUMBER}}
+          cherry_pick_regex:      ${{vars.CHERRY_PICK_REGEX}}
+          github_token:           ${{secrets.GITHUB_TOKEN}}
+
+      - name: Check Branch Count
+        id: checkbranches
+        env:
+          BRANCH_COUNT:  ${{ steps.getbranches.outputs.branch_count }}
+          BRANCHES:  ${{ steps.getbranches.outputs.branches }}
+          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        run: |
+          gh pr edit --repo ${{github.repository}} \
+          --add-label ${{vars.PRE_MERGE_TESTING_IN_PROGRESS}} \
+          ${{env.PR_NUMBER}} || :
+          all_branches=$(echo "$BRANCHES" | jq -c "[ \"$BASE_BRANCH\" ] + .")
+          echo "all_branches=${all_branches}" >>${GITHUB_OUTPUT}
+
+      - name: Pre Check Cherry-Picks
+        if: ${{ steps.getbranches.outputs.branch_count > 0 }}
+        uses: asterisk/asterisk-ci-actions/CherryPick@main
+        with:
+          repo:              ${{github.repository}}
+          pr_number:         ${{env.PR_NUMBER}}
+          branches:          ${{steps.getbranches.outputs.branches}}
+          github_token:      ${{secrets.GITHUB_TOKEN}}
+          push:              false
+
+  PreMergeUnitTestMatrix:
+    needs: [ IdentifyBranches ]
+    if: success()
+    continue-on-error: false
+    strategy:
+      fail-fast: false
+      matrix:
+        branch: ${{ fromJSON(needs.IdentifyBranches.outputs.all_branches) }}
+    runs-on: ubuntu-latest
+    steps:
+      - name: Run Unit Tests for branch ${{matrix.branch}}
+        uses: asterisk/asterisk-ci-actions/AsteriskUnitComposite@main
+        with:
+          asterisk_repo:     ${{github.repository}}
+          pr_number:         ${{env.PR_NUMBER}}
+          base_branch:       ${{matrix.branch}}
+          is_cherry_pick:    true
+          modules_blacklist: ${{env.MODULES_BLACKLIST}}
+          github_token:      ${{secrets.GITHUB_TOKEN}}
+          unittest_command:  ${{vars.UNITTEST_COMMAND}}
+
+  PreMergeUnitTests:
+    needs: [ IdentifyBranches, PreMergeUnitTestMatrix ]
+    runs-on: ubuntu-latest
+    steps:
+      - name: Check unit test matrix status
+        env:
+          RESULT:    ${{needs.PreMergeUnitTestMatrix.result}}
+          GH_TOKEN:  ${{ secrets.GITHUB_TOKEN }}
+        run: |
+          case $RESULT in
+            success)
+              gh pr edit --repo ${{github.repository}} \
+                --remove-label ${{vars.PRE_MERGE_TESTING_IN_PROGRESS}} \
+                --add-label ${{vars.PRE_MERGE_CHECKS_PASSED_LABEL}} \
+                ${{env.PR_NUMBER}} || :
+              echo "::notice::All tests passed"
+              exit 0
+              ;;
+            skipped)
+              gh pr edit --repo ${{github.repository}} \
+                --remove-label ${{vars.PRE_MERGE_TESTING_IN_PROGRESS}} \
+                --add-label ${{vars.PRE_MERGE_CHECKS_FAILED_LABEL}} \
+                ${{env.PR_NUMBER}} || :
+              echo "::notice::Unit tests were skipped because of an earlier failure"
+              exit 1
+              ;;
+            *)
+              gh pr edit --repo ${{github.repository}} \
+                --remove-label ${{vars.PRE_MERGE_TESTING_IN_PROGRESS}} \
+                --add-label ${{vars.PRE_MERGE_CHECKS_FAILED_LABEL}} \
+                ${{env.PR_NUMBER}} || :
+              echo "::error::One or more tests failed ($RESULT)"
+              exit 1
+          esac
+
+  MergeAndCherryPick:
+    needs: [ IdentifyBranches, PreMergeUnitTests ]
+    if: success()
+    concurrency:
+      group: MergeAndCherryPick
+      cancel-in-progress: false
+    runs-on: ubuntu-latest
+    steps:
+      - name: Start Merge
+        env:
+          GH_TOKEN:  ${{ secrets.GITHUB_TOKEN }}
+        run: |
+            gh pr edit --repo ${{github.repository}} \
+              --add-label ${{vars.MERGE_IN_PROGRESS_LABEL}} \
+              ${{env.PR_NUMBER}} || :
+
+      - name: Get Token needed to push cherry-picks
+        id: get_workflow_token
+        uses: peter-murray/workflow-application-token-action@v1
+        with:
+          application_id: ${{secrets.ASTERISK_ORG_ACCESS_APP_ID}}
+          application_private_key: ${{secrets.ASTERISK_ORG_ACCESS_APP_PRIV_KEY}}
+          organization: asterisk
+
+      - name: Merge and Cherry Pick to ${{needs.IdentifyBranches.outputs.branches}}
+        id: mergecp
+        uses: asterisk/asterisk-ci-actions/MergeAndCherryPickComposite@main
+        with:
+          repo:          ${{github.repository}}
+          pr_number:     ${{env.PR_NUMBER}}
+          branches:      ${{needs.IdentifyBranches.outputs.branches}}
+          force:         ${{env.FORCE}}
+          github_token:  ${{steps.get_workflow_token.outputs.token}}
+
+      - name: Merge Cleanup
+        if: always()
+        env:
+          RESULT:    ${{ steps.mergecp.outcome }}
+          GH_TOKEN:  ${{ secrets.GITHUB_TOKEN }}
+          BRANCH_COUNT: ${{ needs.IdentifyBranches.outputs.branch_count }}
+          BRANCHES:     ${{ needs.IdentifyBranches.outputs.branches }}
+
+        run: |
+          case $RESULT in
+            success)
+              gh pr edit --repo ${{github.repository}} \
+                --remove-label ${{vars.MERGE_IN_PROGRESS_LABEL}} \
+                ${{env.PR_NUMBER}} || :
+              if [ $BRANCH_COUNT -eq 0 ] ; then
+                gh pr comment --repo ${{github.repository}} \
+                  -b "Successfully merged to branch $BASE_BRANCH." \
+                  ${{env.PR_NUMBER}} || :
+              else
+                gh pr comment --repo ${{github.repository}} \
+                  -b "Successfully merged to branch $BASE_BRANCH and cherry-picked to $BRANCHES" \
+                  ${{env.PR_NUMBER}} || :
+              fi
+              exit 0
+              ;;
+            failure)
+              gh pr edit --repo ${{github.repository}} \
+                --remove-label ${{vars.MERGE_IN_PROGRESS_LABEL}} \
+                --add-label ${{vars.MERGE_FAILED_LABEL}} \
+                ${{env.PR_NUMBER}} || :
+              exit 1
+              ;;
+              *)
+          esac
index 73af62a49b6f4343835b8c357d0d06eb81967097..774736a3bf185c713e7646225cad0c3082efe7f7 100644 (file)
@@ -30,40 +30,3 @@ jobs:
         with:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 
-  IdentifyBranches:
-    if: github.event.pull_request.merged == true || inputs.pr_number
-    outputs:
-      branches:     ${{ steps.getbranches.outputs.branches }}
-      branch_count: ${{ steps.getbranches.outputs.branch_count }}
-      github_token: ${{steps.get_workflow_token.outputs.token}}
-    runs-on: ubuntu-latest
-    steps:
-      - name: Get cherry-pick branches
-        uses: asterisk/asterisk-ci-actions/GetCherryPickBranchesFromPR@main
-        id: getbranches
-        with:
-          repo:              ${{env.REPO}}
-          pr_number:         ${{env.PR_NUMBER}}
-          cherry_pick_regex: ${{vars.CHERRY_PICK_REGEX}}
-          github_token:      ${{env.GITHUB_TOKEN}}
-
-  MergeCherryPicks:
-    needs: [ IdentifyBranches ]
-    if: needs.IdentifyBranches.outputs.branch_count > 0
-    continue-on-error: false
-    strategy:
-      fail-fast: true
-      matrix:
-        branch: ${{ fromJSON(needs.IdentifyBranches.outputs.branches) }}
-    runs-on: ubuntu-latest
-    steps:
-    
-      - name: Cherry Pick PR ${{env.PR_NUMBER}} to branch ${{matrix.branch}}
-        uses: asterisk/asterisk-ci-actions/CherryPick@main
-        with:
-          repo:              ${{env.REPO}}
-          pr_number:         ${{env.PR_NUMBER}}
-          branch:            ${{matrix.branch}}
-          github_token:      ${{secrets.ASTERISKTEAM_PAT}}
-          access_app_id:     ${{secrets.ASTERISK_ORG_ACCESS_APP_ID}}
-          access_app_key:    ${{secrets.ASTERISK_ORG_ACCESS_APP_PRIV_KEY}}
index 9c8e3a05b0ede5c6c05f190653cede6f5884cdba..e75766a791f05b74ba89bd5a72ad287cde15c859 100644 (file)
@@ -5,10 +5,6 @@ on:
   pull_request_target:
     types: [opened, reopened, synchronize]
 
-#concurrency:
-#  group: ${{github.workflow}}-${{github.event.number}}
-#  cancel-in-progress: true
-
 env:
   ASTERISK_REPO:     ${{github.repository}}
   PR_NUMBER:         ${{github.event.number}}
@@ -19,7 +15,7 @@ env:
 
 jobs:
 
-  AsteriskUnitTests:
+  PROpenUpdateUnitTests:
     runs-on: ubuntu-latest
     steps:
       - name: Get Token needed to add reviewers
@@ -93,8 +89,8 @@ jobs:
             --add-label ${{vars.TEST_CHECKS_PASSED_LABEL}} \
             ${{env.PR_NUMBER}} || :
 
-  AsteriskGate:
-    needs: AsteriskUnitTests
+  PROpenUpdateGateTestMatrix:
+    needs: PROpenUpdateUnitTests
     continue-on-error: false
     strategy:
       fail-fast: false
@@ -117,19 +113,18 @@ jobs:
           gatetest_commands: ${{vars.GATETEST_COMMANDS}}
 
 
-  AsteriskGateTests:
-    name: AsteriskGateTests
+  PROpenUpdateGateTests:
     if: always()
     runs-on: ubuntu-latest
-    needs: AsteriskGate
+    needs: PROpenUpdateGateTestMatrix
     steps:
       - name: Check test matrix status
         env:
-          RESULT: ${{ needs.AsteriskGate.result }}
+          RESULT: ${{ needs.PROpenUpdateGateTestMatrix.result }}
           GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
         run: |
           echo "all results: ${{ toJSON(needs.*.result) }}"
-          echo "composite result: ${{ needs.AsteriskGate.result }}"
+          echo "composite result: $RESULT"
 
           gh pr edit --repo ${{github.repository}} \
             --remove-label ${{vars.TESTING_IN_PROGRESS}} \