Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Improve autofix (#44930)
Conrad Irwin6016d0b8c6a2
diff --git a/.github/workflows/autofix_pr.yml b/.github/workflows/autofix_pr.ymlindex 8c7786f6e1b..308849ccbee 100644--- a/.github/workflows/autofix_pr.yml+++ b/.github/workflows/autofix_pr.yml@@ -11,7 +11,7 @@ on:type: stringjobs:run_autofix:- runs-on: namespace-profile-2x4-ubuntu-2404+ runs-on: namespace-profile-16x32-ubuntu-2204steps:- id: get-app-tokenname: autofix_pr::run_autofix::authenticate_as_zippy@@ -29,6 +29,31 @@ jobs:shell: bash -euxo pipefail {0}env:GITHUB_TOKEN: ${{ steps.get-app-token.outputs.token }}+ - name: steps::setup_cargo_config+ run: |+ mkdir -p ./../.cargo+ cp ./.cargo/ci-config.toml ./../.cargo/config.toml+ shell: bash -euxo pipefail {0}+ - name: steps::cache_rust_dependencies_namespace+ uses: namespacelabs/nscloud-cache-action@v1+ with:+ cache: rust+ - name: steps::setup_linux+ run: ./script/linux+ shell: bash -euxo pipefail {0}+ - name: steps::install_mold+ run: ./script/install-mold+ shell: bash -euxo pipefail {0}+ - name: steps::download_wasi_sdk+ run: ./script/download-wasi-sdk+ shell: bash -euxo pipefail {0}+ - name: steps::setup_pnpm+ uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2+ with:+ version: '9'+ - name: autofix_pr::run_autofix::run_prettier_fix+ run: ./script/prettier --write+ shell: bash -euxo pipefail {0}- name: autofix_pr::run_autofix::run_cargo_fmtrun: cargo fmt --allshell: bash -euxo pipefail {0}@@ -41,13 +66,18 @@ jobs:echo "No changes to commit"elsegit add -A- git commit -m "Apply cargo fmt and clippy --fix"+ git commit -m "Autofix"git pushfishell: bash -euxo pipefail {0}env:GIT_COMMITTER_NAME: Zed Zippy- GIT_COMMITTER_EMAIL: [email protected]+ GIT_COMMITTER_EMAIL: 234243425+zed-zippy[bot]@users.noreply.github.comGIT_AUTHOR_NAME: Zed Zippy- GIT_AUTHOR_EMAIL: [email protected]+ GIT_AUTHOR_EMAIL: 234243425+zed-zippy[bot]@users.noreply.github.comGITHUB_TOKEN: ${{ steps.get-app-token.outputs.token }}+ - name: steps::cleanup_cargo_config+ if: always()+ run: |+ rm -rf ./../.cargo+ shell: bash -euxo pipefail {0}diff --git a/script/prettier b/script/prettierindex 5ad5d15cf03..d7a9ba787fc 100755--- a/script/prettier+++ b/script/prettier@@ -3,14 +3,20 @@ set -euxo pipefailPRETTIER_VERSION=3.5.0-pnpm dlx "prettier@${PRETTIER_VERSION}" assets/settings/default.json --parser=jsonc --check || {+if [[ "${1:-}" == "--write" ]]; then+ MODE="--write"+else+ MODE="--check"+fi++pnpm dlx "prettier@${PRETTIER_VERSION}" assets/settings/default.json --parser=jsonc $MODE || {echo "To fix, run from the root of the Zed repo:"echo " pnpm dlx prettier@${PRETTIER_VERSION} assets/settings/default.json --parser=jsonc --write"false}cd docs-pnpm dlx "prettier@${PRETTIER_VERSION}" . --check || {+pnpm dlx "prettier@${PRETTIER_VERSION}" . $MODE || {echo "To fix, run from the root of the Zed repo:"echo " cd docs && pnpm dlx prettier@${PRETTIER_VERSION} . --write && cd .."falsediff --git a/tooling/xtask/src/tasks/workflows/autofix_pr.rs b/tooling/xtask/src/tasks/workflows/autofix_pr.rsindex 7e00a8bcbdb..835750e282d 100644--- a/tooling/xtask/src/tasks/workflows/autofix_pr.rs+++ b/tooling/xtask/src/tasks/workflows/autofix_pr.rs@@ -2,7 +2,7 @@ use gh_workflow::*;use crate::tasks::workflows::{runners,- steps::{self, NamedJob, named},+ steps::{self, FluentBuilder, NamedJob, named},vars::{self, StepOutput, WorkflowInput},};@@ -45,20 +45,30 @@ fn run_autofix(pr_number: &WorkflowInput) -> NamedJob {)}+ fn run_prettier_fix() -> Step<Run> {+ named::bash("./script/prettier --write")+ }+fn commit_and_push(token: &StepOutput) -> Step<Run> {named::bash(indoc::indoc! {r#"if git diff --quiet; thenecho "No changes to commit"elsegit add -A- git commit -m "Apply cargo fmt and clippy --fix"+ git commit -m "Autofix"git pushfi"#}).add_env(("GIT_COMMITTER_NAME", "Zed Zippy"))- .add_env(("GIT_COMMITTER_EMAIL", "[email protected]"))+ .add_env((+ "GIT_COMMITTER_EMAIL",+ "234243425+zed-zippy[bot]@users.noreply.github.com",+ )).add_env(("GIT_AUTHOR_NAME", "Zed Zippy"))- .add_env(("GIT_AUTHOR_EMAIL", "[email protected]"))+ .add_env((+ "GIT_AUTHOR_EMAIL",+ "234243425+zed-zippy[bot]@users.noreply.github.com",+ )).add_env(("GITHUB_TOKEN", token))}@@ -66,12 +76,18 @@ fn run_autofix(pr_number: &WorkflowInput) -> NamedJob {named::job(Job::default()- .runs_on(runners::LINUX_SMALL)+ .runs_on(runners::LINUX_DEFAULT).add_step(authenticate).add_step(steps::checkout_repo_with_token(&token)).add_step(checkout_pr(pr_number, &token))+ .add_step(steps::setup_cargo_config(runners::Platform::Linux))+ .add_step(steps::cache_rust_dependencies_namespace())+ .map(steps::install_linux_dependencies)+ .add_step(steps::setup_pnpm())+ .add_step(run_prettier_fix()).add_step(run_cargo_fmt()).add_step(run_clippy_fix())- .add_step(commit_and_push(&token)),+ .add_step(commit_and_push(&token))+ .add_step(steps::cleanup_cargo_config(runners::Platform::Linux)),)}