From 42d226f727fa26ba908d1bc66bbc3fdfde679289 Mon Sep 17 00:00:00 2001
From: David Taylor <david@taylorhq.com>
Date: Wed, 21 Sep 2022 14:32:21 +0100
Subject: [PATCH] DEV: Ensure GitHub workflows cancel cleanly (#18314)

We added `always()` on some steps so that they run even if previous steps fail. That helps give us a picture of all failures in one run, rather than having to re-run the workflow after fixing the first failure.

However, when we explicitly cancel a job, we should skip running these steps. `!cancelled()` is a better substitute for `always()` in this case.
---
 .github/workflows/licenses.yml |  6 +++---
 .github/workflows/linting.yml  | 14 +++++++-------
 .github/workflows/tests.yml    |  6 +++---
 3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/.github/workflows/licenses.yml b/.github/workflows/licenses.yml
index 755852add28..adefc3998c4 100644
--- a/.github/workflows/licenses.yml
+++ b/.github/workflows/licenses.yml
@@ -67,7 +67,7 @@ jobs:
             ${{ runner.os }}-yarn-
 
       - name: Check RubyGems Licenses
-        if: ${{ always() }}
+        if: ${{ !cancelled() }}
         run: |
           licensed cache
           licensed status
@@ -76,14 +76,14 @@ jobs:
         run: yarn install
 
       - name: Check Yarn Licenses
-        if: ${{ always() }}
+        if: ${{ !cancelled() }}
         run: |
           yarn global add licensee
           yarn global upgrade licensee
           licensee --errors-only
 
       - name: Check Ember CLI Workspace Licenses
-        if: ${{ always() }}
+        if: ${{ !cancelled() }}
         working-directory: ./app/assets/javascripts
         run: |
           licensee --errors-only
diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml
index 3ce7b5d5f30..59379f06aff 100644
--- a/.github/workflows/linting.yml
+++ b/.github/workflows/linting.yml
@@ -64,19 +64,19 @@ jobs:
         run: yarn install
 
       - name: Rubocop
-        if: ${{ always() }}
+        if: ${{ !cancelled() }}
         run: bundle exec rubocop --parallel .
 
       - name: ESLint (core)
-        if: ${{ always() }}
+        if: ${{ !cancelled() }}
         run: yarn eslint app/assets/javascripts
 
       - name: ESLint (core plugins)
-        if: ${{ always() }}
+        if: ${{ !cancelled() }}
         run: yarn eslint plugins
 
       - name: Prettier
-        if: ${{ always() }}
+        if: ${{ !cancelled() }}
         run: |
           yarn prettier -v
           yarn pprettier --list-different \
@@ -86,7 +86,7 @@ jobs:
             "plugins/**/assets/javascripts/**/*.js"
 
       - name: Ember template lint
-        if: ${{ always() }}
+        if: ${{ !cancelled() }}
         run: |
           yarn ember-template-lint \
             --no-error-on-unmatched-pattern \
@@ -94,9 +94,9 @@ jobs:
             "plugins/**/assets/javascripts/**/*.hbs"
 
       - name: English locale lint (core)
-        if: ${{ always() }}
+        if: ${{ !cancelled() }}
         run: bundle exec ruby script/i18n_lint.rb "config/**/locales/{client,server}.en.yml"
 
       - name: English locale lint (core plugins)
-        if: ${{ always() }}
+        if: ${{ !cancelled() }}
         run: bundle exec ruby script/i18n_lint.rb "plugins/**/locales/{client,server}.en.yml"
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index bf9a71716a5..199b99c208d 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -220,19 +220,19 @@ jobs:
           sudo -E -u discourse -H yarn ember build --environment=test  -o /tmp/emberbuild
 
       - name: Core QUnit 1
-        if: ${{ always() }}
+        if: ${{ !cancelled() }}
         working-directory: ./app/assets/javascripts/discourse
         run: sudo -E -u discourse -H yarn ember exam --path /tmp/emberbuild --split=3 --partition=1 --launch "${{ matrix.browser }}" --random
         timeout-minutes: 15
 
       - name: Core QUnit 2
-        if: ${{ always() }}
+        if: ${{ !cancelled() }}
         working-directory: ./app/assets/javascripts/discourse
         run: sudo -E -u discourse -H yarn ember exam --path /tmp/emberbuild --split=3 --partition=2 --launch "${{ matrix.browser }}" --random
         timeout-minutes: 15
 
       - name: Core QUnit 3
-        if: ${{ always() }}
+        if: ${{ !cancelled() }}
         working-directory: ./app/assets/javascripts/discourse
         run: sudo -E -u discourse -H yarn ember exam --path /tmp/emberbuild --split=3 --partition=3 --launch "${{ matrix.browser }}" --random
         timeout-minutes: 15