From 6baebd79fa9562bce3ff6549a4f3c9cc3c767cf1 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Thu, 12 Oct 2023 05:39:47 +0200 Subject: [PATCH] Add test for what jobs 'all-jobs' references --- tests/github-actions.rs | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/github-actions.rs diff --git a/tests/github-actions.rs b/tests/github-actions.rs new file mode 100644 index 00000000..c902f10b --- /dev/null +++ b/tests/github-actions.rs @@ -0,0 +1,53 @@ +#[test] +fn all_jobs_not_missing_any_jobs() { + let yaml: serde_yaml::Value = + serde_yaml::from_reader(std::fs::File::open(".github/workflows/CICD.yml").unwrap()) + .unwrap(); + let jobs = yaml.get("jobs").unwrap(); + + // Get all jobs that all-jobs depends on: + // + // jobs: + // all-jobs: + // needs: + // - this + // - list + // - ... + let actual = jobs + .get("all-jobs") + .unwrap() + .get("needs") + .unwrap() + .as_sequence() + .unwrap(); + + // Get all jobs used in CI, except the ones we want to ignore: + // + // jobs: + // this: ... + // list: ... + // ... + let exceptions = [ + "all-jobs", // 'all-jobs' should not reference itself + "winget", // only used when publishing a release + ]; + let expected = jobs + .as_mapping() + .unwrap() + .keys() + .filter_map(|k| { + if exceptions.contains(&k.as_str().unwrap_or_default()) { + None + } else { + Some(k) + } + }) + .map(ToOwned::to_owned) + .collect::>(); + + // Make sure they match + assert_eq!( + *actual, expected, + "`all-jobs` should depend on all other jobs" + ); +}