autofix_pr.yml

  1# Generated from xtask::workflows::autofix_pr
  2# Rebuild with `cargo xtask workflows`.
  3name: autofix_pr
  4run-name: 'autofix PR #${{ inputs.pr_number }}'
  5on:
  6  workflow_dispatch:
  7    inputs:
  8      pr_number:
  9        description: pr_number
 10        required: true
 11        type: string
 12      run_clippy:
 13        description: run_clippy
 14        type: boolean
 15        default: 'true'
 16jobs:
 17  run_autofix:
 18    runs-on: namespace-profile-16x32-ubuntu-2204
 19    steps:
 20    - name: steps::checkout_repo
 21      uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
 22      with:
 23        clean: false
 24    - name: autofix_pr::run_autofix::checkout_pr
 25      run: gh pr checkout ${{ inputs.pr_number }}
 26      env:
 27        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 28    - name: steps::setup_cargo_config
 29      run: |
 30        mkdir -p ./../.cargo
 31        cp ./.cargo/ci-config.toml ./../.cargo/config.toml
 32    - name: steps::cache_rust_dependencies_namespace
 33      uses: namespacelabs/nscloud-cache-action@v1
 34      with:
 35        cache: rust
 36        path: ~/.rustup
 37    - name: steps::setup_linux
 38      run: ./script/linux
 39    - name: steps::install_mold
 40      run: ./script/install-mold
 41    - name: steps::download_wasi_sdk
 42      run: ./script/download-wasi-sdk
 43    - name: steps::setup_pnpm
 44      uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2
 45      with:
 46        version: '9'
 47    - name: autofix_pr::run_autofix::install_cargo_machete
 48      if: ${{ inputs.run_clippy }}
 49      uses: clechasseur/rs-cargo@8435b10f6e71c2e3d4d3b7573003a8ce4bfc6386
 50      with:
 51        command: install
 52        args: cargo-machete@0.7.0
 53    - name: autofix_pr::run_autofix::run_cargo_fix
 54      if: ${{ inputs.run_clippy }}
 55      run: cargo fix --workspace --release --all-targets --all-features --allow-dirty --allow-staged
 56    - name: autofix_pr::run_autofix::run_cargo_machete_fix
 57      if: ${{ inputs.run_clippy }}
 58      run: cargo machete --fix
 59    - name: autofix_pr::run_autofix::run_clippy_fix
 60      if: ${{ inputs.run_clippy }}
 61      run: cargo clippy --workspace --release --all-targets --all-features --fix --allow-dirty --allow-staged
 62    - name: autofix_pr::run_autofix::run_prettier_fix
 63      run: ./script/prettier --write
 64    - name: autofix_pr::run_autofix::run_cargo_fmt
 65      run: cargo fmt --all
 66    - id: create-patch
 67      name: autofix_pr::run_autofix::create_patch
 68      run: |
 69        if git diff --quiet; then
 70            echo "No changes to commit"
 71            echo "has_changes=false" >> "$GITHUB_OUTPUT"
 72        else
 73            git diff > autofix.patch
 74            echo "has_changes=true" >> "$GITHUB_OUTPUT"
 75        fi
 76    - name: upload artifact autofix-patch
 77      uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4
 78      with:
 79        name: autofix-patch
 80        path: autofix.patch
 81        if-no-files-found: ignore
 82        retention-days: '1'
 83    - name: steps::cleanup_cargo_config
 84      if: always()
 85      run: |
 86        rm -rf ./../.cargo
 87    outputs:
 88      has_changes: ${{ steps.create-patch.outputs.has_changes }}
 89  commit_changes:
 90    needs:
 91    - run_autofix
 92    if: needs.run_autofix.outputs.has_changes == 'true'
 93    runs-on: namespace-profile-2x4-ubuntu-2404
 94    steps:
 95    - id: get-app-token
 96      name: steps::authenticate_as_zippy
 97      uses: actions/create-github-app-token@bef1eaf1c0ac2b148ee2a0a74c65fbe6db0631f1
 98      with:
 99        app-id: ${{ secrets.ZED_ZIPPY_APP_ID }}
100        private-key: ${{ secrets.ZED_ZIPPY_APP_PRIVATE_KEY }}
101    - name: steps::checkout_repo_with_token
102      uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
103      with:
104        clean: false
105        token: ${{ steps.get-app-token.outputs.token }}
106    - name: autofix_pr::commit_changes::checkout_pr
107      run: gh pr checkout ${{ inputs.pr_number }}
108      env:
109        GITHUB_TOKEN: ${{ steps.get-app-token.outputs.token }}
110    - name: autofix_pr::download_patch_artifact
111      uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53
112      with:
113        name: autofix-patch
114    - name: autofix_pr::commit_changes::apply_patch
115      run: git apply autofix.patch
116    - name: autofix_pr::commit_changes::commit_and_push
117      run: |
118        git commit -am "Autofix"
119        git push
120      env:
121        GIT_COMMITTER_NAME: Zed Zippy
122        GIT_COMMITTER_EMAIL: 234243425+zed-zippy[bot]@users.noreply.github.com
123        GIT_AUTHOR_NAME: Zed Zippy
124        GIT_AUTHOR_EMAIL: 234243425+zed-zippy[bot]@users.noreply.github.com
125        GITHUB_TOKEN: ${{ steps.get-app-token.outputs.token }}
126concurrency:
127  group: ${{ github.workflow }}-${{ inputs.pr_number }}
128  cancel-in-progress: true
129defaults:
130  run:
131    shell: bash -euxo pipefail {0}