-
I have a matrix like this:
I would like to only run the dev-dart and insiders-vscode builds for the master branch, and have only the stable/stable versions run for other branches. I can’t find a way to make these values conditional (either here, or by using exclude). |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments
-
Hi @dantup , Currently, GitHub Actions does not support to filter breaches for matrix jobs. However, as a workaround, you can try to copy two workflows, one only for master branch and one for other branches, then set different branch filters on event and configure different values for the matrix parameters based on the branches.
|
Beta Was this translation helpful? Give feedback.
-
Thanks - that would probably work, but my workflow is quite large and maintaining two of them wouldn’t be ideal. Is it possible this may change in future? To do something similar on Travis, you can have a top-level
And on AppVeyor you can use a
|
Beta Was this translation helpful? Give feedback.
-
I’m looking for something similar - I’m actually trying to only run the job if the matrix option matches a particular value - unfortunately it seems that’s not an option at the job level, so I’d have to do it at the step level, which defeats the purpose |
Beta Was this translation helpful? Give feedback.
-
I’m looking for something similar as well: out of my 4 target configurations Ubuntu, MacOS, Android and iOS I would like to specify that only Ubuntu configuration should be ran on regular daily check-ins into say master (to save me precious minutes), while all 4 configurations should only be ran when I create a version tag (since I also need binaries released for each of the versions). The condition for inclusion of a specific configuration might become more complicated later, but this should be a useful enough use case scenario for you to consider. Here is one thing I tried. In your post from October 1, 2019 “GitHub Actions - New Workflow Syntax Features” you announce support for if: at the job level. So one natural thing I tried was:
but the conditional line gave me error:
|
Beta Was this translation helpful? Give feedback.
-
I think I have now found a workaround for excluding matrix options based on branch. The idea is to simply add the
with this configuration only on all branches with ‘stable’ in the name as well as beginning with ‘v’ all flavors will be built, while on all other branches i exclude the mentioned flavors. |
Beta Was this translation helpful? Give feedback.
-
Dynamic matrix can be used according to this example: https://docs.github.com/en/free-pro-team@latest/actions/reference/context-and-expression-syntax-for-github-actions#example-6.
However I have not figured out how to construct the matrix as a string… Maybe someone of you could figure it out and share. |
Beta Was this translation helpful? Give feedback.
-
Thanks. Your strategy worked for me! In case anyone wants to have a look, here’s the addition: Disable `pr` env in `main` branch by joaomcteixeira · Pull Request #31 · joaomcteixeira/python-project-skeleton · GitHub |
Beta Was this translation helpful? Give feedback.
-
Similar here, thank you! I use the following to run only the (fast) linux/amd64 docker build in pull requests: docker_build:
runs-on: ubuntu-latest
strategy:
matrix:
platform:
- linux/amd64
- linux/arm64
isPR:
- ${{github.event_name == 'pull_request'}}
# Run only the amd64 build in pull reqs:
exclude:
- { isPR: true }
include:
- { platform: "linux/amd64" } |
Beta Was this translation helpful? Give feedback.
-
not sure whether this helps the OP's issue, but i landed here when trying to figure out how to do conditional matrix values. here, what i want is to set defaults for my automated deploys and then accept an input for manual deploys. the big unlock for me is that matrix works with sequences so we can pass them in via on:
workflow_dispatch:
inputs:
env:
description: 'Environment to deploy to'
type: choice
required: true
options:
- sandbox
- dev
- staging
- prod
push:
tags: # or whatever automated thing
- *
jobs:
deploy:
strategy:
matrix:
# defaults defined inline here
env: ${{ github.event.inputs.env && fromJson(format('["{0}"]', github.event.inputs.env)) || fromJson('["dev", "staging"]') }} |
Beta Was this translation helpful? Give feedback.
I think I have now found a workaround for excluding matrix options based on branch. The idea is to simply add the
github.ref
variable to the matrix and thenexclude
it:with this configuration only on al…