Open1

GitHug Actions

みつよしみつよし

テストが失敗するPull Requestのマージを防ぐ

  1. テストを実行するGitHub Actionsのworkflowを作成
  2. workflowをstatus checkに設定する

1. テストを実行するGitHub Actionsのworkflowを作成

name: Run Test

on:
  pull_request: # このworkflowを実行するトリガー
    # Documentation: https://docs.github.com/ja/actions/reference/events-that-trigger-workflows#
    # typesが具体的に何を示しているのかDocumentationに記載がないのでそれらしいものを列挙する
    types: [ opened, reopened, edited, synchronize ]

jobs:
  test: # ジョブ名: 任意でつけていいらしい
    name: Test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - run: yarn install
      - run: yarn jest

master or mainブランチに取り込まれなくとも、pushされた and or PullRequestが作成された時点でworkflowは有効化する

2. workflowをstatus checkに設定する

  1. GitHubのリポジトリページの Settings -> Branches からAdd ruleでBranch Protection Ruleを作成する
  2. Branch name patternに保護したいブランチ名を入力する
  3. Require status checks to pass before mergingにチェックを入れる
  4. 2により現れたサブメニューに先程作成したworkflow名が出てくるのでチェックを入れる

Reference