1

I want to set the matrix group of my job dynamically, based on the branch name. This is my workflow:

name: Deploy

on:
  release:
    types: [released]
  push:
    branches:
      - 'staging'
jobs:
  matrix_prep:
    runs-on: ubuntu-latest
    outputs:
      matrix: ${{ steps.set-matrix.outputs.matrix }}
    steps:
      - uses: actions/checkout@v2
      - id: set-matrix
        run: |
          branchName=$(echo '${{ github.ref }}' | sed 's,refs/heads/,,g')
          echo $branchName
          [[ $branchName = 'staging' ]] && type="staging" || type="release"
          matrix=$(jq --arg branchName "$branchName" 'map(. | select(.type==$branchName) )' .github/workflows/matrix_includes.json)
          echo $matrix
          echo ::set-output name=matrix::{\"include\":$(echo $matrix)}\"
  deploy:
    runs-on: ubuntu-20.04
    strategy:
      matrix: ${{fromJson(needs.matrix_prep.outputs.matrix.config)}}

The JSON file I'm referring to is this one:

[
  {
    "type": "staging",
    "config": {
      "group": [
        "staging"
      ]
    }
  },
  {
    "type": "release",
    "config": {
      "group": [
        "prod"
      ]
    }
  }
]

I'm basing this logic on this answer. I cannot see what I'm doing different. This is the result of the github action execution:

enter image description here

Any idea how to fix it? Is more information needed?

Antonio Gamiz Delgado
  • 1,871
  • 1
  • 12
  • 33

0 Answers0