diff --git a/.github/workflows/MergeApproved.yml b/.github/workflows/MergeApproved.yml deleted file mode 100644 index 1d1984e9d5..0000000000 --- a/.github/workflows/MergeApproved.yml +++ /dev/null @@ -1,187 +0,0 @@ -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() - 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@v2 - 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 diff --git a/.github/workflows/OnPRLabeled.yml b/.github/workflows/OnPRRecheck.yml similarity index 60% rename from .github/workflows/OnPRLabeled.yml rename to .github/workflows/OnPRRecheck.yml index 1254a90791..518684a890 100644 --- a/.github/workflows/OnPRLabeled.yml +++ b/.github/workflows/OnPRRecheck.yml @@ -1,5 +1,5 @@ -name: PRLabeled -run-name: "${{github.workflow}}-${{github.event.label.name}}-${{github.event.number}}" +name: PRRecheck +run-name: "PR ${{github.event.number}} PRRecheck" on: pull_request_target: types: [ labeled ] @@ -8,20 +8,9 @@ concurrency: group: ${{github.workflow}}-${{github.event.label.name}}-${{github.event.number}} cancel-in-progress: true -env: - PR_NUMBER: ${{ github.event.number }} - MODULES_BLACKLIST: ${{ vars.GATETEST_MODULES_BLACKLIST }} ${{ vars.UNITTEST_MODULES_BLACKLIST }} - jobs: - AsteriskCherryPickTest: - name: CherryPickTest - if: ${{ github.event.label.name == vars.CHERRY_PICK_TEST_LABEL }} - uses: asterisk/asterisk-ci-actions/.github/workflows/AsteriskCherryPickTest.yml@main - secrets: - TOKEN: ${{ secrets.GITHUB_TOKEN }} - - AsteriskRecheckPR: - name: Recheck + PRCheck: + name: PRCheck if: ${{ github.event.label.name == vars.RECHECKPR_LABEL }} uses: asterisk/asterisk-ci-actions/.github/workflows/AsteriskUnitGateTest.yml@main with: diff --git a/.github/workflows/OnPRStateChange.yml b/.github/workflows/OnPRStateChange.yml index 1bf9beb424..a553ad4bf3 100644 --- a/.github/workflows/OnPRStateChange.yml +++ b/.github/workflows/OnPRStateChange.yml @@ -28,8 +28,8 @@ jobs: with: action-vars: ${{ toJSON(steps.setvars.outputs) }} - CheckPR: - name: CheckPR + PRCheck: + name: PRCheck needs: Setup uses: asterisk/asterisk-ci-actions/.github/workflows/AsteriskUnitGateTest.yml@main with: diff --git a/.github/workflows/OnPRTestCherryPick.yml b/.github/workflows/OnPRTestCherryPick.yml new file mode 100644 index 0000000000..0e3cebfeac --- /dev/null +++ b/.github/workflows/OnPRTestCherryPick.yml @@ -0,0 +1,17 @@ +name: PRTestCherryPick +run-name: "PR ${{github.event.number}} PRTestCherryPick" +on: + pull_request_target: + types: [ labeled ] + +concurrency: + group: ${{github.workflow}}-${{github.event.label.name}}-${{github.event.number}} + cancel-in-progress: true + +jobs: + CherryPickTest: + name: CherryPickTest + if: ${{ github.event.label.name == vars.CHERRY_PICK_TEST_LABEL }} + uses: asterisk/asterisk-ci-actions/.github/workflows/AsteriskCherryPickTest.yml@main + secrets: + TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/PRSubmitActions.yml b/.github/workflows/PRPostCheckActions.yml similarity index 61% rename from .github/workflows/PRSubmitActions.yml rename to .github/workflows/PRPostCheckActions.yml index c7706d5609..1ce206fc52 100644 --- a/.github/workflows/PRSubmitActions.yml +++ b/.github/workflows/PRPostCheckActions.yml @@ -1,8 +1,8 @@ -name: PRSubmitActions -run-name: "PRSubmitActions: Test ${{github.event.action}}" +name: PRPostCheckActions +run-name: "PRPostCheckActions ${{github.event.workflow.name}} ${{github.event.action}}" on: workflow_run: - workflows: [PRSubmitTests] + workflows: [PRStateChanged,PRRecheck] types: - requested - completed @@ -12,26 +12,31 @@ env: REPO: ${{ github.repository }} jobs: - PRSubmitActions: + PRPostCheckActions: runs-on: ubuntu-latest + outputs: + PR_NUMBER: ${{ steps.getpr.outputs.PR_NUMBER }} steps: + - name: DumpEnvironment + uses: asterisk/asterisk-ci-actions/DumpEnvironmentAction@main + - name: Get PR Number id: getpr - uses: actions/github-script@v7 - with: - retries: 5 - script: | - let search = `repo:${context.repo.owner}/${context.repo.repo} ${context.payload.workflow_run.head_sha}`; - let prs = await github.rest.search.issuesAndPullRequests({ - q: search, - }); - if (prs.data.total_count == 0) { - core.setFailed(`Unable to get PR for ${context.payload.workflow_run.head_sha}`); - return; - } - let pr_number = prs.data.items[0].number; - core.setOutput('pr_number', pr_number); - return; + env: + GH_TOKEN: ${{ github.token }} + SHA: ${{github.event.workflow_run.head_sha}} + run: | + PR_NUMBER=$(gh -R $REPO search prs $SHA --json number --jq '.[].number') + if [ -z "$PR_NUMBER" ] ; then + echo "::error::Unable to find PR number" + exit 1 + fi + if [[ "$PR_NUMBER" =~ ^[0-9]+$ ]] ; then + echo "PR_NUMBER=${PR_NUMBER}" >>${GITHUB_OUTPUT} + exit 0 + fi + echo "::error::PR number '$PR_NUMBER' not valid" + exit 1 - name: Set Label id: setlabel @@ -115,35 +120,35 @@ jobs: }) return; - - name: Add reviewers - if: github.event.action == 'completed' - uses: actions/github-script@v7 - env: - PR_NUMBER: ${{steps.getpr.outputs.PR_NUMBER}} - REVIEWERS: ${{vars.PR_REVIEWERS}} - with: - retries: 5 - github-token: ${{ secrets.ASTERISKTEAM_PAT }} - script: | - let rs = JSON.parse(process.env.REVIEWERS.length ? process.env.REVIEWERS : '[]'); - let users = []; - let teams = []; - for (const r of rs) { - if (r.indexOf("/") > 0) { - teams.push(r.split('/')[1]); - } else { - users.push(r); - } - } - if (teams.length > 0 || users.length > 0) { - core.info(`Adding user reviewers ${users}`); - core.info(`Adding team reviewers ${teams}`); - await github.rest.pulls.requestReviewers({ - pull_number: process.env.PR_NUMBER, - owner: context.repo.owner, - repo: context.repo.repo, - reviewers: users, - team_reviewers: teams - }); - } - return; +# - name: Add reviewers +# if: github.event.action == 'completed' +# uses: actions/github-script@v7 +# env: +# PR_NUMBER: ${{steps.getpr.outputs.PR_NUMBER}} +# REVIEWERS: ${{vars.PR_REVIEWERS}} +# with: +# retries: 5 +# github-token: ${{ secrets.ASTERISKTEAM_PAT }} +# script: | +# let rs = JSON.parse(process.env.REVIEWERS.length ? process.env.REVIEWERS : '[]'); +# let users = []; +# let teams = []; +# for (const r of rs) { +# if (r.indexOf("/") > 0) { +# teams.push(r.split('/')[1]); +# } else { +# users.push(r); +# } +# } +# if (teams.length > 0 || users.length > 0) { +# core.info(`Adding user reviewers ${users}`); +# core.info(`Adding team reviewers ${teams}`); +# await github.rest.pulls.requestReviewers({ +# pull_number: process.env.PR_NUMBER, +# owner: context.repo.owner, +# repo: context.repo.repo, +# reviewers: users, +# team_reviewers: teams +# }); +# } +# return; diff --git a/.github/workflows/onPRMergeApproved.yml b/.github/workflows/onPRMergeApproved.yml new file mode 100644 index 0000000000..6d668c9336 --- /dev/null +++ b/.github/workflows/onPRMergeApproved.yml @@ -0,0 +1,19 @@ +name: PRMergeApproved +run-name: "PR ${{github.event.number}} PRMergeApproved" +on: + pull_request_target: + types: [labeled] + +concurrency: + group: ${{github.workflow}}-${{github.event.label.name}}-${{github.event.number}} + cancel-in-progress: true + +jobs: + MergePR: + name: MergePR + if: contains(fromJSON(vars.MERGE_APPROVED_LABELS), github.event.label.name) + uses: asterisk/asterisk-ci-actions/.github/workflows/AsteriskMergePR.yml@main + with: + dry_run: true + secrets: + TOKEN: ${{ secrets.GITHUB_TOKEN }}