Matrix.os fails to match

Am trying to build pyinstaller executables for multiple OSs, Since MS windows uses “;” separators I used ‘matrix.os’ to switch the run command.

However ‘build with pyinstaller on gnu/Linux and MacOS’ step runs on all OS including MS windows.

Could someone point what I am missing here. Thanks

name: Package Excalibur with Pyinstaller

on:
  push:
    branches: [master]
  pull_request:
    branches: [master]

jobs:
  build:
    runs-on: ${{ matrix.config.os }}

    strategy:
      matrix:
        config:
          - { os: macos-latest, arch: x64, name: macos-latest }
          - { os: ubuntu-latest, arch: x64, name: ubuntu-latest }
          - { os: windows-latest, arch: x64, name: windows-latest }
          - { os: windows-latest, arch: ia32, name: windows-latest-32 }

    steps:
      - uses: actions/checkout@v1
      - name: Set up Python 3.8
        uses: actions/setup-python@v1
        with:
          python-version: 3.8
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install pyinstaller
      - name: build with pyinstaller on gnu/Linux and MacOS
        if: matrix.os == 'ubuntu-latest' || 'macos-latest'
        run: |
          pyi-makespec --paths=excalibur/executors/celery_executor.py arthur.py
          pyinstaller --onefile --add-data "excalibur/www/templates:excalibur/www/templates" --add-data "excalibur/www/static:excalibur/www/static" --add-data "excalibur/config_templates:excalibur/config_templates" arthur.py
      - name: build with pyinstaller on MS Windows
        if: matrix.os == 'windows-latest'
        run: |
          pyi-makespec --paths=excalibur/executors/celery_executor.py arthur.py
          pyinstaller --onefile --add-data "excalibur/www/templates;excalibur/www/templates" --add-data "excalibur/www/static;excalibur/www/static" --add-data "excalibur/config_templates;excalibur/config_templates" arthur.py
  #  - uses: actions/upload-artifact@v2
  #     with:
  #       name: name-of-artifact
  #       path: src/dist/
1 Like

I’d guess the problem is the missing matrix.os == before 'macos-latest', and then the non-empty string evaluates to true.

2 Likes

Thank you! That fixed it.

1 Like

@arky,

The problem is caused by the incorrect expressions you are using in the if conditional:

  1. You are using the incomplete expression (matrix.os) to access the value of os from the matrix context. The correct and complete expression should be “matrix.config.os”, and you can’t omit any node from the expression.
if: ${{ matrix.config.os == 'windows-latest' }}
  1. Both sides of the logical operator (&& or ||) must be complete conditional statements. You can’t omit any part from the conditional statements. The correct and complete conditional statements should be like as below.
if: ${{ matrix.config.os == 'ubuntu-latest' || matrix.config.os == 'macos-latest' }}

In summary, the correct configurations in your workflow should be like as below:

jobs:
  build:
    runs-on: ${{ matrix.config.os }}
    strategy:
      matrix:
        config:
          - { os: macos-latest, arch: x64, name: macos-latest }
          - { os: ubuntu-latest, arch: x64, name: ubuntu-latest }
          - { os: windows-latest, arch: x64, name: windows-latest }
          - { os: windows-latest, arch: ia32, name: windows-latest-32 }
    steps:
      . . .

      - name: build with pyinstaller on gnu/Linux and MacOS
        if: ${{ matrix.config.os == 'ubuntu-latest' || matrix.config.os == 'macos-latest' }}
        . . .

      - name: build with pyinstaller on MS Windows
        if: ${{ matrix.config.os == 'windows-latest' }}
        . . .
2 Likes

Thank you @brightran @airtower-luna

I ended up using the similar runner.os context instead of martix.config.os

if: runner.os == 'Linux' || runner.os == 'macOS'

if: runner.os == 'Windows'

2 Likes