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