summaryrefslogtreecommitdiffstats
path: root/tests/github-actions.rs
blob: c902f10bfd622a4188d4145826d980075b327801 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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::<Vec<_>>();

    // Make sure they match
    assert_eq!(
        *actual, expected,
        "`all-jobs` should depend on all other jobs"
    );
}