Experiment 7

There are times when you may need to cancel any currently running workflow within the same concurrency group. To do this, simply set cancel-in-progress: true.

1. Make sure you are still in the right project folder.

cd path/to/experiment-5-6-7

2. In the .github/workflows/main.yml file, add cancel-in-progress: true setting for concurrency group.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
name: main

on:
  push:
    branches: ["main"]

concurrency:
  group: main
  cancel-in-progress: true

jobs:
  run-test:
    runs-on: ubuntu-latest
    steps:
      - name: Extend the workflow duration by an additional 300 seconds.
        run: sleep 300

3. Modify the README.md file with the following content.

echo "experiment 7: the first workflow execution!" > README.md

4. Make another commit and push to the remote repository.

git add . && git commit -m "experiment 7: the first workflow execution" && git push

5. On your remote repository, click the Actions tab, you should see that a workflow execution has been triggered.

0001

6. On your local repository, update the README.md file with the following content.

echo "experiment 7: the second workflow execution!" > README.md

7. Make another commit and push to the remote repository.

git add . && git commit -m "experiment 7: the second workflow execution" && git push

8. On your remote repository, under the Actions tab, you may notice that the first workflow execution has been canceled, while the second workflow is now running.

0002

Throughout the experiments, leveraging a concurrency group proves beneficial, allowing you to run a single workflow at a time. This is particularly useful for managing your account’s or organization’s resources, especially in situations where running multiple workflows simultaneously could lead to conflicts or unexpectedly high consumption of Actions minutes and storage.