From 9aa6b1481eff1cacf5e21862aedab4c2c167a6f9 Mon Sep 17 00:00:00 2001 From: Finn Evers Date: Tue, 17 Feb 2026 19:49:18 +0100 Subject: [PATCH] extension_ci: Increase fetch depth for tests job (#49389) 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 --- .github/workflows/autofix_pr.yml | 2 +- .github/workflows/bump_patch_version.yml | 2 +- .github/workflows/extension_tests.yml | 1 + .../workflows/extension_workflow_rollout.yml | 10 +- .github/workflows/run_tests.yml | 3 +- .../xtask/src/tasks/workflows/autofix_pr.rs | 2 +- .../src/tasks/workflows/bump_patch_version.rs | 8 +- .../src/tasks/workflows/deploy_collab.rs | 4 +- .../src/tasks/workflows/extension_bump.rs | 2 +- .../src/tasks/workflows/extension_tests.rs | 2 +- .../workflows/extension_workflow_rollout.rs | 23 ++-- tooling/xtask/src/tasks/workflows/release.rs | 5 +- .../src/tasks/workflows/release_nightly.rs | 8 +- .../xtask/src/tasks/workflows/run_tests.rs | 12 +- tooling/xtask/src/tasks/workflows/steps.rs | 114 +++++++++++++++--- 15 files changed, 135 insertions(+), 63 deletions(-) diff --git a/.github/workflows/autofix_pr.yml b/.github/workflows/autofix_pr.yml index 87abbb86a03b221840a46050b8460eb42187f387..60cc66294af2cf65e17aaad530a9df511ec61503 100644 --- a/.github/workflows/autofix_pr.yml +++ b/.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 diff --git a/.github/workflows/bump_patch_version.yml b/.github/workflows/bump_patch_version.yml index 68bc37e5c755b5557a90f38de2f26ad9cecfcade..480d8b0ada98e859d2e72b49a39805ffe8f72b25 100644 --- a/.github/workflows/bump_patch_version.yml +++ b/.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 diff --git a/.github/workflows/extension_tests.yml b/.github/workflows/extension_tests.yml index 76bbc423f66ff560e0179c71d0eda9cf222b28aa..4393ca6e44525f1f8a9cd7d7e98c361333207d1f 100644 --- a/.github/workflows/extension_tests.yml +++ b/.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 diff --git a/.github/workflows/extension_workflow_rollout.yml b/.github/workflows/extension_workflow_rollout.yml index 29aa8f781ce56b65be0dc16e36db8b5cd1635589..d8eae61c116f5d1544c0e1c12a51a23fbdfe9201 100644 --- a/.github/workflows/extension_workflow_rollout.yml +++ b/.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]" diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index fb2e74aaedbf9e492ae651ac0c2b68becd3d1779..72693eb8939933b0d2821fc091b7b69ae25429e6 100644 --- a/.github/workflows/run_tests.yml +++ b/.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" ]; diff --git a/tooling/xtask/src/tasks/workflows/autofix_pr.rs b/tooling/xtask/src/tasks/workflows/autofix_pr.rs index e1e93e45fc8094217485c5b99a0f9a79d0ae1f81..c2c89b7cd05394c225c015a6cc83f48bd35b24a4 100644 --- a/tooling/xtask/src/tasks/workflows/autofix_pr.rs +++ b/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()) diff --git a/tooling/xtask/src/tasks/workflows/bump_patch_version.rs b/tooling/xtask/src/tasks/workflows/bump_patch_version.rs index cc6229587bfe3af7863f84e341fd0da2ba54c47e..5ef149be29313bc2078dbc1f75a82845c3d3b666 100644 --- a/tooling/xtask/src/tasks/workflows/bump_patch_version.rs +++ b/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 { - 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 { diff --git a/tooling/xtask/src/tasks/workflows/deploy_collab.rs b/tooling/xtask/src/tasks/workflows/deploy_collab.rs index 17d48d93fca8f18637b48b544c5bd39ab3c5ff06..58212118c7ba4fa6d44d5f29fac671ca6eb5e662 100644 --- a/tooling/xtask/src/tasks/workflows/deploy_collab.rs +++ b/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) diff --git a/tooling/xtask/src/tasks/workflows/extension_bump.rs b/tooling/xtask/src/tasks/workflows/extension_bump.rs index d19ae9bdedd72352d138dabb2452fde64464490d..fcc73bce391ea1fb7a943f8a7b3e1b66417592c6 100644 --- a/tooling/xtask/src/tasks/workflows/extension_bump.rs +++ b/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) diff --git a/tooling/xtask/src/tasks/workflows/extension_tests.rs b/tooling/xtask/src/tasks/workflows/extension_tests.rs index 02ed264682bea94db558bfe42983cd8235ddfb06..3d7f96157b5a792b2d1e50b960bb61585ff47422 100644 --- a/tooling/xtask/src/tasks/workflows/extension_tests.rs +++ b/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()) diff --git a/tooling/xtask/src/tasks/workflows/extension_workflow_rollout.rs b/tooling/xtask/src/tasks/workflows/extension_workflow_rollout.rs index a9fcd6d9467cf9f5e6cf37f6f50c34b66247df23..bcee9be9a272079135c70ee45e5d16953eda2876 100644 --- a/tooling/xtask/src/tasks/workflows/extension_workflow_rollout.rs +++ b/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 { + 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 { - 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, 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 { - 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 { diff --git a/tooling/xtask/src/tasks/workflows/release.rs b/tooling/xtask/src/tasks/workflows/release.rs index 5ac21efbfc324fab1532d95bdb42c8397594e38f..8241fc58f0821b950e32ee9b1a42473975ec008d 100644 --- a/tooling/xtask/src/tasks/workflows/release.rs +++ b/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/")) diff --git a/tooling/xtask/src/tasks/workflows/release_nightly.rs b/tooling/xtask/src/tasks/workflows/release_nightly.rs index f814a153eb9e87a5cacc8047839a29b2d85003f9..bcae94d08d14a76bef82482c1afd707c5a8a4bda 100644 --- a/tooling/xtask/src/tasks/workflows/release_nightly.rs +++ b/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()) diff --git a/tooling/xtask/src/tasks/workflows/run_tests.rs b/tooling/xtask/src/tasks/workflows/run_tests.rs index 393675e983075e7296cc306d7a4f3f5877fbe0cb..f141c92e1f17c282dcb6649485be2f673adfd595 100644 --- a/tooling/xtask/src/tasks/workflows/run_tests.rs +++ b/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 { - named::bash("git clean -df") - } - fn ensure_fresh_merge() -> Step { 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()), diff --git a/tooling/xtask/src/tasks/workflows/steps.rs b/tooling/xtask/src/tasks/workflows/steps.rs index 8fffd1b0f46bb603c33fe41a795653fe8c43d036..19aea15ddcf6e38e1dd3a368f75dd83370d88737 100644 --- a/tooling/xtask/src/tasks/workflows/steps.rs +++ b/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 for Step { } } -pub fn checkout_repo() -> Step { - 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 { - 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, + token: Option, + path: Option, + repository: Option, + ref_: Option, +} + +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) -> 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 for Step { + 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 { @@ -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 FluentBuilder for Step {} /// A helper trait for building complex objects with imperative conditionals in a fluent style. /// Copied from GPUI to avoid adding GPUI as dependency