Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Github actions】workflow_dispatchのinputsでmatrixの内容を動的に変更する

Posted at

背景

弊社のQAチームでは、E2EテストをPlaywrightを用いて実行しておりますが、シナリオ数増大に伴ってテスト実行時間の増加・テストが不安定になるなどが課題になっておりました。(純粋にPlaywrightのWorkersを増やして並列実行するとやや不安定な挙動になるように見受けられました。)
そこでE2Eテストをディレクトリで分けて、Github actionsのmatrixを使ってディレクトリごとに並列実行することにより上記の課題を解決できないかと考えました。

matrixを使用してPlaywrightのテストを実行

純粋にmatrixを使用してディレクトごとに並列でPlaywrightのテストを実行するコードの例は以下のような形になるかと思います。(nameの配列で指定している名前でテストがディレクトリ分けされているものとします。)

test.yaml
name: e2e
on:
  workflow_dispatch:
jobs:
  test:
    strategy:
      fail-fast: false
      matrix:
        name: ["apple", "banana", "orange"]
    timeout-minutes: 60
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - name: Install dependencies
        run: npm ci
      - name: Install Playwright Browsers
        run: npx playwright install --with-deps
      - name: Run Playwright tests
        run: npx playwright test --project=e2e-${{ matrix.name }}

workflow_dispatchのinputsを使うように修正

しかし上記のコードでは、ひとつのディレクトリのテストのみを実行したいシチュエーションに対応できない形となっています。そこでworkflow_dispatchのinputsからmatrixの内容を動的に変更して、テストを実行したいディレクトリを指定できるように修正します。

test2.yaml
name: e2e
on:
  workflow_dispatch:
      inputs:
          tenant:
            description: "tenant"
            type: choice
            options:
              - '"apple","banana","orange"'
              - '"apple"'
              - '"banana"'
              - '"orange"'
            required: true
jobs:
  test:
    strategy:
      fail-fast: false
      matrix:
        name: ${{ fromJSON(format('[{0}]', inputs.tenant || '"apple","banana","orange"')) }}
    timeout-minutes: 60
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - name: Install dependencies
        run: npm ci
      - name: Install Playwright Browsers
        run: npx playwright install --with-deps
      - name: Run Playwright tests
        run: npx playwright test --project=e2e-${{ matrix.name }}

Actionsでのinputsの選択イメージとしては以下のような形となるかと思います。
image.png

以下の記述をすることで、workflow_dispatchで選択した値をmatrixに指定することができます。例えばappleを選択した場合は、appleディレクトリのファイルのみテストが実行されます。特に指定がない場合は、"apple","banana","orange"ディレクトリすべてが実行されます。

matrix:
        name: ${{ fromJSON(format('[{0}]', inputs.tenant || '"apple","banana","orange"')) }}
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

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?