extension_ci: Increase fetch depth for tests job (#49389)

Finn Evers created

We need more fetch depth here for the check, hence bumping this.

Also does a drive-by cleanup of the checkout step within xtask to make
this (hopefully) more intuitive to use.

Release Notes:

- N/A

Change summary

.github/workflows/autofix_pr.yml                                |   2 
.github/workflows/bump_patch_version.yml                        |   2 
.github/workflows/extension_tests.yml                           |   1 
.github/workflows/extension_workflow_rollout.yml                |  10 
.github/workflows/run_tests.yml                                 |   3 
tooling/xtask/src/tasks/workflows/autofix_pr.rs                 |   2 
tooling/xtask/src/tasks/workflows/bump_patch_version.rs         |   8 
tooling/xtask/src/tasks/workflows/deploy_collab.rs              |   4 
tooling/xtask/src/tasks/workflows/extension_bump.rs             |   2 
tooling/xtask/src/tasks/workflows/extension_tests.rs            |   2 
tooling/xtask/src/tasks/workflows/extension_workflow_rollout.rs |  23 
tooling/xtask/src/tasks/workflows/release.rs                    |   5 
tooling/xtask/src/tasks/workflows/release_nightly.rs            |   8 
tooling/xtask/src/tasks/workflows/run_tests.rs                  |  12 
tooling/xtask/src/tasks/workflows/steps.rs                      | 114 ++
15 files changed, 135 insertions(+), 63 deletions(-)

Detailed changes

.github/workflows/autofix_pr.yml 🔗

@@ -98,7 +98,7 @@ jobs:
       with:
         app-id: ${{ secrets.ZED_ZIPPY_APP_ID }}
         private-key: ${{ secrets.ZED_ZIPPY_APP_PRIVATE_KEY }}
-    - name: steps::checkout_repo_with_token
+    - name: steps::checkout_repo
       uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
       with:
         clean: false

.github/workflows/bump_patch_version.yml 🔗

@@ -19,7 +19,7 @@ jobs:
       with:
         app-id: ${{ secrets.ZED_ZIPPY_APP_ID }}
         private-key: ${{ secrets.ZED_ZIPPY_APP_PRIVATE_KEY }}
-    - name: steps::checkout_repo_with_token
+    - name: steps::checkout_repo
       uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
       with:
         clean: false

.github/workflows/extension_tests.yml 🔗

@@ -86,6 +86,7 @@ jobs:
       uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
       with:
         clean: false
+        fetch-depth: ${{ github.ref == 'refs/heads/main' && 2 || 350 }}
     - id: cache-zed-extension-cli
       name: extension_tests::cache_zed_extension_cli
       uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830

.github/workflows/extension_workflow_rollout.yml 🔗

@@ -56,15 +56,15 @@ jobs:
       uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
       with:
         clean: false
+        fetch-depth: 0
         path: zed
-        fetch-depth: '0'
-    - name: steps::checkout_repo_with_token
+    - name: checkout_extension_repo
       uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
       with:
         clean: false
         token: ${{ steps.generate-token.outputs.token }}
-        repository: zed-extensions/${{ matrix.repo }}
         path: extension
+        repository: zed-extensions/${{ matrix.repo }}
     - id: prev-tag
       name: extension_workflow_rollout::rollout_workflows_to_extension::get_previous_tag_commit
       run: |
@@ -167,12 +167,12 @@ jobs:
         app-id: ${{ secrets.ZED_ZIPPY_APP_ID }}
         private-key: ${{ secrets.ZED_ZIPPY_APP_PRIVATE_KEY }}
         permission-contents: write
-    - name: steps::checkout_repo_with_token
+    - name: steps::checkout_repo
       uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
       with:
         clean: false
+        fetch-depth: 0
         token: ${{ steps.generate-token.outputs.token }}
-        fetch-depth: '0'
     - name: extension_workflow_rollout::create_rollout_tag::configure_git
       run: |
         git config user.name "zed-zippy[bot]"

.github/workflows/run_tests.yml 🔗

@@ -605,9 +605,8 @@ jobs:
     - name: steps::checkout_repo
       uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
       with:
+        clean: false
         fetch-depth: 0
-    - name: run_tests::check_postgres_and_protobuf_migrations::remove_untracked_files
-      run: git clean -df
     - name: run_tests::check_postgres_and_protobuf_migrations::ensure_fresh_merge
       run: |
         if [ -z "$GITHUB_BASE_REF" ];

tooling/xtask/src/tasks/workflows/autofix_pr.rs 🔗

@@ -169,7 +169,7 @@ fn commit_changes(pr_number: &WorkflowInput, autofix_job: &NamedJob) -> NamedJob
                 autofix_job.name
             )))
             .add_step(authenticate)
-            .add_step(steps::checkout_repo_with_token(&token))
+            .add_step(steps::checkout_repo().with_token(&token))
             .add_step(checkout_pr(pr_number, &token))
             .add_step(download_patch_artifact())
             .add_step(apply_patch())

tooling/xtask/src/tasks/workflows/bump_patch_version.rs 🔗

@@ -2,7 +2,7 @@ use gh_workflow::*;
 
 use crate::tasks::workflows::{
     runners,
-    steps::{self, named},
+    steps::{self, CheckoutStep, named},
     vars::{StepOutput, WorkflowInput},
 };
 
@@ -22,8 +22,10 @@ pub fn bump_patch_version() -> Workflow {
 }
 
 fn run_bump_patch_version(branch: &WorkflowInput) -> steps::NamedJob {
-    fn checkout_branch(branch: &WorkflowInput, token: &StepOutput) -> Step<Use> {
-        steps::checkout_repo_with_token(token).add_with(("ref", branch.to_string()))
+    fn checkout_branch(branch: &WorkflowInput, token: &StepOutput) -> CheckoutStep {
+        steps::checkout_repo()
+            .with_token(token)
+            .with_ref(branch.to_string())
     }
 
     fn bump_patch_version(token: &StepOutput) -> Step<Run> {

tooling/xtask/src/tasks/workflows/deploy_collab.rs 🔗

@@ -28,7 +28,7 @@ fn style() -> NamedJob {
             .name("Check formatting and Clippy lints")
             .with_repository_owner_guard()
             .runs_on(runners::LINUX_XL)
-            .add_step(steps::checkout_repo().add_with(("fetch-depth", 0)))
+            .add_step(steps::checkout_repo().with_full_history())
             .add_step(steps::setup_cargo_config(Platform::Linux))
             .add_step(steps::cache_rust_dependencies_namespace())
             .map(steps::install_linux_dependencies)
@@ -58,7 +58,7 @@ fn tests(deps: &[&NamedJob]) -> NamedJob {
                          --health-retries 10",
                     ),
             )
-            .add_step(steps::checkout_repo().add_with(("fetch-depth", 0)))
+            .add_step(steps::checkout_repo().with_full_history())
             .add_step(steps::setup_cargo_config(Platform::Linux))
             .add_step(steps::cache_rust_dependencies_namespace())
             .map(steps::install_linux_dependencies)

tooling/xtask/src/tasks/workflows/extension_bump.rs 🔗

@@ -95,7 +95,7 @@ fn check_version_changed() -> (NamedJob, StepOutput, StepOutput) {
         ])
         .runs_on(runners::LINUX_SMALL)
         .timeout_minutes(1u32)
-        .add_step(steps::checkout_repo().add_with(("fetch-depth", 0)))
+        .add_step(steps::checkout_repo().with_full_history())
         .add_step(compare_versions);
 
     (named::job(job), version_changed, current_version)

tooling/xtask/src/tasks/workflows/extension_tests.rs 🔗

@@ -85,7 +85,7 @@ pub(crate) fn check_extension() -> NamedJob {
         .with_repository_owner_guard()
         .runs_on(runners::LINUX_LARGE_RAM)
         .timeout_minutes(4u32)
-        .add_step(steps::checkout_repo())
+        .add_step(steps::checkout_repo().with_deep_history_on_non_main())
         .add_step(cache_download)
         .add_step(download_zed_extension_cli(cache_hit))
         .add_step(check())

tooling/xtask/src/tasks/workflows/extension_workflow_rollout.rs 🔗

@@ -5,6 +5,7 @@ use indoc::formatdoc;
 use indoc::indoc;
 use serde_json::json;
 
+use crate::tasks::workflows::steps::CheckoutStep;
 use crate::tasks::workflows::{
     extension_bump::{RepositoryTarget, generate_token},
     runners,
@@ -67,17 +68,19 @@ fn fetch_extension_repos() -> NamedJob {
 }
 
 fn rollout_workflows_to_extension(fetch_repos_job: &NamedJob) -> NamedJob {
-    fn checkout_zed_repo() -> Step<Use> {
+    fn checkout_zed_repo() -> CheckoutStep {
         steps::checkout_repo()
-            .name("checkout_zed_repo")
-            .add_with(("path", "zed"))
-            .add_with(("fetch-depth", "0"))
+            .with_full_history()
+            .with_path("zed")
+            .with_custom_name("checkout_zed_repo")
     }
 
-    fn checkout_extension_repo(token: &StepOutput) -> Step<Use> {
-        steps::checkout_repo_with_token(token)
-            .add_with(("repository", "zed-extensions/${{ matrix.repo }}"))
-            .add_with(("path", "extension"))
+    fn checkout_extension_repo(token: &StepOutput) -> CheckoutStep {
+        steps::checkout_repo()
+            .with_custom_name("checkout_extension_repo")
+            .with_token(token)
+            .with_repository("zed-extensions/${{ matrix.repo }}")
+            .with_path("extension")
     }
 
     fn get_previous_tag_commit() -> (Step<Run>, StepOutput) {
@@ -253,8 +256,8 @@ fn rollout_workflows_to_extension(fetch_repos_job: &NamedJob) -> NamedJob {
 }
 
 fn create_rollout_tag(rollout_job: &NamedJob) -> NamedJob {
-    fn checkout_zed_repo(token: &StepOutput) -> Step<Use> {
-        steps::checkout_repo_with_token(token).add_with(("fetch-depth", "0"))
+    fn checkout_zed_repo(token: &StepOutput) -> CheckoutStep {
+        steps::checkout_repo().with_full_history().with_token(token)
     }
 
     fn update_rollout_tag() -> Step<Run> {

tooling/xtask/src/tasks/workflows/release.rs 🔗

@@ -254,9 +254,8 @@ fn create_draft_release() -> NamedJob {
             // 25 was chosen arbitrarily.
             .add_step(
                 steps::checkout_repo()
-                    .add_with(("fetch-depth", 25))
-                    .add_with(("clean", false))
-                    .add_with(("ref", "${{ github.ref }}")),
+                    .with_custom_fetch_depth(25)
+                    .with_ref("${{ github.ref }}"),
             )
             .add_step(steps::script("script/determine-release-channel"))
             .add_step(steps::script("mkdir -p target/"))

tooling/xtask/src/tasks/workflows/release_nightly.rs 🔗

@@ -72,11 +72,7 @@ pub fn release_nightly() -> Workflow {
 fn check_style() -> NamedJob {
     let job = release_job(&[])
         .runs_on(runners::MAC_DEFAULT)
-        .add_step(
-            steps::checkout_repo()
-                .add_with(("clean", false))
-                .add_with(("fetch-depth", 0)),
-        )
+        .add_step(steps::checkout_repo().with_full_history())
         .add_step(steps::cargo_fmt())
         .add_step(steps::script("./script/clippy"));
 
@@ -112,7 +108,7 @@ fn update_nightly_tag_job(bundle: &ReleaseBundleJobs) -> NamedJob {
         name: "update_nightly_tag".to_owned(),
         job: steps::release_job(&bundle.jobs())
             .runs_on(runners::LINUX_MEDIUM)
-            .add_step(steps::checkout_repo().add_with(("fetch-depth", 0)))
+            .add_step(steps::checkout_repo().with_full_history())
             .add_step(download_workflow_artifacts())
             .add_step(steps::script("ls -lR ./artifacts"))
             .add_step(prep_release_artifacts())

tooling/xtask/src/tasks/workflows/run_tests.rs 🔗

@@ -219,10 +219,7 @@ fn orchestrate_impl(rules: &[&PathCondition], include_package_filter: bool) -> N
         .runs_on(runners::LINUX_SMALL)
         .with_repository_owner_guard()
         .outputs(outputs)
-        .add_step(steps::checkout_repo().add_with((
-            "fetch-depth",
-            "${{ github.ref == 'refs/heads/main' && 2 || 350 }}",
-        )))
+        .add_step(steps::checkout_repo().with_deep_history_on_non_main())
         .add_step(Step::new(step_name.clone()).run(script).id(step_name));
 
     NamedJob { name, job }
@@ -442,10 +439,6 @@ fn run_platform_tests_impl(platform: Platform, filter_packages: bool) -> NamedJo
 }
 
 pub(crate) fn check_postgres_and_protobuf_migrations() -> NamedJob {
-    fn remove_untracked_files() -> Step<Run> {
-        named::bash("git clean -df")
-    }
-
     fn ensure_fresh_merge() -> Step<Run> {
         named::bash(indoc::indoc! {r#"
             if [ -z "$GITHUB_BASE_REF" ];
@@ -477,8 +470,7 @@ pub(crate) fn check_postgres_and_protobuf_migrations() -> NamedJob {
             .add_env(("GIT_AUTHOR_EMAIL", "ci@zed.dev"))
             .add_env(("GIT_COMMITTER_NAME", "Protobuf Action"))
             .add_env(("GIT_COMMITTER_EMAIL", "ci@zed.dev"))
-            .add_step(steps::checkout_repo().with(("fetch-depth", 0))) // fetch full history
-            .add_step(remove_untracked_files())
+            .add_step(steps::checkout_repo().with_full_history())
             .add_step(ensure_fresh_merge())
             .add_step(bufbuild_setup_action())
             .add_step(bufbuild_breaking_action()),

tooling/xtask/src/tasks/workflows/steps.rs 🔗

@@ -1,4 +1,5 @@
 use gh_workflow::*;
+use serde_json::Value;
 
 use crate::tasks::workflows::{runners::Platform, vars, vars::StepOutput};
 
@@ -49,25 +50,103 @@ impl From<Nextest> for Step<Run> {
     }
 }
 
-pub fn checkout_repo() -> Step<Use> {
-    named::uses(
-        "actions",
-        "checkout",
-        "11bd71901bbe5b1630ceea73d27597364c9af683", // v4
-    )
-    // prevent checkout action from running `git clean -ffdx` which
-    // would delete the target directory
-    .add_with(("clean", false))
+#[derive(Default)]
+enum FetchDepth {
+    #[default]
+    Shallow,
+    Full,
+    Custom(serde_json::Value),
 }
 
-pub fn checkout_repo_with_token(token: &StepOutput) -> Step<Use> {
-    named::uses(
-        "actions",
-        "checkout",
-        "11bd71901bbe5b1630ceea73d27597364c9af683", // v4
-    )
-    .add_with(("clean", false))
-    .add_with(("token", token.to_string()))
+#[derive(Default)]
+pub(crate) struct CheckoutStep {
+    fetch_depth: FetchDepth,
+    name: Option<String>,
+    token: Option<String>,
+    path: Option<String>,
+    repository: Option<String>,
+    ref_: Option<String>,
+}
+
+impl CheckoutStep {
+    pub fn with_full_history(mut self) -> Self {
+        self.fetch_depth = FetchDepth::Full;
+        self
+    }
+
+    pub fn with_custom_name(mut self, name: &str) -> Self {
+        self.name = Some(name.to_string());
+        self
+    }
+
+    pub fn with_custom_fetch_depth(mut self, fetch_depth: impl Into<Value>) -> Self {
+        self.fetch_depth = FetchDepth::Custom(fetch_depth.into());
+        self
+    }
+
+    /// Sets `fetch-depth` to `2` on the main branch and `350` on all other branches.
+    pub fn with_deep_history_on_non_main(self) -> Self {
+        self.with_custom_fetch_depth("${{ github.ref == 'refs/heads/main' && 2 || 350 }}")
+    }
+
+    pub fn with_token(mut self, token: &StepOutput) -> Self {
+        self.token = Some(token.to_string());
+        self
+    }
+
+    pub fn with_path(mut self, path: &str) -> Self {
+        self.path = Some(path.to_string());
+        self
+    }
+
+    pub fn with_repository(mut self, repository: &str) -> Self {
+        self.repository = Some(repository.to_string());
+        self
+    }
+
+    pub fn with_ref(mut self, ref_: impl ToString) -> Self {
+        self.ref_ = Some(ref_.to_string());
+        self
+    }
+}
+
+impl From<CheckoutStep> for Step<Use> {
+    fn from(value: CheckoutStep) -> Self {
+        Step::new(value.name.unwrap_or("steps::checkout_repo".to_string()))
+            .uses(
+                "actions",
+                "checkout",
+                "11bd71901bbe5b1630ceea73d27597364c9af683", // v4
+            )
+            // prevent checkout action from running `git clean -ffdx` which
+            // would delete the target directory
+            .add_with(("clean", false))
+            .map(|step| match value.fetch_depth {
+                FetchDepth::Shallow => step,
+                FetchDepth::Full => step.add_with(("fetch-depth", 0)),
+                FetchDepth::Custom(depth) => step.add_with(("fetch-depth", depth)),
+            })
+            .map(|step| match value.token {
+                Some(token) => step.add_with(("token", token)),
+                None => step,
+            })
+            .map(|step| match value.path {
+                Some(path) => step.add_with(("path", path)),
+                None => step,
+            })
+            .map(|step| match value.repository {
+                Some(repository) => step.add_with(("repository", repository)),
+                None => step,
+            })
+            .map(|step| match value.ref_ {
+                Some(ref_) => step.add_with(("ref", ref_)),
+                None => step,
+            })
+    }
+}
+
+pub fn checkout_repo() -> CheckoutStep {
+    CheckoutStep::default()
 }
 
 pub fn setup_pnpm() -> Step<Use> {
@@ -270,6 +349,7 @@ pub(crate) fn dependant_job(deps: &[&NamedJob]) -> Job {
 impl FluentBuilder for Job {}
 impl FluentBuilder for Workflow {}
 impl FluentBuilder for Input {}
+impl<T> FluentBuilder for Step<T> {}
 
 /// A helper trait for building complex objects with imperative conditionals in a fluent style.
 /// Copied from GPUI to avoid adding GPUI as dependency