From 2b9f1bebd57132a149c6b56c9f93a4bff1678d5c Mon Sep 17 00:00:00 2001 From: George Joseph Date: Wed, 6 Nov 2024 11:54:31 -0700 Subject: [PATCH] .github: Reusable workflows Similar to what's already been done for Asterisk, the existing github workflows have been replaced with calls to reusable workflows from asterisk-ci-actions. Also refactored the self test slightly to not require an Asterisk build and install. All it took was adding a recent asterisk buildopts.h to lib/python/asterisk/self_test. --- .github/workflows/CherryPickTest.yml | 111 ---------- .github/workflows/MergeApproved.yml | 191 ------------------ .github/workflows/OnPRCherryPickTest.yml | 105 ++++++++++ .github/workflows/OnPRMergeApproved.yml | 19 ++ .github/workflows/OnPRRecheck.yml | 70 +++++++ .github/workflows/OnPRStateChanged.yml | 49 +++++ .github/workflows/OnPRStateChangedPriv.yml | 27 +++ .github/workflows/PRMerged.yml | 32 --- .github/workflows/PRSubmitActions.yml | 148 -------------- .github/workflows/PRSubmitTests.yml | 78 ------- lib/python/asterisk/self_test/buildopts.h | 13 ++ .../asterisk/self_test/test_buildoptions.py | 2 +- 12 files changed, 284 insertions(+), 561 deletions(-) delete mode 100644 .github/workflows/CherryPickTest.yml delete mode 100644 .github/workflows/MergeApproved.yml create mode 100644 .github/workflows/OnPRCherryPickTest.yml create mode 100644 .github/workflows/OnPRMergeApproved.yml create mode 100644 .github/workflows/OnPRRecheck.yml create mode 100644 .github/workflows/OnPRStateChanged.yml create mode 100644 .github/workflows/OnPRStateChangedPriv.yml delete mode 100644 .github/workflows/PRMerged.yml delete mode 100644 .github/workflows/PRSubmitActions.yml delete mode 100644 .github/workflows/PRSubmitTests.yml create mode 100644 lib/python/asterisk/self_test/buildopts.h diff --git a/.github/workflows/CherryPickTest.yml b/.github/workflows/CherryPickTest.yml deleted file mode 100644 index ff2f4e340..000000000 --- a/.github/workflows/CherryPickTest.yml +++ /dev/null @@ -1,111 +0,0 @@ -name: CherryPickTest -run-name: "Cherry-Pick Tests for PR ${{github.event.number}}" -on: - pull_request_target: - types: [ labeled ] - -concurrency: - group: ${{github.workflow}}-${{github.event.number}} - cancel-in-progress: true - -env: - PR_NUMBER: ${{ github.event.number }} - MODULES_BLACKLIST: ${{ vars.GATETEST_MODULES_BLACKLIST }} ${{ vars.UNITTEST_MODULES_BLACKLIST }} - -jobs: - IdentifyBranches: - name: IdentifyBranches - if: ${{ github.event.label.name == vars.CHERRY_PICK_TEST_LABEL }} - outputs: - branches: ${{ steps.getbranches.outputs.branches }} - branch_count: ${{ steps.getbranches.outputs.branch_count }} - runs-on: ubuntu-latest - steps: - - name: Remove Trigger Label, Add InProgress Label - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - gh pr edit --repo ${{github.repository}} \ - --remove-label ${{vars.CHERRY_PICK_TEST_LABEL}} \ - --remove-label ${{vars.CHERRY_PICK_CHECKS_PASSED_LABEL}} \ - --remove-label ${{vars.CHERRY_PICK_CHECKS_FAILED_LABEL}} \ - --remove-label ${{vars.CHERRY_PICK_GATES_PASSED_LABEL}} \ - --remove-label ${{vars.CHERRY_PICK_GATES_FAILED_LABEL}} \ - --remove-label ${{vars.CHERRY_PICK_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 - if: ${{ steps.getbranches.outputs.branch_count > 0 }} - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - gh pr edit --repo ${{github.repository}} \ - --add-label ${{vars.CHERRY_PICK_TESTING_IN_PROGRESS}} \ - ${{env.PR_NUMBER}} || : - - CherryPickUnitTestMatrix: - needs: [ IdentifyBranches ] - if: ${{ needs.IdentifyBranches.outputs.branch_count > 0 && ( success() || failure() ) }} - continue-on-error: false - strategy: - fail-fast: false - matrix: - branch: ${{ fromJSON(needs.IdentifyBranches.outputs.branches) }} - runs-on: ubuntu-latest - steps: - - name: Run Unit Tests for branch ${{matrix.branch}} - uses: asterisk/asterisk-ci-actions/TestsuiteUnitComposite@main - with: - testsuite_repo: ${{github.repository}} - asterisk_repo: ${{vars.ASTERISK_REPO}} - 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}} - - 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.CherryPickUnitTestMatrix.result}} - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - case $RESULT in - success) - gh pr edit --repo ${{github.repository}} \ - --remove-label ${{vars.CHERRY_PICK_TESTING_IN_PROGRESS}} \ - --add-label ${{vars.CHERRY_PICK_CHECKS_PASSED_LABEL}} \ - ${{env.PR_NUMBER}} || : - echo "::notice::All tests passed" - exit 0 - ;; - skipped) - gh pr edit --repo ${{github.repository}} \ - --remove-label ${{vars.CHERRY_PICK_TESTING_IN_PROGRESS}} \ - --add-label ${{vars.CHERRY_PICK_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.CHERRY_PICK_TESTING_IN_PROGRESS}} \ - --add-label ${{vars.CHERRY_PICK_CHECKS_FAILED_LABEL}} \ - ${{env.PR_NUMBER}} || : - echo "::error::One or more tests failed ($RESULT)" - exit 1 - esac diff --git a/.github/workflows/MergeApproved.yml b/.github/workflows/MergeApproved.yml deleted file mode 100644 index 34f38b3e9..000000000 --- a/.github/workflows/MergeApproved.yml +++ /dev/null @@ -1,191 +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/TestsuiteUnitComposite@main - with: - testsuite_repo: ${{github.repository}} - asterisk_repo: ${{vars.ASTERISK_REPO}} - 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 diff --git a/.github/workflows/OnPRCherryPickTest.yml b/.github/workflows/OnPRCherryPickTest.yml new file mode 100644 index 000000000..99f65724e --- /dev/null +++ b/.github/workflows/OnPRCherryPickTest.yml @@ -0,0 +1,105 @@ +name: PRCPCheck +run-name: "PR ${{ github.event.number }} CherryPickTest" +on: + pull_request_target: + types: [ labeled ] + +concurrency: + group: ${{ github.workflow }}-${{ github.event.label.name }}-${{ github.event.number }} + cancel-in-progress: true + +env: + PR_NUMBER: ${{ github.event.number }} + +jobs: + Setup: + if: ${{ github.event.label.name == vars.CHERRY_PICK_TEST_LABEL }} + name: Setup + runs-on: ubuntu-latest + outputs: + branches: ${{ steps.getbranches.outputs.branches }} + branch_count: ${{ steps.getbranches.outputs.branch_count }} + steps: + - name: Remove Trigger Label, Add InProgress Label + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh pr edit --repo ${{ github.repository }} \ + --remove-label ${{ vars.CHERRY_PICK_TEST_LABEL }} \ + --remove-label ${{ vars.CHERRY_PICK_CHECKS_PASSED_LABEL }} \ + --remove-label ${{ vars.CHERRY_PICK_CHECKS_FAILED_LABEL }} \ + --remove-label ${{ vars.CHERRY_PICK_TESTING_IN_PROGRESS }} \ + $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 + if: ${{ steps.getbranches.outputs.branch_count > 0 }} + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh pr edit --repo ${{ github.repository }} \ + --add-label ${{ vars.CHERRY_PICK_TESTING_IN_PROGRESS }} \ + $PR_NUMBER || : + + - name: CherryPick + uses: asterisk/asterisk-ci-actions/CherryPick@main + with: + repo: ${{ github.repository }} + pr_number: ${{ github.event.number }} + branches: ${{ steps.getbranches.outputs.branches }} + push: false + github_token: ${{ secrets.GITHUB_TOKEN }} + debug: false + + Check: + needs: [Setup] + if: ${{ needs.Setup.outputs.branch_count > 0 && ( success() ) }} + strategy: + fail-fast: false + matrix: + branch: ${{ fromJSON(needs.Setup.outputs.branches) }} + uses: asterisk/asterisk-ci-actions/.github/workflows/RunTestsuiteUnitTest.yml@main + with: + pr_number: ${{ github.event.number }} + base_branch: ${{ matrix.branch }} + unittest_command: ${{ vars.UNITTEST_COMMAND }} + secrets: + TOKEN: ${{ secrets.GITHUB_TOKEN }} + + Summary: + if: ${{ success() || failure() }} + runs-on: ubuntu-latest + needs: [Setup,Check] + steps: + - name: Check status + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RESULT_UNIT: ${{ needs.Check.result }} + TESTS_PASSED: ${{ vars.CHERRY_PICK_CHECKS_PASSED_LABEL }} + TESTS_FAILED: ${{ vars.CHERRY_PICK_CHECKS_FAILED_LABEL }} + run: | + declare -i rc=0 + case $RESULT_UNIT in + success) + ;; + skipped) + rc+=1 + ;; + *) + rc+=1 + esac + [ $rc -gt 0 ] && label=$TESTS_FAILED || label=$TESTS_PASSED + gh pr edit --repo ${{ github.repository }} \ + --remove-label ${{ vars.CHERRY_PICK_TESTING_IN_PROGRESS }} \ + --add-label $label \ + $PR_NUMBER || : + exit $rc + diff --git a/.github/workflows/OnPRMergeApproved.yml b/.github/workflows/OnPRMergeApproved.yml new file mode 100644 index 000000000..5e68eba49 --- /dev/null +++ b/.github/workflows/OnPRMergeApproved.yml @@ -0,0 +1,19 @@ +name: MergePR +run-name: "PR ${{ github.event.number }} MergeApproved" +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/TestsuiteMergePR.yml@main + secrets: + TOKEN: ${{ secrets.GITHUB_TOKEN }} + application_id: ${{ secrets.ASTERISK_ORG_ACCESS_APP_ID }} + application_private_key: ${{ secrets.ASTERISK_ORG_ACCESS_APP_PRIV_KEY }} diff --git a/.github/workflows/OnPRRecheck.yml b/.github/workflows/OnPRRecheck.yml new file mode 100644 index 000000000..82390324a --- /dev/null +++ b/.github/workflows/OnPRRecheck.yml @@ -0,0 +1,70 @@ +name: PRReCheck +run-name: "PR ${{ github.event.number }} Recheck" +on: + pull_request_target: + types: [ labeled ] + +concurrency: + group: check-${{ github.event.number }} + cancel-in-progress: true + +env: + PR_NUMBER: ${{ github.event.number }} + +jobs: + Setup: + if: ${{ github.event.label.name == vars.RECHECKPR_LABEL }} + runs-on: ubuntu-latest + steps: + - name: Set Label + id: setlabel + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh pr edit --repo ${{ github.repository }} \ + --remove-label ${{ vars.RECHECKPR_LABEL }} \ + --remove-label ${{ vars.PR_SUBMIT_TESTS_PASSED }} \ + --remove-label ${{ vars.PR_SUBMIT_TESTS_FAILED }} \ + --add-label ${{ vars.PR_SUBMIT_TESTING_IN_PROGRESS }} \ + $PR_NUMBER || : + + Check: + name: Check + needs: Setup + uses: asterisk/asterisk-ci-actions/.github/workflows/RunTestsuiteUnitTest.yml@main + with: + pr_number: ${{ github.event.number }} + base_branch: ${{ github.event.pull_request.base.ref }} + unittest_command: ${{ vars.UNITTEST_COMMAND }} + secrets: + TOKEN: ${{ secrets.GITHUB_TOKEN }} + + Summary: + if: ${{ success() || failure() }} + runs-on: ubuntu-latest + needs: [Setup,Check] + steps: + - name: Check status + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RESULT_UNIT: ${{ needs.Check.result }} + TESTS_PASSED: ${{ vars.PR_SUBMIT_TESTS_PASSED }} + TESTS_FAILED: ${{ vars.PR_SUBMIT_TESTS_FAILED }} + run: | + declare -i rc=0 + case $RESULT_UNIT in + success) + ;; + skipped) + rc+=1 + ;; + *) + rc+=1 + esac + [ $rc -gt 0 ] && label=$TESTS_FAILED || label=$TESTS_PASSED + gh pr edit --repo ${{ github.repository }} \ + --remove-label ${{ vars.PR_SUBMIT_TESTING_IN_PROGRESS }} \ + --add-label $label \ + $PR_NUMBER || : + exit $rc + diff --git a/.github/workflows/OnPRStateChanged.yml b/.github/workflows/OnPRStateChanged.yml new file mode 100644 index 000000000..7fe247eb3 --- /dev/null +++ b/.github/workflows/OnPRStateChanged.yml @@ -0,0 +1,49 @@ +# +# Workflows, like this one, that are triggered by PRs submitted +# from forked repositories are severly limited in what they can do +# for security reasons. For instance, they can't add or remove +# labels or comments even on the PR that triggered them. Since +# we need to both of those things, GitHub recommends creating a +# separate workflow that does those tasks that's triggered when +# this PR workflow starts or finishes. Since that workflow isn't +# being run in the context of a forked repo, it has all the +# privileges needed to add and remove labels and comments. The +# accompanying OnPRStateChangedPriv workflow does just that. + +name: PRChanged +run-name: "PR ${{ github.event.number }} ${{ github.event.action }} by ${{ github.actor }}" +on: + pull_request: + types: [opened, reopened, synchronize] + +concurrency: + group: check-${{ github.event.number }} + cancel-in-progress: true + +jobs: +# +# Pull requests created from forked respositories don't have access +# to the "Action Variables" ('vars' context) so we need to retrieve +# control data from an action that's located in asterisk-ci-actions. +# + Setup: + runs-on: ubuntu-latest + outputs: + vars: ${{ steps.setvars.outputs.control_data }} + steps: + - id: setvars + uses: asterisk/asterisk-ci-actions/GetRepoControlData@main + with: + repo: ${{ github.event.repository.name }} + + Check: + name: Check + needs: Setup + uses: asterisk/asterisk-ci-actions/.github/workflows/RunTestsuiteUnitTest.yml@main + with: + pr_number: ${{ github.event.number }} + base_branch: ${{ github.event.pull_request.base.ref }} + unittest_command: ${{ fromJSON(needs.Setup.outputs.vars).UNITTEST_COMMAND }} + secrets: + TOKEN: ${{ secrets.GITHUB_TOKEN }} + diff --git a/.github/workflows/OnPRStateChangedPriv.yml b/.github/workflows/OnPRStateChangedPriv.yml new file mode 100644 index 000000000..39ac25d08 --- /dev/null +++ b/.github/workflows/OnPRStateChangedPriv.yml @@ -0,0 +1,27 @@ +# +# Workflows triggered by PRs submitted from forked repositories +# (all of ours) are severly limited in what they can do. +# For instance, they can't add or remove labels or comments even +# on the PR that triggered them. Since we need to both of those, +# GitHub recommends creating a separate workflow (this one) that +# does those tasks that's triggered when the PR submit workflow +# starts or finishes. Since this workflow isn't being run in the +# context of a forked repo, it has all the privileges needed to +# add and remove labels and comments. Hence the "Priv" at the end +# of this workflow name. +# +name: PRChangedPriv +run-name: "PRChangedPriv ${{ github.event.workflow.name }} ${{ github.event.action }}" +on: + workflow_run: + workflows: [PRChanged] + types: + - requested + - completed + +jobs: + PRChangedPriv: + name: PRChangedPriv + uses: asterisk/asterisk-ci-actions/.github/workflows/TestsuitePRStateChangedPriv.yml@main + secrets: + TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/PRMerged.yml b/.github/workflows/PRMerged.yml deleted file mode 100644 index 774736a3b..000000000 --- a/.github/workflows/PRMerged.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: PRMerged -run-name: "PR ${{github.event.number || inputs.pr_number}} ${{github.event.action || 'MANUAL POST MERGE'}} by ${{ github.actor }}" -on: - pull_request_target: - types: [closed] - workflow_dispatch: - inputs: - pr_number: - description: 'PR number' - required: true - type: number - -concurrency: - group: ${{github.workflow}}-${{github.event.number || inputs.pr_number}} - cancel-in-progress: true - -env: - REPO: ${{github.repository}} - PR_NUMBER: ${{github.event.number || inputs.pr_number}} - GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} - -jobs: - CloseIssues: - if: github.event.pull_request.merged == true - runs-on: ubuntu-latest - steps: - - uses: wow-actions/auto-close-fixed-issues@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - diff --git a/.github/workflows/PRSubmitActions.yml b/.github/workflows/PRSubmitActions.yml deleted file mode 100644 index 3e4f0dc96..000000000 --- a/.github/workflows/PRSubmitActions.yml +++ /dev/null @@ -1,148 +0,0 @@ -name: PRSubmitActions -run-name: "PRSubmitActions: Test ${{github.event.action}}" -on: - workflow_run: - workflows: [PRSubmitTests] - types: - - requested - - completed -env: - ACTION: ${{ github.event.action }} - CONCLUSION: ${{ github.event.workflow_run.conclusion }} - REPO: ${{ github.repository }} - -jobs: - PRSubmitActions: - runs-on: ubuntu-latest - steps: - - 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; - - - name: Set Label - id: setlabel - uses: actions/github-script@v7 - env: - PR_NUMBER: ${{ steps.getpr.outputs.PR_NUMBER }} - LABEL_TIP: ${{ vars.PR_SUBMIT_TESTING_IN_PROGRESS }} - LABEL_PASS: ${{ vars.PR_SUBMIT_TESTS_PASSED }} - LABEL_FAIL: ${{ vars.PR_SUBMIT_TESTS_FAILED }} - with: - retries: 5 - script: | - let label; - if (process.env.ACTION === 'requested') { - label = process.env.LABEL_TIP; - } else { - if ( process.env.CONCLUSION === 'success' ) { - label = process.env.LABEL_PASS; - } else { - label = process.env.LABEL_FAIL; - } - } - core.info(`Setting label ${label}`); - github.rest.issues.setLabels({ - issue_number: process.env.PR_NUMBER, - owner: context.repo.owner, - repo: context.repo.repo, - labels: [ label ] - }); - return; - - - name: Get cherry-pick branches - if: github.event.action == 'completed' - id: getbranches - uses: asterisk/asterisk-ci-actions/GetCherryPickBranchesFromPR@main - with: - repo: ${{env.REPO}} - pr_number: ${{steps.getpr.outputs.PR_NUMBER}} - cherry_pick_regex: ${{vars.CHERRY_PICK_REGEX}} - github_token: ${{secrets.GITHUB_TOKEN}} - - - name: Add cherry-pick reminder - if: github.event.action == 'completed' - uses: actions/github-script@v7 - env: - PR_NUMBER: ${{steps.getpr.outputs.PR_NUMBER}} - CHERRY_PICK_REMINDER: ${{vars.CHERRY_PICK_REMINDER}} - BRANCHES_OUTPUT: ${{toJSON(steps.getbranches.outputs)}} - BRANCH_COUNT: ${{steps.getbranches.outputs.branch_count}} - FORCED_NONE: ${{steps.getbranches.outputs.forced_none}} - with: - retries: 5 - script: | - if (process.env.FORCED_NONE === 'true' || - process.env.BRANCH_COUNT > 0) { - core.info("No cherry-pick reminder needed."); - return; - } - let comments = await github.rest.issues.listComments({ - issue_number: process.env.PR_NUMBER, - owner: context.repo.owner, - repo: context.repo.repo, - }); - let found = false; - for (const c of comments.data) { - if (c.body.startsWith("")) { - found = true; - break; - } - } - if (found) { - core.info("Cherry-pick reminder already exists."); - return; - } - core.info("Adding cherry-pick reminder."); - await github.rest.issues.createComment({ - issue_number: process.env.PR_NUMBER, - owner: context.repo.owner, - repo: context.repo.repo, - body: process.env.CHERRY_PICK_REMINDER - }) - 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 - script: | - let rs = JSON.parse(process.env.REVIEWERS); - let users = []; - let teams = []; - for (const r of rs) { - if (r.indexOf("/") > 0) { - teams.push(r); - } 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({ - pr_number: process.env.PR_NUMBER, - owner: context.repo.owner, - repo: context.repo.repo, - reviewers: users, - team_reviewers: teams - }); - } - return; diff --git a/.github/workflows/PRSubmitTests.yml b/.github/workflows/PRSubmitTests.yml deleted file mode 100644 index 87aa7f7e1..000000000 --- a/.github/workflows/PRSubmitTests.yml +++ /dev/null @@ -1,78 +0,0 @@ -name: PRSubmitTests -run-name: "PR ${{github.event.number}} ${{github.event.action}} by ${{ github.actor }}" -on: - pull_request: - types: [opened, reopened, synchronize] - -concurrency: - group: ${{github.workflow}}-${{github.event.number}} - cancel-in-progress: true - -env: - TESTSUITE_REPO: ${{github.repository}} - PR_NUMBER: ${{github.event.number}} - PR_COMMIT: ${{github.event.pull_request.head.sha}} - BRANCH: ${{github.event.pull_request.base.ref}} - -jobs: -# -# Pull requests created from forked respositories don't have access to -# the "Action Variables" ('vars' context) so we need to retrieve control -# data from an action. -# - PRSGetControlData: - runs-on: ubuntu-latest - outputs: - control_data: ${{ steps.setvars.outputs.control_data }} - steps: - - id: setvars - uses: asterisk/asterisk-ci-actions/GetRepoControlData@main - with: - repo: ${{ github.event.repository.name}} - - name: DumpEnvironment - uses: asterisk/asterisk-ci-actions/DumpEnvironmentAction@main - with: - action-inputs: ${{toJSON(inputs)}} - action-vars: ${{ toJSON(steps.setvars.outputs) }} - - PRSUnitTests: - needs: PRSGetControlData - runs-on: ubuntu-latest - env: - UNITTEST_COMMAND: ${{ fromJSON(needs.PRSGetControlData.outputs.control_data).UNITTEST_COMMAND }} - ASTERISK_REPO: ${{ fromJSON(needs.PRSGetControlData.outputs.control_data).ASTERISK_REPO }} - steps: - - name: Run Unit Tests - uses: asterisk/asterisk-ci-actions/TestsuiteUnitComposite@main - with: - asterisk_repo: ${{env.ASTERISK_REPO}} - testsuite_repo: ${{env.TESTSUITE_REPO}} - pr_number: ${{env.PR_NUMBER}} - base_branch: ${{env.BRANCH}} - unittest_command: ${{env.UNITTEST_COMMAND}} - - PRSTestResults: - if: always() - runs-on: ubuntu-latest - needs: [PRSUnitTests] - steps: - - name: Check test matrix status - env: - RESULT_UNIT: ${{ needs.PRSUnitTests.result }} - run: | - declare -i rc=0 - echo "all results: ${{ toJSON(needs.*.result) }}" - case $RESULT_UNIT in - success) - echo "::notice::Unit tests passed" - ;; - skipped) - echo "::error::Unit tests were skipped because of an earlier failure" - rc+=1 - ;; - *) - echo "::error::One or more unit tests failed ($RESULT_UNIT)" - rc+=1 - esac - echo "::notice::Final result code: $rc" - exit $rc diff --git a/lib/python/asterisk/self_test/buildopts.h b/lib/python/asterisk/self_test/buildopts.h new file mode 100644 index 000000000..75062456d --- /dev/null +++ b/lib/python/asterisk/self_test/buildopts.h @@ -0,0 +1,13 @@ +/* + * buildopts.h + * Automatically generated + */ + +#define AST_DEVMODE 1 +#define DONT_OPTIMIZE 1 +#define OPTIONAL_API 1 +#define DO_CRASH 1 +#define TEST_FRAMEWORK 1 +#define AST_BUILDOPT_SUM "c1ede5e75208a56856a96370ccdead31" +#define AST_BUILDOPTS "OPTIONAL_API, DO_CRASH, TEST_FRAMEWORK" +#define AST_BUILDOPTS_ALL "DONT_OPTIMIZE, OPTIONAL_API, DO_CRASH, TEST_FRAMEWORK" diff --git a/lib/python/asterisk/self_test/test_buildoptions.py b/lib/python/asterisk/self_test/test_buildoptions.py index 1f4ca770d..be839ab1a 100755 --- a/lib/python/asterisk/self_test/test_buildoptions.py +++ b/lib/python/asterisk/self_test/test_buildoptions.py @@ -18,7 +18,7 @@ class AsteriskBuildOptionsTests(unittest.TestCase): def test_1(self): """Test the defaults paths""" - build_options = AsteriskBuildOptions() + build_options = AsteriskBuildOptions("./lib/python/asterisk/self_test/buildopts.h") self.assertTrue(build_options)