From 1dff47741cfa83bf896ecc9e84fcec1bae502c01 Mon Sep 17 00:00:00 2001
From: Trevor Gross <tmgross@umich.edu>
Date: Sat, 28 Dec 2024 23:22:30 +0000
Subject: [PATCH] Add a `success` job to CI for branch protection

---
 .github/workflows/rust.yml | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index 054f897..8f3901c 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -49,3 +49,17 @@ jobs:
         rustup update --no-self-update
 
     - run: cargo build
+
+  success:
+    needs:
+      - test
+      - msrv
+    runs-on: ubuntu-latest
+    # GitHub branch protection is exceedingly silly and treats "jobs skipped because a dependency
+    # failed" as success. So we have to do some contortions to ensure the job fails if any of its
+    # dependencies fails.
+    if: always() # make sure this is never "skipped"
+    steps:
+      # Manually check the status of all dependencies. `if: failure()` does not work.
+      - name: check if any dependency failed
+        run: jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}'