7
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

GitHub Actions で Laravel Pint を自動整形&自動コミットする

Last updated at Posted at 2023-02-06

Laravel Pint(ピント) とは

Laravel Pint はPHPコードスタイルフィクサーのPHP-CS-Fixerのラッパーライブラリです。
コードスタイルルールに沿って統一されたコードにしてくれるとても便利なライブラリです。

Laravel9以降はデフォルトでインストールされています。
設定ファイルを別途用意しなくてもLaravelと同様のコードスタイルで統一してくれます。

GitHub Actions とは

GitHub Actionsは、GitHub上でのワークフローの自動化を支援するサービスです。開発者はGitHub上のリポジトリに対して、特定のイベント(例えば、プッシュやプルリクエスト)が発生した際に自動的に実行されるタスク(例えば、ビルドやデプロイ)を定義できます。これにより開発者はリポジトリに対しての変更を素早く反映し、リリースをスムーズにできます。

環境

  • PHP: 8.2.1
  • Laravel: 9.x

GitHub Actions ワークフロー

.github/workflows/pint.yml
name: Pint

on:
   pull_request:
     paths:
       - '**.php'

jobs:
  pint:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
        with:
          ref: ${{ github.head_ref }}
          token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

      - name: Apply Pint
        uses: aglipanci/laravel-pint-action@2.1.0

      - name: Auto Commit
        uses: stefanzweifel/git-auto-commit-action@v4
        with:
          commit_message: Apply Pint

aglipanci/laravel-pint-action オプション

      - name: Apply Pint
        uses: aglipanci/laravel-pint-action@2.1.0
          with:
            preset: laravel
            configPath: "src/pint.json"
            pintVersion: 1.4.0
            verboseMode: true
            testMode: true
  • preset: 現在サポートされているpresetは laravel, psr12, symfony
  • configPath: 設定ファイルを用意している場合は指定する
  • verboseMode: 詳細を表示する
  • testMode: 実際にファイル変更せず、コードスタイルの検査のみ

stefanzweifel/git-auto-commit-action のための PERSONAL_ACCESS_TOKEN の設定

CI上でコミットさせるためにパーソナルアクセストークンを取得します。
リポジトリの設定 Settings > Security > Secrets and variables > Actions > New repository secret
PERSONAL_ACCESS_TOKEN の名前で取得したパーソナルアクセストークンを追加すればOKです。

詳細なルール設定

別記事で細かい設定について書いてます。

7
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?