Improve autofix (#44930)

Conrad Irwin created

Release Notes:

- N/A

Change summary

.github/workflows/autofix_pr.yml                | 38 +++++++++++++++++--
script/prettier                                 | 10 ++++-
tooling/xtask/src/tasks/workflows/autofix_pr.rs | 28 +++++++++++---
3 files changed, 64 insertions(+), 12 deletions(-)

Detailed changes

.github/workflows/autofix_pr.yml 🔗

@@ -11,7 +11,7 @@ on:
         type: string
 jobs:
   run_autofix:
-    runs-on: namespace-profile-2x4-ubuntu-2404
+    runs-on: namespace-profile-16x32-ubuntu-2204
     steps:
     - id: get-app-token
       name: 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_fmt
       run: cargo fmt --all
       shell: bash -euxo pipefail {0}
@@ -41,13 +66,18 @@ jobs:
             echo "No changes to commit"
         else
             git add -A
-            git commit -m "Apply cargo fmt and clippy --fix"
+            git commit -m "Autofix"
             git push
         fi
       shell: bash -euxo pipefail {0}
       env:
         GIT_COMMITTER_NAME: Zed Zippy
-        GIT_COMMITTER_EMAIL: hi@zed.dev
+        GIT_COMMITTER_EMAIL: 234243425+zed-zippy[bot]@users.noreply.github.com
         GIT_AUTHOR_NAME: Zed Zippy
-        GIT_AUTHOR_EMAIL: hi@zed.dev
+        GIT_AUTHOR_EMAIL: 234243425+zed-zippy[bot]@users.noreply.github.com
         GITHUB_TOKEN: ${{ steps.get-app-token.outputs.token }}
+    - name: steps::cleanup_cargo_config
+      if: always()
+      run: |
+        rm -rf ./../.cargo
+      shell: bash -euxo pipefail {0}

script/prettier 🔗

@@ -3,14 +3,20 @@ set -euxo pipefail
 
 PRETTIER_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 .."
     false

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; then
                 echo "No changes to commit"
             else
                 git add -A
-                git commit -m "Apply cargo fmt and clippy --fix"
+                git commit -m "Autofix"
                 git push
             fi
         "#})
         .add_env(("GIT_COMMITTER_NAME", "Zed Zippy"))
-        .add_env(("GIT_COMMITTER_EMAIL", "hi@zed.dev"))
+        .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", "hi@zed.dev"))
+        .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)),
     )
 }