ediie726 / action-workflow-matrix

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

action-workflow-matrix

License

GitHub action to generate build matrix from yaml file

Requirements

  • checkout repository to read the yaml file
- uses: actions/checkout@v2

Usage

- uses: bonddim/action-workflow-matrix@stable
  with:
    matrix-file: "${{ github.workspace }}/.github/workflow-matrix.yml"
    # [optional]
    # The YAML file with matrix. Default is .github/workflow-matrix.yml
    # Action will fail if file not found
    workflow: "${{ github.workflow }}"
    # [optional]
    # Key in the matrix file to get the matrix. Default is '${{ github.workflow }}'
    # Action will generate matrix from default key (matrix) if workflow key is not defined in matrix file
    # Action will generate empty matrix if workflow and matrix keys are not defined in matrix file

Example of .github/workflow-matrix.yml:

---
matrix: &default
  node: [12, 14]
  os: [ubuntu-latest, windows-latest, macos-latest]
  include: &default_icnlude
    - node: 16
      os: ubuntu-latest

# Overwrite parameter
ubuntu:
  matrix:
    <<: *default
    os: [ubuntu-latest]

# Overwrite include
include:
  matrix:
    <<: *default
    include:
      - os: ubuntu-18.04
        node: 10

# Note: All include combinations are processed after exclude. This allows you to use include to add back combinations that were previously excluded.
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix
# Exclude from default matrix
exclude:
  matrix:
    <<: *default
    exclude:
      - os: macos-latest
        node: 12
      - os: windows-latest
        node: 14

# Additional parameters
parameter:
  matrix:
    <<: *default
    experimental: [true]
    foo: [bar]
# This workflow will generate default matrix
name: default

jobs:
  matrix:
    runs-on: ubuntu-latest
    outputs:
      matrix: ${{ steps.set-matrix.outputs.matrix }}
    steps:
      - uses: actions/checkout@v2
      - name: Set build matrix
        id: set-matrix
        uses: bonddim/action-workflow-matrix@stable

  build:
    runs-on: ${{ matrix.os }}
    needs: matrix
    strategy:
      fail-fast: false
      matrix: ${{ fromJson(needs.matrix.outputs.matrix) }}
    steps:
      - name: Dump matrix context
        run: echo "$MATRIX_CONTEXT"
        env:
          MATRIX_CONTEXT: ${{ toJSON(matrix) }}

Check other build examples:

License

MIT

About

License:MIT License


Languages

Language:JavaScript 100.0%