release_nightly.rs

  1use crate::tasks::workflows::{
  2    nix_build::build_nix,
  3    release::{
  4        ReleaseBundleJobs, create_sentry_release, download_workflow_artifacts, notify_on_failure,
  5        prep_release_artifacts,
  6    },
  7    run_bundling::{bundle_linux, bundle_mac, bundle_windows},
  8    run_tests::run_platform_tests,
  9    runners::{Arch, Platform, ReleaseChannel},
 10    steps::{FluentBuilder, NamedJob},
 11};
 12
 13use super::{runners, steps, steps::named, vars};
 14use gh_workflow::*;
 15
 16/// Generates the release_nightly.yml workflow
 17pub fn release_nightly() -> Workflow {
 18    let style = check_style();
 19    // run only on windows as that's our fastest platform right now.
 20    let tests = run_platform_tests(Platform::Windows);
 21    let nightly = Some(ReleaseChannel::Nightly);
 22
 23    let bundle = ReleaseBundleJobs {
 24        linux_aarch64: bundle_linux(Arch::AARCH64, nightly, &[&style, &tests]),
 25        linux_x86_64: bundle_linux(Arch::X86_64, nightly, &[&style, &tests]),
 26        mac_aarch64: bundle_mac(Arch::AARCH64, nightly, &[&style, &tests]),
 27        mac_x86_64: bundle_mac(Arch::X86_64, nightly, &[&style, &tests]),
 28        windows_aarch64: bundle_windows(Arch::AARCH64, nightly, &[&style, &tests]),
 29        windows_x86_64: bundle_windows(Arch::X86_64, nightly, &[&style, &tests]),
 30    };
 31
 32    let nix_linux_x86 = build_nix(
 33        Platform::Linux,
 34        Arch::X86_64,
 35        "default",
 36        None,
 37        &[&style, &tests],
 38    );
 39    let nix_mac_arm = build_nix(
 40        Platform::Mac,
 41        Arch::AARCH64,
 42        "default",
 43        None,
 44        &[&style, &tests],
 45    );
 46    let update_nightly_tag = update_nightly_tag_job(&bundle);
 47    let notify_on_failure = notify_on_failure(&bundle.jobs());
 48
 49    named::workflow()
 50        .on(Event::default()
 51            // Fire every day at 7:00am UTC (Roughly before EU workday and after US workday)
 52            .schedule([Schedule::new("0 7 * * *")])
 53            .push(Push::default().add_tag("nightly")))
 54        .add_env(("CARGO_TERM_COLOR", "always"))
 55        .add_env(("RUST_BACKTRACE", "1"))
 56        .add_job(style.name, style.job)
 57        .add_job(tests.name, tests.job)
 58        .map(|mut workflow| {
 59            for job in bundle.into_jobs() {
 60                workflow = workflow.add_job(job.name, job.job);
 61            }
 62            workflow
 63        })
 64        .add_job(nix_linux_x86.name, nix_linux_x86.job)
 65        .add_job(nix_mac_arm.name, nix_mac_arm.job)
 66        .add_job(update_nightly_tag.name, update_nightly_tag.job)
 67        .add_job(notify_on_failure.name, notify_on_failure.job)
 68}
 69
 70fn check_style() -> NamedJob {
 71    let job = release_job(&[])
 72        .runs_on(runners::MAC_DEFAULT)
 73        .add_step(
 74            steps::checkout_repo()
 75                .add_with(("clean", false))
 76                .add_with(("fetch-depth", 0)),
 77        )
 78        .add_step(steps::cargo_fmt())
 79        .add_step(steps::script("./script/clippy"));
 80
 81    named::job(job)
 82}
 83
 84fn release_job(deps: &[&NamedJob]) -> Job {
 85    let job = Job::default()
 86        .cond(Expression::new(
 87            "github.repository_owner == 'zed-industries'",
 88        ))
 89        .timeout_minutes(60u32);
 90    if deps.len() > 0 {
 91        job.needs(deps.iter().map(|j| j.name.clone()).collect::<Vec<_>>())
 92    } else {
 93        job
 94    }
 95}
 96
 97fn update_nightly_tag_job(bundle: &ReleaseBundleJobs) -> NamedJob {
 98    fn update_nightly_tag() -> Step<Run> {
 99        named::bash(indoc::indoc! {r#"
100            if [ "$(git rev-parse nightly)" = "$(git rev-parse HEAD)" ]; then
101              echo "Nightly tag already points to current commit. Skipping tagging."
102              exit 0
103            fi
104            git config user.name github-actions
105            git config user.email github-actions@github.com
106            git tag -f nightly
107            git push origin nightly --force
108        "#})
109    }
110
111    NamedJob {
112        name: "update_nightly_tag".to_owned(),
113        job: steps::release_job(&bundle.jobs())
114            .runs_on(runners::LINUX_MEDIUM)
115            .add_step(steps::checkout_repo().add_with(("fetch-depth", 0)))
116            .add_step(download_workflow_artifacts())
117            .add_step(steps::script("ls -lR ./artifacts"))
118            .add_step(prep_release_artifacts())
119            .add_step(
120                steps::script("./script/upload-nightly")
121                    .add_env((
122                        "DIGITALOCEAN_SPACES_ACCESS_KEY",
123                        vars::DIGITALOCEAN_SPACES_ACCESS_KEY,
124                    ))
125                    .add_env((
126                        "DIGITALOCEAN_SPACES_SECRET_KEY",
127                        vars::DIGITALOCEAN_SPACES_SECRET_KEY,
128                    )),
129            )
130            .add_step(update_nightly_tag())
131            .add_step(create_sentry_release()),
132    }
133}