Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop github action matrix case

I want to use a github action matrix for different build types, but there's one case of the matrix that I'm not interested in supporting. How do I stop this case from running but still get the build to marked successfully.

In this particular case I want to build Windows and Ubuntu, 32bit and 64bit but I'm not interested in supporting 32bit on Ubuntu. So my matrix would be:

    strategy:
      fail-fast: false
      matrix:
        os: [windows-latest, ubuntu-latest]
        platform: ['x64', 'x86']

My current solution is to stop each action running by adding an if expression:

    - name: Build Native
      if: ${{ ! (matrix.os == 'ubuntu-18.04' && matrix.platform == 'x86') }}

While this works okay, I feel there ought to be a more elegant way of solving this. Can anyone help make my yaml script more beautiful?

like image 688
Robert Avatar asked Apr 24 '21 07:04

Robert


People also ask

What is GitHub Head_ref?

github.head_ref. string. The head_ref or source branch of the pull request in a workflow run. This property is only available when the event that triggers a workflow run is either pull_request or pull_request_target .

How do I skip an action in GitHub?

Github action for skipping workflows upon matching or finding phrase in commit message(s) or pull request. Works by searching for phrase in or matching RegExp with commit message(s), pull request title, and/or pull request body. skip output value can then be used to conditionally skip the following jobs or steps.

What is matrix in GitHub action?

A matrix strategy lets you use variables in a single job definition to automatically create multiple job runs that are based on the combinations of the variables. For example, you can use a matrix strategy to test your code in multiple versions of a language or on multiple operating systems.


2 Answers

Perhaps the strategy.matrix.exclude directive is suitable?

From the documentation:

You can remove a specific configurations defined in the build matrix using the exclude option. Using exclude removes a job defined by the build matrix.

So in your case, probably something like this:

strategy:
  matrix:
    os: [windows-latest, ubuntu-latest]
    platform: ['x64', 'x86']
    exclude:
      - os: ubuntu-latest
        platform: x86
like image 117
DannyB Avatar answered Dec 11 '22 00:12

DannyB


There are situations where one wants to include or exclude specific matrix coordinates so as not to run some of them, yet (stretching the question a bit) also still want the job to run for a couple of these coordinates, so as to track the evolution of it across commits, while not blocking the whole process.

In that situation, continue-on-error at the job level, combined with matrix include and exclude is very useful:

Prevents a workflow run from failing when a job fails. Set to true to allow a workflow run to pass when this job fails.

This is similar to GitLab CI's allow_failure, although at time of writing GitHub Actions UI only has two states (red failed and green passed) whereas GitLab introduces a third one (orange warning) in that case.

Here is a real-life workflow example:

jobs:
    linux:
        continue-on-error: ${{ matrix.experimental }}
        strategy:
            fail-fast: false
            matrix:
                os:
                    - ubuntu-20.04
                container:
                    - 'ruby:2.0'
                    - 'ruby:2.1'
                    - 'ruby:2.2'
                    - 'ruby:2.3'
                    - 'ruby:2.4'
                    - 'ruby:2.5'
                    - 'ruby:2.6'
                    - 'ruby:2.7'
                    - 'ruby:3.0'
                    - 'ruby:2.1-alpine'
                    - 'ruby:2.2-alpine'
                    - 'ruby:2.3-alpine'
                    - 'ruby:2.4-alpine'
                    - 'ruby:2.5-alpine'
                    - 'ruby:2.6-alpine'
                    - 'ruby:2.7-alpine'
                    - 'jruby:9.2-jdk'
                experimental:
                    - false
                include:
                    - os: ubuntu-20.04
                      container: 'ruby:3.0.0-preview2'
                      experimental: true
                    - os: ubuntu-20.04
                      container: 'ruby:3.0.0-preview2-alpine'
                      experimental: true
like image 21
Lloeki Avatar answered Dec 11 '22 01:12

Lloeki