Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 2
Message 1 of 3

how to create dynamic matrix value?

Solved! Go to Solution.

hello,

 

I know from this post that the matrix can not be a value from secrets.

any thoughts on how to make matrix value can be dynamic, so I don't need to change the workflow file every time I add a new app?

 

so here's my current yml file:

 

jobs:
  build:

    runs-on: ubuntu-latest
    strategy:
      max-parallel: 4
      matrix:
        python-version: [3.6, 3.7, 3.8]
        django-version: [2.2, 3.0.0]
        django-app: [halo, splitviewsmodels]

 

 

actually the django-app list is a directory names inside my project, so I can easily get the names of it, if I can't set the value from secrets(?)

 

thank you for your help.

 

 

2 Replies
Solution
GitHub Partner
Message 2 of 3

Re: how to create dynamic matrix value?

Currently, we have no any way to make the values of a matrix parameter can be dynamic.

If you want to add new values into the matrix parameter, you have to change the workflow definition every time. You can use the keyword exclude in the matrix job to let job not run for some combinations of the configurations.

There is a ticket reported the similar question as reference: https://github.community/t5/GitHub-Actions/Dynamically-Select-Secrets/td-p/42612

Ground Controller Lvl 2
Message 3 of 3

Re: how to create dynamic matrix value?

Im actually really keen on this idea.

 

Im using the matrix to build apps in my mono repo, but ideally I'd only like to build apps that have changed.

 

So im looking for something like: (beware sudo code)

 

 

jobs:
  collect_apps:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - run: echo "find changed paths"
      - run: |
          # for each app
            echo "::add-matrix name=app::%changed_path%"
          # end for each
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        app: ${{ steps.collect_apps.matrix }}
    env:
      TZ: Australia/Brisbane
    steps:
      - uses: actions/checkout@v1
      - run: yarn install
      - name: Build (${{ matrix.app }})
        id: app_built
        run: |
          yarn workspace ${{ matrix.app }} build;
          echo "::set-output name=dist_dir::apps/${{ matrix.app }}/dist"
      - uses: actions/upload-artifact@v1.0.0
        with:
          name: ${{ matrix.app }}
          path: ${{ steps.app_built.outputs.dist_dir }}