Friday, November 5, 2021

Matrix to use multiple arbitrary values for environments, like different nodejs versions,different OSs

 

name: Matrix
on: push
jobs:
  node-version:
    strategy:
      matrix:
        os: [macos-latest,ubuntu-latest,windows-latest] #run three times here
        node-version: [6,8,10] #runs three times here
        #we can create some arbitrary array and use that context also here
      
      max-parallel: 2
      fail-fast: true #if false, above 3 jobs will be independent, total 2 matrix with 3 values each so 3x3=9 jobs
    runs-on: ${{matrix.os}}
    steps:
      - name: Log node node version 
        run: node -v 
      - uses: actions/setup-node@v1
        with:
          node-version: ${{matrix.node_version}}
      - name: Log node node version 
        run: node -v


To exclude some specific parts above.
include will add extra values to existing configuration, it won't add a new iteration.
name: Matrix
on: push
jobs:
  node-version:
    strategy:
      matrix:
        os: [macos-latest,ubuntu-latest,windows-latest] #run three times here
        node-version: [6,8,10] 
        include: 
          - os: ubuntu-latest
            node-version: 8
            is_ubuntu_8: "true"
        exclude:
          - os: ubuntu-latest
            node-version: 6
          - os: macos-latest
            node-version: 8
      
      max-parallel: 2
      fail-fast: true #if false, above 3 jobs will be independent, total 2 matrix with 3 values each so 3x3=9 jobs
    runs-on: ${{matrix.os}}
    env: 
      IS_UBUNTU_8: ${{matrix.is_ubuntu_8}}
    steps:
      - name: Log node node version 
        run: node -v 
      - uses: actions/setup-node@v1
        with:
          node-version: ${{matrix.node_version}}
      - name: Log node node version 
        run:  |
          node -v
          echo $IS_UBUNTU_8

No comments:

Post a Comment