From 0d35337618977cb85f45da1f793e927a77c8e22c Mon Sep 17 00:00:00 2001 From: Anthony Islas Date: Thu, 12 Dec 2024 13:52:39 -0700 Subject: [PATCH 1/5] Convert to dispatch workflow and switch context vars to inputs --- .github/workflows/ci.yml | 45 ++++++++++++++++++++++------- .github/workflows/test_workflow.yml | 21 +++++++++++--- 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 087f9eba34..9348e6124f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,15 +1,34 @@ name: Regression Suite -run-name : ${{ github.event_name == 'push' && 'CI' || github.event.label.name }} (${{ github.event_name }}) +run-name : Run ${{ inputs.event_name == 'push' && 'CI' || inputs.test }} (${{ inputs.event_name }}) on: - push: - branches: [ master, develop ] -# See https://stackoverflow.com/a/78444521 and -# https://github.com/orgs/community/discussions/26874#discussioncomment-3253755 -# as well as official (but buried) documentation : -# https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#pull-request-events-for-forked-repositories-2 - pull_request: - types: [ labeled ] + workflow_dispatch: + inputs: + event_name: + description: Event name that triggered this dispatch + required: false + default: push + type: string + event_number: + description: Event number that triggered this dispatch + required: false + default: 0 + type: string + ref: + description: Actual ref to use + required: false + default: null + type: string + test: + description: Test to run + required: true + default: all-tests + type: choice + options: + - all-tests + - compile-tests + - tmp-tests + # https://docs.github.com/en/actions/sharing-automations/reusing-workflows#supported-keywords-for-jobs-that-call-a-reusable-workflow # Also https://stackoverflow.com/a/74959635 @@ -30,7 +49,7 @@ on: # https://stackoverflow.com/a/68940067 jobs: buildtests: - if : ${{ github.event.label.name == 'compile-tests' || github.event.label.name == 'all-tests' || github.event_name == 'push' }} + if : ${{ contains( fromJson('["compile-tests","all-tests"]'), inputs.test ) || inputs.event_name == 'push' }} strategy: max-parallel: 4 fail-fast: false @@ -86,6 +105,12 @@ jobs: args : ${{ matrix.testSet.args }} pool : ${{ matrix.testSet.pool }} tpool : ${{ matrix.testSet.tpool }} + + # required to emulate event trigger + event_name : ${{ inputs.event_name }} + event_number : ${{ inputs.event_number }} + ref : ${{ inputs.ref }} + # I am leaving this here for posterity if this is to be replicated in private repositories for testing permissions: contents: read diff --git a/.github/workflows/test_workflow.yml b/.github/workflows/test_workflow.yml index e80d6f3392..4da30cd38c 100644 --- a/.github/workflows/test_workflow.yml +++ b/.github/workflows/test_workflow.yml @@ -46,6 +46,16 @@ on : required : false type : number default : 1 + + event_name : + required : true + type : string + event_number: + required : true + type : string + ref : + required : true + type : string @@ -57,12 +67,14 @@ jobs: name: Test ${{ inputs.name }} on ${{ inputs.host }} runs-on: ${{ inputs.host }} env : - LOG_SUFFIX : ${{ github.event_name == 'push' && 'master' || github.event.number }} + LOG_SUFFIX : ${{ inputs.event_name == 'push' && github.ref_name || inputs.event_number }} steps: - uses: actions/checkout@v4 with: path : main submodules: true + ref: ${{ inputs.ref }} + # Immediately copy out to # of tests to do - name: Create testing directories @@ -90,7 +102,7 @@ jobs: -t ${{ join( fromJson( inputs.tests ), ' ' ) }} \ -a "${{ inputs.account }}" \ -p ${{ inputs.pool}} -tp ${{ inputs.tpool }} \ - -jn ${{ github.event_name == 'push' && github.ref_name || github.event.number }}-${{ inputs.id }} \ + -jn ${{ inputs.event_name == 'push' && github.ref_name || inputs.event_number }}-${{ inputs.id }} \ ${{ inputs.args }} $ALT_DIRS @@ -133,8 +145,9 @@ jobs: # *documented* functionality doesn't work as expected. Wow, bravo # can't use ${{ env. }} as somehow this combination of matrix->reusable workflow->call step is too complex # and expands to nothing - name: ${{ github.event_name == 'push' && github.ref_name || github.event.number }}-${{ inputs.id }}_logfiles - path: ${{ inputs.archive }}/${{ github.event_name == 'push' && github.ref_name || github.event.number }}/${{ inputs.id }}/ + name: ${{ inputs.event_name == 'push' && github.ref_name || inputs.event_number }}-${{ inputs.id }}_logfiles + path: ${{ inputs.archive }}/${{ inputs.event_name == 'push' && github.ref_name || inputs.event_number }}/${{ inputs.id }}/ + include-hidden-files: true # As noted in ci.yml, this will need to be moved to a separate workflow with pull_request_target # and strictly controlled usage of the GH token From 653302e60952c413026e406f13887a897bef585f Mon Sep 17 00:00:00 2001 From: Anthony Islas Date: Thu, 12 Dec 2024 13:53:14 -0700 Subject: [PATCH 2/5] Add commit status to dispatch sha --- .github/workflows/ci.yml | 1 + .github/workflows/test_workflow.yml | 34 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9348e6124f..62521047f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -115,6 +115,7 @@ jobs: permissions: contents: read pull-requests: write + statuses: write name : Test ${{ matrix.testSet.name }} on ${{ matrix.testSet.host }} # In the event that 'all-tests' is used, this final job will be the one to remove diff --git a/.github/workflows/test_workflow.yml b/.github/workflows/test_workflow.yml index 4da30cd38c..3b576e99a8 100644 --- a/.github/workflows/test_workflow.yml +++ b/.github/workflows/test_workflow.yml @@ -69,6 +69,25 @@ jobs: env : LOG_SUFFIX : ${{ inputs.event_name == 'push' && github.ref_name || inputs.event_number }} steps: + # Don't use gh checks as they are woefully underdeveloped as a feature leading + # to confusing UI and misplaced metrics + # https://github.com/orgs/community/discussions/24616 + - name: Set pending status + id: check_run_start + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + github.rest.repos.createCommitStatus({ + owner: context.repo.owner, + repo: context.repo.repo, + sha: context.sha, + target_url: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}', + description: '${{ inputs.name }}', + context: '${{ inputs.host }}/${{ inputs.id }}', + state: 'pending' + }) + - uses: actions/checkout@v4 with: path : main @@ -149,6 +168,21 @@ jobs: path: ${{ inputs.archive }}/${{ inputs.event_name == 'push' && github.ref_name || inputs.event_number }}/${{ inputs.id }}/ include-hidden-files: true + - name: Set completed status + if: ${{ always() }} + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + github.rest.repos.createCommitStatus({ + owner: context.repo.owner, + repo: context.repo.repo, + sha: context.sha, + target_url: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}', + description: '${{ inputs.name }}', + context: '${{ inputs.host }}/${{ inputs.id }}', + state: '${{ job.status == 'success' && 'success' || 'failure' }}' + }) # As noted in ci.yml, this will need to be moved to a separate workflow with pull_request_target # and strictly controlled usage of the GH token # - name : Remove '${{ inputs.label }}' label From a6e12811b82df1ea6e0315f41020a6b4ebf7422b Mon Sep 17 00:00:00 2001 From: Anthony Islas Date: Thu, 12 Dec 2024 13:53:35 -0700 Subject: [PATCH 3/5] Comment out skipped step for now --- .github/workflows/ci.yml | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 62521047f9..7cf4c5e8bc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -118,20 +118,21 @@ jobs: statuses: write name : Test ${{ matrix.testSet.name }} on ${{ matrix.testSet.host }} - # In the event that 'all-tests' is used, this final job will be the one to remove - # the label from the PR - removeAllLabel : - if : ${{ !cancelled() && github.event.label.name == 'all-tests' }} - name : Remove 'all-tests' label - runs-on: ubuntu-latest - needs : [ buildtests ] # Put tests here to make this wait for the tests to complete - steps: - - name : Remove '${{ github.event.label.name }}' label - env: - PR_NUMBER: ${{ github.event.number }} - run: | - curl \ - -X DELETE \ - -H "Accept: application/vnd.github.v3+json" \ - -H 'Authorization: token ${{ github.token }}' \ - https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/labels/${{ github.event.label.name }} + + # # In the event that 'all-tests' is used, this final job will be the one to remove + # # the label from the PR + # removeAllLabel : + # if : ${{ !cancelled() && github.event.label.name == 'all-tests' }} + # name : Remove 'all-tests' label + # runs-on: ubuntu-latest + # needs : [ buildtests ] # Put tests here to make this wait for the tests to complete + # steps: + # - name : Remove '${{ github.event.label.name }}' label + # env: + # PR_NUMBER: ${{ github.event.number }} + # run: | + # curl \ + # -X DELETE \ + # -H "Accept: application/vnd.github.v3+json" \ + # -H 'Authorization: token ${{ github.token }}' \ + # https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/labels/${{ github.event.label.name }} From 371998e5defd1c6f8a71468b83397ea3bb87cfdc Mon Sep 17 00:00:00 2001 From: Anthony Islas Date: Thu, 12 Dec 2024 13:54:14 -0700 Subject: [PATCH 4/5] Create proxy workflow to act as label/ci/cd trigger entry point --- .github/workflows/entry_point.yml | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/entry_point.yml diff --git a/.github/workflows/entry_point.yml b/.github/workflows/entry_point.yml new file mode 100644 index 0000000000..ace2743add --- /dev/null +++ b/.github/workflows/entry_point.yml @@ -0,0 +1,43 @@ +name: Regression Suite Entry Point CI/CD +run-name : Queue ${{ github.event_name == 'push' && 'CI' || github.event.label.name }} (${{ github.event_name }}) + +on: + push: + branches: [ master, develop ] +# See https://stackoverflow.com/a/78444521 and +# https://github.com/orgs/community/discussions/26874#discussioncomment-3253755 +# as well as official (but buried) documentation : +# https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#pull-request-events-for-forked-repositories-2 + pull_request: + types: [ labeled ] + +# Write our tests out this way for easier legibility +# testsSet : +# - key : value +# key : value +# tests : +# - value +# - value +# - < next test > +# https://stackoverflow.com/a/68940067 +jobs: + queue_tests: + if : ${{ contains( fromJson('["compile-tests","all-tests"]'), github.event.label.name ) || github.event_name == 'push' }} + name: Queue Test (${{ github.event_name == 'push' && github.ref_name || github.event.label.name }}) + runs-on: ubuntu-latest + permissions: + actions: write + steps: + - name: Test + run : | + echo "Hello World!" + curl -L \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${{ github.token }}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/workflows/ci.yml/dispatches \ + -d '{"ref":"${{ github.head_ref }}","inputs":{"event_name":"${{ github.event_name }}", "event_number" : "${{ github.event.number }}", "test":"${{ github.event.label.name }}", "ref":"${{ github.ref }}"}}' + + + From d53ef5110308f8de99ac42c9478fda91730fc673 Mon Sep 17 00:00:00 2001 From: Anthony Islas Date: Thu, 12 Dec 2024 15:03:41 -0700 Subject: [PATCH 5/5] Try to use pr merge ref --- .github/workflows/entry_point.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/entry_point.yml b/.github/workflows/entry_point.yml index ace2743add..cbec4f3bde 100644 --- a/.github/workflows/entry_point.yml +++ b/.github/workflows/entry_point.yml @@ -37,7 +37,7 @@ jobs: -H "Authorization: Bearer ${{ github.token }}" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/workflows/ci.yml/dispatches \ - -d '{"ref":"${{ github.head_ref }}","inputs":{"event_name":"${{ github.event_name }}", "event_number" : "${{ github.event.number }}", "test":"${{ github.event.label.name }}", "ref":"${{ github.ref }}"}}' + -d '{"ref":"${{ github.event_name == 'push' && github.ref_name || github.event.pull_request.head.ref }}","inputs":{"event_name":"${{ github.event_name }}", "event_number" : "${{ github.event.number }}", "test":"${{ github.event.label.name }}", "ref":"${{ github.ref }}"}}'