Skip to content

Commit

Permalink
update PR workflows to use concurrency
Browse files Browse the repository at this point in the history
The pr-recieve and pr-comment workflows now use concurrencey
<https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency>
to cancel in-progress workflow runs if a new workflow run is started.
This will prevent situations like
<carpentries/lesson-development-training#165 (comment)>
from happening.

This PR will fix #374
  • Loading branch information
zkamvar committed Dec 16, 2022
1 parent 391dbae commit 4b120aa
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
@@ -1,6 +1,6 @@
Package: sandpaper
Title: Create and Curate Carpentries Lessons
Version: 0.11.2
Version: 0.11.3
Authors@R: c(
person(given = "Zhian N.",
family = "Kamvar",
Expand Down
13 changes: 13 additions & 0 deletions NEWS.md
@@ -1,3 +1,16 @@
# sandpaper 0.11.3

CONTINUOUS INTEGRATION
----------------------

* Pull Request workflows will now automatically cancel if several commits are
sent in succession. Specifically, the workflows `pr-recieve.yaml` and
`pr-comment.yaml` are given separate `concurrency` parameters based on the
branch name and the pull request number. These concurrencies will prevent
false alarms as found in
<https://github.com/carpentries/lesson-development-training/pull/165#issuecomment-1337182275>.
(discovered: @anenadic; reported: @zkamvar, #374; fixed: @zkamvar, #376)

# sandpaper 0.11.2

MISC
Expand Down
9 changes: 7 additions & 2 deletions inst/workflows/README.md
Expand Up @@ -147,6 +147,11 @@ pull request. GitHub has safeguarded the token used in this workflow to have no
priviledges in the repository, but we have taken precautions to protect against
spoofing.

This workflow is triggered with every push to a pull request. If this workflow
is already running and a new push is sent to the pull request, the workflow
running from the previous push will be cancelled and a new workflow run will be
started.

The first step of this workflow is to check if it is valid (e.g. that no
workflow files have been modified). If there are workflow files that have been
modified, a comment is made that indicates that the workflow is not run. If
Expand All @@ -160,7 +165,7 @@ request. This builds the content and uploads three artifacts:
3. The rendered files (build)

Because this workflow builds generated content, it follows the same general
process as the sandpaper-main workflow with the same caching mechanisms.
process as the `sandpaper-main` workflow with the same caching mechanisms.

The artifacts produced are used by the next workflow.

Expand All @@ -176,7 +181,7 @@ The steps in this workflow are:
3. If it is valid: update the pull request comment with the summary of changes

Importantly: if the pull request is invalid, the branch is not created so any
malicious code is not published.
malicious code is not published.

From here, the maintainer can request changes from the author and eventually
either merge or reject the PR. When this happens, if the PR was valid, the
Expand Down
5 changes: 5 additions & 0 deletions inst/workflows/pr-comment.yaml
Expand Up @@ -8,6 +8,11 @@ on:
types:
- completed

concurrency:
group: pr-${{ github.event.workflow_run.pull_requests[0].number }}
cancel-in-progress: true


jobs:
# Pull requests are valid if:
# - they match the sha of the workflow run head commit
Expand Down
4 changes: 4 additions & 0 deletions inst/workflows/pr-receive.yaml
Expand Up @@ -5,6 +5,10 @@ on:
types:
[opened, synchronize, reopened]

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

jobs:
test-pr:
name: "Record PR number"
Expand Down

0 comments on commit 4b120aa

Please sign in to comment.