In Github Actions, how can the on: delete be tested?

From the documentation
Note: This event will only trigger a workflow run if the workflow file is on the master or default branch.”

How is it possible to ever test a “delete” workflow, when it only runs if the file already exists in the default branch? Are we supposed to just merge in the delete workflow file and hope for the best?

There are few points you need to understand:

  1. Every workflow run must and only have one Git ref (github.ref: a branch ref or a tag ref). If you want a workflow runs on a branch ref, this branch must be existing in the repository, and GitHub will only reference the configurations defined in the workflow file from this branch to execute the workflow.

  2. When deleting a branch to trigger the workflow runs on the delete event, the deleted branch has not existed in the repository, GitHub can’t reference the workflow file from the deleted branch to execute the workflow. So it defaults to only reference workflow file from the master or default branch, because the master or default branch is not allowed to be deleted. This will ensure that certain events (such as delete and schedule) can steadily trigger workflows in the repository without being affected by some other events (such as branches or tags are deleted).