1use gh_workflow::*;
 2
 3use crate::tasks::workflows::steps::{NamedJob, named};
 4
 5use super::{runners, steps};
 6
 7/// Generates the danger.yml workflow
 8pub fn danger() -> Workflow {
 9    let danger = danger_job();
10
11    named::workflow()
12        .on(
13            Event::default().pull_request(PullRequest::default().add_branch("main").types([
14                PullRequestType::Opened,
15                PullRequestType::Synchronize,
16                PullRequestType::Reopened,
17                PullRequestType::Edited,
18            ])),
19        )
20        .add_job(danger.name, danger.job)
21}
22
23fn danger_job() -> NamedJob {
24    pub fn install_deps() -> Step<Run> {
25        named::bash("pnpm install --dir script/danger")
26    }
27
28    pub fn run() -> Step<Run> {
29        named::bash("pnpm run --dir script/danger danger ci")
30            // This GitHub token is not used, but the value needs to be here to prevent
31            // Danger from throwing an error.
32            .add_env(("GITHUB_TOKEN", "not_a_real_token"))
33            // All requests are instead proxied through an instance of
34            // https://github.com/maxdeviant/danger-proxy that allows Danger to securely
35            // authenticate with GitHub while still being able to run on PRs from forks.
36            .add_env((
37                "DANGER_GITHUB_API_BASE_URL",
38                "https://danger-proxy.fly.dev/github",
39            ))
40    }
41
42    NamedJob {
43        name: "danger".to_string(),
44        job: Job::default()
45            .cond(Expression::new(
46                "github.repository_owner == 'zed-industries'",
47            ))
48            .runs_on(runners::LINUX_SMALL)
49            .add_step(steps::checkout_repo())
50            .add_step(steps::setup_pnpm())
51            .add_step(
52                steps::setup_node()
53                    .add_with(("cache", "pnpm"))
54                    .add_with(("cache-dependency-path", "script/danger/pnpm-lock.yaml")),
55            )
56            .add_step(install_deps())
57            .add_step(run()),
58    }
59}