LoginSignup
0
0

Pull Requestのタイミングでlinter・formatterを実行する方法

Last updated at Posted at 2023-12-17

やりたいこと

プルリクのタイミングでlinter・formatterを実行させて、成功しないとマージできないようにしたい。

Pipelineの設定

1. 新しいPipelineを作成

スクリーンショット 2023-12-17 19.20.32.png
Azure Devopsの左サイドバーから「Pipelines」を選択して、右上にある「New pipeline」を押下。


スクリーンショット 2023-12-17 19.20.44.png
Azure Repos Git」を押下。
次のタブで対象のリポジトリを選択。


スクリーンショット 2023-12-17 19.20.52.png
Starter pipeline」を押下。


スクリーンショット 2023-12-17 19.21.03.png
pipelineのファイル名を変えます。
今回は「continuous-integration.yml」にしました。


2. yamlファイルの作成

continuous-integration.yml
trigger:
- none

pool:
  vmImage: ubuntu-latest
strategy:
  matrix:
    Python39:
      python.version: '3.9'

steps:
- script: |
    python -m pip install black
    black --check --diff .
  displayName: 'Run format tests'

- script: |
    python -m pip install isort
    isort --check-only .
  displayName: 'Run import sort tests'

- script: |
    python -m pip install pyproject-flake8
    pflake8 .
  displayName: 'Run lint tests'

- script: |
    python -m pip install mypy
    mypy --ignore-missing-imports .
  displayName: 'Run type check tests'

▪️ trigger...「none」でOK。
▪️ strategy...Pythonのバージョンは複数選ぶことも可能です。今回はPython3.9を使ってるので「'3.9'」に設定。
▪️ steps....ここに実行させたいコマンドを入れていきます。


...以上でpipelineの設定は完了。

プルリクのタイミングで実行されるように設定

スクリーンショット 2023-12-12 23.18.21.png
Devopsの左サイドバーから「Repos」→「Branches」を選択。

スクリーンショット 2023-12-12 23.18.37.png
右の3点リーダーボタンから「Branch policies」を選択。

スクリーンショット 2023-12-12 23.19.33.png
Build Validation」に新しく追加をしていく。
右の「+」ボタンを選択。

スクリーンショット 2023-12-12 23.19.52.png

先ほど作成したPipelineを選択。
そのほかの設定は、
▪️ Trigger...こちらは自動でおこなって欲しいので、「Automatic」を選択。
▪️ Policy requirement...成功しないとマージできないようにしたいので「Required」を選択。
▪️ Build expiration...ビルドの有効期限ですが、こちらは「Never」を選択。

「save」をクリック。
...

スクリーンショット 2023-12-12 23.20.01.png
するとスクショのように「Build Validation」に新しく追加されたと思います。

検証

スクリーンショット 2023-12-12 23.20.15.png
ブランチにプルリクを作成すると自動でPipelineが実行されました。
succeededになったのでマージできました。

0
0
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
0
0