[ci] cancel previous jobs for pull requests (#958)

* cancel previous jobs for pull requests

In short, this cancels previous jobs for PRs but not for the `master` branch.

* empty for testing

* fix

* empty for testing
diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml
index f9381cb..351ac6c 100644
--- a/.github/workflows/build-and-publish.yml
+++ b/.github/workflows/build-and-publish.yml
@@ -30,6 +30,10 @@
         required: true
         default: "master"
 
+concurrency:
+  group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}-${{ github.event_name != 'pull_request' && github.sha || '' }}
+  cancel-in-progress: true
+
 jobs:
   macos-built-distributions:
     name: Build macOS wheels
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 8ff3bbc..64fee33 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -8,6 +8,10 @@
     branches:
       - '**'
 
+concurrency:
+  group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}-${{ github.event_name != 'pull_request' && github.sha || '' }}
+  cancel-in-progress: true
+
 jobs:
   tox:
     name: ${{ matrix.tox.name }} ${{ matrix.os.emoji }} ${{ matrix.os.name }} ${{ matrix.python }}