Cancel workflow(s) on PR being closed/merged

For our open-source framework Trixi.jl we use a CI workflow Documenter.yml to auto-build documentation and deploy it to GH Pages. Next to official releases and the current main, we also auto-build documentation previews for PRs. These previews get cleaned up (i.e., the respective folder is removed from the gh-pages branch) once a PR is closed/merged using the DocPreviewCleanup.yml workflow.

However, there are situations that can cause a race condition. Specifically, if a PR is merged/closed before the documentation preview has been deployed, it can be that the Documenter.yml workflow is still running when the DocPreviewCleanup.yml is triggered. In that case, the documentation preview still gets added, since the cleanup workflow has already finished by the time the documentation is ready.

Is there a way we can prevent this from happening? The easiest way to achieve this would be IMHO to have the DocPreviewCleanup.yml workflow all currently running/queued/pending Documenter.yml for the same PR. Another way could be to make the cleanup workflow depend on all Documenter.yml workflows being finished. In both cases, I don’t know if this is even possible with GH Actions and how I could go about to implement it, thus any input or ideas are highly appreciated!