1
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 のmatrix - 配列の繰り返し処理のようなもの

Posted at

matrixって結局なに?

matrixは、配列の要素を順番に処理していくような機能です。
プログラミングでいう「for文」のようなものです。

基本的な書き方

jobs:
  example:
    strategy:
      matrix:
        name: [a, b, c]
    steps:
      - run: echo ${{ matrix.name }}

これは以下のようなコードのイメージです:

names = ['a', 'b', 'c']
for name in names:
    print(name)

もう少し実用的な例

jobs:
  build:
    strategy:
      matrix:
        service: [frontend, backend, worker]
    steps:
      - run: docker build -f ${{ matrix.service }}/Dockerfile .

これは以下の処理が実行されます:

  • docker build -f frontend/Dockerfile .
  • docker build -f backend/Dockerfile .
  • docker build -f worker/Dockerfile .

複数の配列も組み合わせられる

strategy:
  matrix:
    name: [frontend, backend]
    env: [dev, stg, prod]

これは以下の組み合わせが実行されます:

  • frontend + dev
  • frontend + stg
  • frontend + prod
  • backend + dev
  • backend + stg
  • backend + prod

まとめ

  • matrixは配列の繰り返し処理みたいなもの
  • 複数の配列を組み合わせることもできる

シンプルですが強力な機能なので、同じような処理を複数回実行するときに活用してみてください!

1
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
1
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?