matlab-actions / .github

Automate your workflows with GitHub actions for MATLAB.
66 stars 2 forks source link

Should state be saved between steps? #6

Closed H0R5E closed 2 years ago

H0R5E commented 2 years ago

Hi, I was just wondering if the behaviour I am seeing when calling MATLAB in batch mode across multiple steps is expected. For instance, when I combine installing my toolbox and my (basic) test, everything works fine:

      - name: Install and test MHKiT-MATLAB
        run: |
          matlab -batch \
            "matlab.addons.toolbox.installToolbox('mhkit.mltbx'), \
             import mhkit.river.performance.*, \
             [x, y] = circular(30)"
Run matlab -batch \
  matlab -batch \
    "matlab.addons.toolbox.installToolbox('mhkit.mltbx'), \
     import mhkit.river.performance.*, \
     [x, y] = circular(30)"
  shell: /usr/bin/bash -e {0}
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.7.12/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.7.12/x64/lib

    Sponsored License -- for use in support of a program or activity sponsored by MathWorks.
    Not for government, commercial or other non-sponsored organizational use.

[Warning: Name is nonexistent or not a directory: /home/runner/MATLAB
Add-Ons/Toolboxes/mhkit/tests/test_results] 
[> In path (line 109)
In addpath (line 84)
In matlab.addons.enableAddon (line 82)
In matlab.addons.install/launchInstallation (line 221)
In matlab.addons.install (line 177)
In matlab.addons.toolbox.installToolbox
In mdcsbatch (line 58)
[Warning: Name is nonexistent or not a directory: /home/runner/MATLAB
Add-Ons/Toolboxes/mhkit/tests/test_results/_rels] 
[> In path (line 109)
In addpath (line 84)
In matlab.addons.enableAddon (line 82)
In matlab.addons.install/launchInstallation (line 221)
In matlab.addons.install (line 177)
In matlab.addons.toolbox.installToolbox
In mdcsbatch (line 58)] 
[Warning: Name is nonexistent or not a directory: /home/runner/MATLAB
Add-Ons/Toolboxes/mhkit/tests/test_results/images] 
[> In path (line 109)
In addpath (line 84)
In matlab.addons.enableAddon (line 82)
In matlab.addons.install/launchInstallation (line 221)
In matlab.addons.install (line 177)
In matlab.addons.toolbox.installToolbox
In mdcsbatch (line 58)] 
[Warning: Name is nonexistent or not a directory: /home/runner/MATLAB
Add-Ons/Toolboxes/mhkit/tests/test_results/stylesheets] 
[> In path (line 109)
In addpath (line 84)
In matlab.addons.enableAddon (line 82)
In matlab.addons.install/launchInstallation (line 221)
In matlab.addons.install (line 177)
In matlab.addons.toolbox.installToolbox
In mdcsbatch (line 58)] 

ans = 

  struct with fields:

       Name: 'mhkit'
    Version: '0.3.2'
       Guid: 'a2dc6eda-931e-408a-8e3c-8f63d1f9da82'

x =

    30

y =

   1.1310e+04

However, when I split the installation and the test step it fails:

      - name: Install MHKiT-MATLAB
        run: |
          matlab -batch \
            "matlab.addons.toolbox.installToolbox('mhkit.mltbx')"
      - name: Run basic test
        run: |
          matlab -batch \
            "import mhkit.river.performance.*, \
             [x, y] = circular(30)"
Run matlab -batch \

    Sponsored License -- for use in support of a program or activity sponsored by MathWorks.
    Not for government, commercial or other non-sponsored organizational use.

[Warning: Name is nonexistent or not a directory: /home/runner/MATLAB
Add-Ons/Toolboxes/mhkit/tests/test_results] 
[> In path (line 109)
In addpath (line 84)
In matlab.addons.enableAddon (line 82)
In matlab.addons.install/launchInstallation (line 221)
In matlab.addons.install (line 177)
In matlab.addons.toolbox.installToolbox
In mdcsbatch (line 58)] 
[Warning: Name is nonexistent or not a directory: /home/runner/MATLAB
Add-Ons/Toolboxes/mhkit/tests/test_results/_rels] 
[> In path (line 109)
In addpath (line 84)
In matlab.addons.enableAddon (line 82)
In matlab.addons.install/launchInstallation (line 221)
In matlab.addons.install (line 177)
In matlab.addons.toolbox.installToolbox
In mdcsbatch (line 58)] 
[Warning: Name is nonexistent or not a directory: /home/runner/MATLAB
Add-Ons/Toolboxes/mhkit/tests/test_results/images] 
[> In path (line 109)
In addpath (line 84)
In matlab.addons.enableAddon (line 82)
In matlab.addons.install/launchInstallation (line 221)
In matlab.addons.install (line 177)
In matlab.addons.toolbox.installToolbox
In mdcsbatch (line 58)] 
[Warning: Name is nonexistent or not a directory: /home/runner/MATLAB
Add-Ons/Toolboxes/mhkit/tests/test_results/stylesheets] 
[> In path (line 109)
In addpath (line 84)
In matlab.addons.enableAddon (line 82)
In matlab.addons.install/launchInstallation (line 221)
In matlab.addons.install (line 177)
In matlab.addons.toolbox.installToolbox
In mdcsbatch (line 58)] 

ans = 

  struct with fields:

       Name: 'mhkit'
    Version: '0.3.2'
       Guid: 'a2dc6eda-931e-408a-8e3c-8f63d1f9da82'
Run matlab -batch \
  matlab -batch \
    "import mhkit.river.performance.*, \
     [x, y] = circular(30)"
  shell: /usr/bin/bash -e {0}
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.7.12/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.7.12/x64/lib

    Sponsored License -- for use in support of a program or activity sponsored by MathWorks.
    Not for government, commercial or other non-sponsored organizational use.

{Undefined function 'circular' for input arguments of type 'double'.
} 
Error: Process completed with exit code 1.

Is this expected behaviour? The full (working) workflow is as follows:

name: Run MATLAB tests

on:
  push:
    branches: [ github_actions ]
  pull_request:
    branches: [ github_actions ]

jobs:
  main:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version: [3.7, 3.8, 3.9]
    env:
      mhkit-python-dir: 'MHKiT-Python'
    steps:
      - name: Check out MHKiT-MATLAB
        uses: actions/checkout@v2
      - name: Check out MHKiT-Python
        uses: actions/checkout@v2
        with:
          repository: 'MHKiT-Software/MHKiT-Python'
          path: ${{env.mhkit-python-dir}}
      - name: Set up MATLAB
        uses: matlab-actions/setup-matlab@v1
      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install MHKiT-Python
        run: python -m pip install -e . "matplotlib<3.4.2"
        working-directory: ${{env.mhkit-python-dir}}
      - name: Install and test MHKiT-MATLAB
        run: |
          matlab -batch \
            "matlab.addons.toolbox.installToolbox('mhkit.mltbx'), \
             import mhkit.river.performance.*, \
             [x, y] = circular(30)"
mcafaro commented 2 years ago

Hi @H0R5E,

This is expected behavior because the -batch option disables persistent changes to preferences. Preferences are used to register the installation of a toolbox.

You can find all the effects of using -batch listed under the input arguments section on this page: https://www.mathworks.com/help/matlab/ref/matlablinux.html

Best, Mark

H0R5E commented 2 years ago

@mcafaro, so are you saying there is no way to store preferences during a CI run? matlab-actions/run-command just calls -batch as well, as far as I can tell.

EDIT: It's not an issue once you know this, as you can just build a super long command or have a script prepared to do everything in one call, but I think it's worth documenting the fact, as my colleagues were stumped for weeks because of successive calls to run-command not working as expected.

mcafaro commented 2 years ago

@H0R5E that is right (at least for GitHub-hosted agents). GitHub-hosted agents are currently only licensed for MATLAB execution with the -batch option, which does not persist preferences between launches. Self-hosted agents have more flexibility over licensing and don't necessarily need to use -batch.

Reopening to see if we can better highlight this behavior in the doc. Is there a particular place you would have hoped to see this behavior mentioned?

H0R5E commented 2 years ago

@mcafaro, I think somewhere in the Run MATLAB Command section of the matlab-actions/run-command README would be useful. I'm happy to do a quick PR if that would be helpful.

Mat

mcafaro commented 2 years ago

@H0R5E, if you are willing to complete an individual CLA (Contributor License Agreement), we would happily review a PR. Otherwise, we have this issue open for tracking. Thanks for bringing it to our attention.