Hiratake Web ロゴ

GitHub で autofix.ci をつかってコードを自動で修正する

投稿した日
更新した日
書いたひと
icon
ひらたけ

何ができるのか

使ってみる

{
  "scripts": {
    "lint": "eslint . --ext .js,.ts --fix",
    "format": "prettier . -w"
  },
  ...
}
name: autofix.ci # 必ず「autofix.ci」とする必要がある

on:
  pull_request:
    branches:
      - main

permissions:
  contents: read

jobs:
  # Autofix
  autofix:
    name: Autofix
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 18
      - name: Setup pnpm
        uses: pnpm/action-setup@v2
        id: pnpm-install
        with:
          run_install: false
      - name: Get pnpm store directory
        id: pnpm-cache
        shell: bash
        run: |
          echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
      - name: Setup pnpm cache
        uses: actions/cache@v3
        with:
          path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
          key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
          restore-keys: |
            ${{ runner.os }}-pnpm-store-
      - name: Install dependencies
        run: pnpm install

      # ESLint の修正を実行
      - name: Run ESLint
        run: pnpm lint
      # Prettier の修正を実行
      - name: Run Prettier
        run: pnpm format
      # autofix.ci の Action を実行
      - name: Autofix
        uses: autofix-ci/action@8caa572fd27b0019a65e4c695447089c8d3138b9