compliance_check.rs

 1use gh_workflow::{Event, Job, Schedule, Workflow, WorkflowDispatch};
 2
 3use crate::tasks::workflows::{
 4    release::{ComplianceContext, add_compliance_steps},
 5    runners,
 6    steps::{self, CommonJobConditions, named},
 7    vars::StepOutput,
 8};
 9
10pub fn compliance_check() -> Workflow {
11    let check = scheduled_compliance_check();
12
13    named::workflow()
14        .on(Event::default()
15            .schedule([Schedule::new("30 17 * * 2")])
16            .workflow_dispatch(WorkflowDispatch::default()))
17        .add_env(("CARGO_TERM_COLOR", "always"))
18        .add_job(check.name, check.job)
19}
20
21fn scheduled_compliance_check() -> steps::NamedJob {
22    let determine_version_step = named::bash(indoc::indoc! {r#"
23        VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' crates/zed/Cargo.toml | tr -d '[:space:]')
24        if [ -z "$VERSION" ]; then
25            echo "Could not determine version from crates/zed/Cargo.toml"
26            exit 1
27        fi
28        TAG="v${VERSION}-pre"
29        echo "Checking compliance for $TAG"
30        echo "tag=$TAG" >> "$GITHUB_OUTPUT"
31    "#})
32    .id("determine-version");
33
34    let tag_output = StepOutput::new(&determine_version_step, "tag");
35
36    let job = Job::default()
37        .with_repository_owner_guard()
38        .runs_on(runners::LINUX_SMALL)
39        .add_step(steps::checkout_repo().with_full_history())
40        .add_step(steps::cache_rust_dependencies_namespace())
41        .add_step(determine_version_step);
42
43    named::job(
44        add_compliance_steps(
45            job,
46            ComplianceContext::Scheduled {
47                tag_source: tag_output,
48            },
49        )
50        .0,
51    )
52}