NeLy-EPFL / flygym

Simulating embodied sensorimotor control with NeuroMechFly v2
https://neuromechfly.org/
Apache License 2.0
20 stars 6 forks source link

Rendering doesn't work on Github Actions runners #170

Closed sibocw closed 3 months ago

sibocw commented 3 months ago

Despite usual env variables to render with CPU on headless machine, .render() breaks the test during automated testing with Github Actions.

sibocw commented 3 months ago

Working now - see minimal reproducible example here: https://github.com/NeLy-EPFL/neuromechfly-ci-test

The solution

  1. Install renderer dependencies:
    • sudo apt-get update
    • sudo apt-get install -y libgl1-mesa-dev libgl1-mesa-glx libosmesa6-dev
  2. Set environmental variables with echo "VARIABLE=value" >> $GITHUB_ENV. Environment variables set using export VARIABLE=value within a single step are not automatically available to subsequent steps. This is because each step in a GitHub Actions workflow runs in its own process and environment.

Helpful tools

  1. SSH into the runner to debug interactively (!) with action-upterm
  2. Upload output as "artifacts" with upload-artifact. The uploaded file can be easily accessed from the Artifact section of the Action summary page (see this).

Final YAML file for workflow

name: MuJoCo Tests

on: [push]

# env:
#   LD_PRELOAD: /usr/lib/x86_64-linux-gnu/libGLEW.so

jobs:
  build:

    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.12"]

    steps:
      - uses: actions/checkout@v3
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}  
      - name: Set up renderer
        run: |
          sudo apt-get update
          sudo apt-get install -y libgl1-mesa-dev libgl1-mesa-glx libosmesa6-dev
          echo "MUJOCO_GL=egl" >> $GITHUB_ENV
          echo "PYOPENGL_PLATFORM=egl" >> $GITHUB_ENV
      - name: Install dependencies
        run: |
          pip install --upgrade pip
          pip cache purge
          git clone https://github.com/NeLy-EPFL/flygym.git
          cd flygym
          pip install -e .
          cd ..
      - name: Test script
        run: |
          pwd
          python tests/render_test.py
      # - name: Debugging with ssh
      #   uses: lhotari/action-upterm@v1
      - name: Upload artifacts
        uses: actions/upload-artifact@v4
        with:
          name: upload-rendered-video
          path: video.mp4
          if-no-files-found: error
          retention-days: 1
          compression-level: 6
          overwrite: false