diff --git a/.github/workflows/autofix_pr.yml b/.github/workflows/autofix_pr.yml index 762b86c446f4592e8fd76c8f5a00cf8cf8ab3f38..1591ba2a9a98b8587814d25858f4e0d78d9f7d34 100644 --- a/.github/workflows/autofix_pr.yml +++ b/.github/workflows/autofix_pr.yml @@ -123,3 +123,6 @@ jobs: GIT_AUTHOR_NAME: Zed Zippy GIT_AUTHOR_EMAIL: 234243425+zed-zippy[bot]@users.noreply.github.com GITHUB_TOKEN: ${{ steps.get-app-token.outputs.token }} +concurrency: + group: ${{ github.workflow }}-${{ inputs.pr_number }} + cancel-in-progress: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7afac285b5a34df2aadd04952400809059e12222..155b38666f4bd73e68e9ea326db9a6862288a1fe 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -74,6 +74,12 @@ jobs: - name: steps::clippy run: ./script/clippy shell: bash -euxo pipefail {0} + - name: steps::trigger_autofix + if: failure() && github.event_name == 'pull_request' && github.actor != 'zed-zippy[bot]' + run: gh workflow run autofix_pr.yml -f pr_number=${{ github.event.pull_request.number }} -f run_clippy=true + shell: bash -euxo pipefail {0} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: steps::cargo_install_nextest uses: taiki-e/install-action@nextest - name: steps::clear_target_dir_if_large diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 9584d7a0cb70469820bf40d76beb6154f2a53b1e..a9a46b7a797faae793c87601d306a2aea80e6592 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -77,6 +77,15 @@ jobs: - name: ./script/prettier run: ./script/prettier shell: bash -euxo pipefail {0} + - name: steps::cargo_fmt + run: cargo fmt --all -- --check + shell: bash -euxo pipefail {0} + - name: steps::trigger_autofix + if: failure() && github.event_name == 'pull_request' && github.actor != 'zed-zippy[bot]' + run: gh workflow run autofix_pr.yml -f pr_number=${{ github.event.pull_request.number }} -f run_clippy=false + shell: bash -euxo pipefail {0} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: ./script/check-todos run: ./script/check-todos shell: bash -euxo pipefail {0} @@ -87,9 +96,6 @@ jobs: uses: crate-ci/typos@2d0ce569feab1f8752f1dde43cc2f2aa53236e06 with: config: ./typos.toml - - name: steps::cargo_fmt - run: cargo fmt --all -- --check - shell: bash -euxo pipefail {0} timeout-minutes: 60 run_tests_windows: needs: @@ -160,6 +166,12 @@ jobs: - name: steps::clippy run: ./script/clippy shell: bash -euxo pipefail {0} + - name: steps::trigger_autofix + if: failure() && github.event_name == 'pull_request' && github.actor != 'zed-zippy[bot]' + run: gh workflow run autofix_pr.yml -f pr_number=${{ github.event.pull_request.number }} -f run_clippy=true + shell: bash -euxo pipefail {0} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: steps::cargo_install_nextest uses: taiki-e/install-action@nextest - name: steps::clear_target_dir_if_large diff --git a/tooling/xtask/src/tasks/workflows/autofix_pr.rs b/tooling/xtask/src/tasks/workflows/autofix_pr.rs index 44dd0f9ea9b840163767e15b973192e72b57f4a8..f4a8e0e2b09df93cc430f0931c3db3f9e67b07df 100644 --- a/tooling/xtask/src/tasks/workflows/autofix_pr.rs +++ b/tooling/xtask/src/tasks/workflows/autofix_pr.rs @@ -18,6 +18,12 @@ pub fn autofix_pr() -> Workflow { .add_input(pr_number.name, pr_number.input()) .add_input(run_clippy.name, run_clippy.input()), )) + .concurrency( + Concurrency::new(Expression::new(format!( + "${{{{ github.workflow }}}}-{pr_number}" + ))) + .cancel_in_progress(true), + ) .add_job(run_autofix.name.clone(), run_autofix.job) .add_job(commit_changes.name, commit_changes.job) } diff --git a/tooling/xtask/src/tasks/workflows/run_tests.rs b/tooling/xtask/src/tasks/workflows/run_tests.rs index 0bb3e152fb390e044ebac456fd3347707c66f612..13639fd6c4bf33fe090dcb9d5f3cafdf45a36e76 100644 --- a/tooling/xtask/src/tasks/workflows/run_tests.rs +++ b/tooling/xtask/src/tasks/workflows/run_tests.rs @@ -237,10 +237,11 @@ fn check_style() -> NamedJob { .add_step(steps::cache_rust_dependencies_namespace()) .add_step(steps::setup_pnpm()) .add_step(steps::script("./script/prettier")) + .add_step(steps::cargo_fmt()) + .add_step(steps::trigger_autofix(false)) .add_step(steps::script("./script/check-todos")) .add_step(steps::script("./script/check-keymaps")) - .add_step(check_for_typos()) - .add_step(steps::cargo_fmt()), + .add_step(check_for_typos()), ) } @@ -326,7 +327,8 @@ pub(crate) fn run_platform_tests(platform: Platform) -> NamedJob { .add_step(steps::setup_node()) .add_step(steps::clippy(platform)) .when(platform == Platform::Linux, |job| { - job.add_step(steps::cargo_install_nextest()) + job.add_step(steps::trigger_autofix(true)) + .add_step(steps::cargo_install_nextest()) }) .add_step(steps::clear_target_dir_if_large(platform)) .add_step(steps::cargo_nextest(platform)) diff --git a/tooling/xtask/src/tasks/workflows/steps.rs b/tooling/xtask/src/tasks/workflows/steps.rs index 7d55df2db433d6e6eae96a5ae62a0c033689d904..54873c011ce9d1fb7d4e7e0b734695c7c1a30fad 100644 --- a/tooling/xtask/src/tasks/workflows/steps.rs +++ b/tooling/xtask/src/tasks/workflows/steps.rs @@ -344,3 +344,13 @@ pub fn git_checkout(ref_name: &dyn std::fmt::Display) -> Step { "git fetch origin {ref_name} && git checkout {ref_name}" )) } + +pub fn trigger_autofix(run_clippy: bool) -> Step { + named::bash(format!( + "gh workflow run autofix_pr.yml -f pr_number=${{{{ github.event.pull_request.number }}}} -f run_clippy={run_clippy}" + )) + .if_condition(Expression::new( + "failure() && github.event_name == 'pull_request' && github.actor != 'zed-zippy[bot]'", + )) + .add_env(("GITHUB_TOKEN", vars::GITHUB_TOKEN)) +}