sensu / bonsai

Apache License 2.0
1 stars 7 forks source link

Enhancement: Change webhook logic to look for completed workflow_job #361

Closed jspaleta closed 2 years ago

jspaleta commented 2 years ago

Problem Statement

We want to be able to have a GitHub Actions workflow kick off a Bonsai asset recompile. The current webhook approach is racy, because the release event it relies on comes before all the asset builds are uploaded into the GitHub release, causing recompile errors and forcing people to manually recompile.

The new build/ api approach requires personal access tokens to be generated, which is cumbersome as it can't be fully automated. The generated GitHub Action tokens aren't tied to a user, so fail the collaborator check we have in place. And ther doesn't appear to be a way to figure out that a specific token is a GitHub Action token.

Possible Solution

Refactor the webhook logic to trigger on completed workload_job events with a specific workload name.

Ref: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#workflow_job

Straw Implementation

Bonsai refactor

  1. Refactor automatic webhook generation to create a repository webhook that subscribes to workflow_job events instead of release events
  2. Add logic on recieving a workflow_job event check that the job name is "bonsai-recompile" the event action is completed and if so kick off a recompile request for the repository listed in the workflow_job event

    GitHub Action refactor

  3. Have GitHub Action logic that runs a "bonsai-recompile" job after successful release workflow.