Trying to create a Github action that auto lints and formats the changed code in a PR

I have two Github actions one for auto formating and another for linting:

Auto lint

name: Lint Changed Files

on:
  pull_request:
    types: [opened, synchronize, reopened]

jobs:
  lint:
    name: Lint Changed Files
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '20'

      - name: Install pnpm
        run: npm install -g pnpm

      - name: Install dependencies
        run: pnpm install

      - name: Get changed files
        id: changed-files
        run: |
          echo "${{ github.event.pull_request.base.sha }}" > base_sha.txt
          echo "${{ github.event.pull_request.head.sha }}" > head_sha.txt
          git diff --name-only $(cat base_sha.txt) $(cat head_sha.txt) > changed_files.txt

      - name: Create lint script for changed files
        run: |
          # Read the list of changed files
          changed_files=$(cat changed_files.txt)

          # Initialize an empty array to hold files to be linted
          files_to_lint=()

          # Loop over each changed file
          for file in $changed_files; do
            # Add JS/TS files to the list
            if [[  $file == *.js || $file == *.ts || $file == *.tsx || $file == *.cjs || $file == *.mjs || $file == *.astro || $file == *.spec.ts || $file == *.mdx ]]; then
              files_to_lint+=($file)
            fi
          done

          # Create a temporary lint script if there are files to lint
          if [ ${#files_to_lint[@]} -eq 0 ]; then
            echo "No JavaScript or TypeScript files were changed." > lint.sh
          else
            echo "pnpm run lint:check -- ${files_to_lint[@]}" > lint.sh
          fi

          chmod +x lint.sh

      - name: Run linter on changed files
        run: ./lint.sh

Auto format

name: Autoformat Changed Files

on:
  pull_request:
    types: [opened, synchronize, reopened]

jobs:
  autoformat:
    name: Autoformat Changed Files
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '20'

      - name: Install pnpm
        run: npm install -g pnpm

      - name: Install dependencies
        run: pnpm install

      - name: Get changed files
        id: changed-files
        run: |
          echo "${{ github.event.pull_request.base.sha }}" > base_sha.txt
          echo "${{ github.event.pull_request.head.sha }}" > head_sha.txt
          git diff --name-only $(cat base_sha.txt) $(cat head_sha.txt) > changed_files.txt

      - name: Create format script for changed files
        run: |
          # Read the list of changed files
          changed_files=$(cat changed_files.txt)

          # Initialize an empty array to hold files to be formatted
          files_to_format=()

          # Loop over each changed file
          for file in $changed_files; do
            # Add JS/TS files to the list
            if [[ $file == *.js || $file == *.ts || $file == *.tsx || $file == *.cjs || $file == *.mjs || $file == *.astro || $file == *.spec.ts || $file == *.mdx ]]; then
              files_to_format+=($file)
            fi
          done

          # Create a temporary format script if there are files to format
          if [ ${#files_to_format[@]} -eq 0 ]; then
            echo "No JavaScript or TypeScript files were changed." > format.sh
          else
            echo "pnpm run format -- ${files_to_format[@]}" > format.sh
          fi

          chmod +x format.sh

      - name: Run formatter on changed files
        run: ./format.sh

      - name: Commit formatted changes
        run: |
          git config --global user.name 'github-actions[bot]'
          git config --global user.email 'github-actions[bot]@users.noreply.github.com'
          git add .
          git commit -m 'Autoformat changed files' || echo "No changes to commit"
          git push origin HEAD:${{ github.head_ref }}

When running these two with Act and github actions they fail with the error:

[Lint Changed Files/Lint Changed Files            ]   ✅  Success - Main Install dependencies
[Lint Changed Files/Lint Changed Files            ] ⭐ Run Main Get changed files
[Lint Changed Files/Lint Changed Files            ]   ????  docker exec cmd=[bash --noprofile --norc -e -o pipefail /var/run/act/workflow/changed-files] user= workdir=
[Lint Changed Files/Lint Changed Files            ]   ✅  Success - Main Get changed files
[Lint Changed Files/Lint Changed Files            ] ⭐ Run Main Create lint script for changed files
[Lint Changed Files/Lint Changed Files            ]   ????  docker exec cmd=[bash --noprofile --norc -e -o pipefail /var/run/act/workflow/5] user= workdir=
[Lint Changed Files/Lint Changed Files            ]   ✅  Success - Main Create lint script for changed files
[Lint Changed Files/Lint Changed Files            ] ⭐ Run Main Run linter on changed files
[Lint Changed Files/Lint Changed Files            ]   ????  docker exec cmd=[bash --noprofile --norc -e -o pipefail /var/run/act/workflow/6] user= workdir=
| ./lint.sh: line 1: No: command not found
[Lint Changed Files/Lint Changed Files            ]   ❌  Failure - Main Run linter on changed files
[Lint Changed Files/Lint Changed Files            ] exitcode '127': command not found, please refer to https://github.com/nektos/act/issues/107 for more information
[Lint Changed Files/Lint Changed Files            ] ????  Job failed

[run-tests/format changed files                   ]   ❓  ::endgroup::
[run-tests/format changed files                   ]   ❓ add-matcher /run/act/actions/actions-setup-node@v4/.github/tsc.json
[run-tests/format changed files                   ]   ❓ add-matcher /run/act/actions/actions-setup-node@v4/.github/eslint-stylish.json
[run-tests/format changed files                   ]   ❓ add-matcher /run/act/actions/actions-setup-node@v4/.github/eslint-compact.json
[run-tests/format changed files                   ]   ✅  Success - Main actions/setup-node@v4
[run-tests/format changed files                   ]   ⚙  ::set-output:: node-version=v20.14.0
[run-tests/format changed files                   ]   ⚙  ::add-path:: /opt/hostedtoolcache/node/20.14.0/arm64/bin
[run-tests/format changed files                   ] ⭐ Run Main actions/checkout@v4
[run-tests/format changed files                   ]   ????  docker cp src=/Users/ekrich/git/eTech-UI/. dst=/Users/ekrich/git/eTech-UI
| npm error code ENOTEMPTY
| npm error syscall rename
| npm error path /opt/hostedtoolcache/node/20.14.0/arm64/lib/node_modules/pnpm
| npm error dest /opt/hostedtoolcache/node/20.14.0/arm64/lib/node_modules/.pnpm-i4BzBorb
| npm error errno -39
| npm error ENOTEMPTY: directory not empty, rename '/opt/hostedtoolcache/node/20.14.0/arm64/lib/node_modules/pnpm' -> '/opt/hostedtoolcache/node/20.14.0/arm64/lib/node_modules/.pnpm-i4BzBorb'
| 
| npm error A complete log of this run can be found in: /root/.npm/_logs/2024-06-08T03_31_06_800Z-debug-0.log
[Autoformat Changed Files/Autoformat Changed Files]   ❌  Failure - Main Install pnpm
[Autoformat Changed Files/Autoformat Changed Files] exitcode '217': failure
[Autoformat Changed Files/Autoformat Changed Files] ????  Job failed
[run-tests/format changed files                   ]   ✅  Success - Main actions/checkout@v4
[run-tests/format changed files                   ] ⭐ Run Main pnpm install

Any idea what is wrong here? Is there a pre-made action I can use instead? I’ve tried using actions/changed-files but that doesn’t work either.

Refrences I’ve looked at but still had no luck in:

  • Get modified files in Github actions
  • https://github.com/marketplace/actions/github-action-auto-format

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật