Skip to content

Commit

Permalink
Provide an entry point for trigger events to facilitate dispatch work…
Browse files Browse the repository at this point in the history
…flow

This simple entry point workflow should funnel event webhooks
to the dispatch workflow IF the event is deemed an actual test
event. This combined with the decoupled dispatch workflow is
how PRs will still be able to trigger testing without needing
manual running of the dispatch workflow. Likewise, it will stop
unnecessary skipped job statuses from showing up on the PR.

The status of this workflow will inevitably be constantly
overriden from multiple label events, but the published
commit status of the dispatch workflow, if queued, will
provide the handle to the run via a target_url.

Since the workflow_dispatch webhook event cannot take a
pull request merge ref, certain measures must be taken to
allow running the workflow in a valid context. For PRs
originating from forks, it is impossible to run the workflow
in the parent repo using the head ref as that branch exists
in a different repo. In this case we will run the base ref
of the PR. This has the added benefit of security, ensuring
the runners never run workflows from outside sources.
Unfortunately, this would limit critical patches to the
workflow from being demonstated within a PR. To allow for
this use case, when a PR from an internal repo branch is
used, the dispatch event will be made using the PR branch
head ref, thus running the changes.

This paradigm will also guarantee that the workflow_dispatch
will only ever use internal refs, increasing security and
allowing label modifications.
  • Loading branch information
islas committed Dec 14, 2024
1 parent c22e2a1 commit 91f918b
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/entry_point.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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: Dispatch Regression Suite
run : |
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 \
--data-binary @- << EOF
{
"ref" : "${{ github.event_name == 'push' && github.ref_name || github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.head.ref || github.event.pull_request.base.ref }}",
"inputs" :
{
"event_name" : "${{ github.event_name }}",
"event_number" : "${{ github.event.number }}",
"test" : "${{ github.event.label.name }}",
"ref" : "${{ github.ref }}",
"sha" : "${{ github.event_name == 'push' && github.sha || github.event.pull_request.head.sha }}"
}
}
EOF

0 comments on commit 91f918b

Please sign in to comment.