diff --git a/.github/workflows/regenerate-matlab-bindings.yml b/.github/workflows/regenerate-matlab-bindings.yml new file mode 100644 index 0000000..e8a5b5c --- /dev/null +++ b/.github/workflows/regenerate-matlab-bindings.yml @@ -0,0 +1,100 @@ +name: Regenerate MATLAB bindings +# This action regenerates the MATLAB bindings for CasADi +# Inspired from: +# * https://github.com/robotology/yarp-matlab-bindings/blob/master/.github/workflows/regenerate-matlab-bindings.yml +# * https://github.com/robotology/idyntree/blob/master/.github/workflows/regenerate-matlab-bindings.yml + +on: + workflow_dispatch: + pull_request: + +jobs: + regenerate-matlab-bindings: + name: "Regenerate MATLAB bindings" + # Use Ubuntu Bionic as the https://github.com/casadi/casadi/wiki/matlab suggest to use GCC 7 + runs-on: [ubuntu-18.04] + steps: + - uses: actions/checkout@v2 + + - name: Install dependencies via apt + run: | + # Install CasADi dependencies + sudo apt-get update -y + sudo apt-get upgrade -y + # From https://github.com/casadi/casadi/wiki/InstallationLinux + sudo apt-get install -y build-essential gcc g++ gfortran git cmake liblapack-dev pkg-config coinor-libipopt-dev liboctave-dev --install-recommends + # From https://github.com/swig/swig/wiki/Getting-Started + sudo apt-get install -y libpcre3-dev autoconf automake libtool bison --install-recommends + + # From https://github.com/casadi/casadi/wiki/matlab + - name: Install SWIG for that supports MATLAB required by CasADi + run: | + sudo apt-get remove swig swig3.0 + cd .. + git clone https://github.com/jaeandersson/swig + cd swig + git checkout matlab-customdoc + sh autogen.sh + ./configure --with-matlab + make + sudo make install + + - name: Verify which SWIG and gcc is found + run: | + which swig + swig --help + which gcc + gcc --version + + + - name: Configure and compile CasADi + run: | + # Remove autogenerate files to ensure that removed files are actually removed + # ignore return status if the directory does not exist + git rm -r autogenerated || true + # Clone casadi from a given tag + git clone https://github.com/dic-iit/casadi.git + cd casadi + git checkout 3.5.5.3 + # Compile casadi and generate MATLAB bindings + mkdir build + cd build + cmake -DWITH_IPOPT:BOOL=ON -DWITH_OCTAVE:BOOL=ON -DWITH_EXAMPLES:BOOL=OFF -DINCLUDE_PREFIX:PATH=include -DCMAKE_INSTALL_PREFIX=./install -DCMAKE_PREFIX:PATH=lib/cmake/casadi -DLIB_PREFIX:PATH=lib -DBIN_PREFIX:PATH=bin .. + make install + # Copy the MATLAB files from the install directory + cd ${GITHUB_WORKSPACE} + mkdir -p autogenerated/matlab + cp ./casadi/build/install/matlab/*.m ./autogenerated/matlab + mkdir -p autogenerated/matlab/+casadi + cp ./casadi/build/install/matlab/+casadi/*.m ./autogenerated/matlab/+casadi + mkdir -p autogenerated/matlab/octave-extra/ + cp ./casadi/build/install/matlab/octave-extra/*.m ./autogenerated/matlab/octave-extra + # Copy the mex C++ file from the build directory + mkdir -p autogenerated/cxx + cp ./casadi/build/swig/*.cxx ./autogenerated/cxx + cp ./casadi/build/swig/*.h ./autogenerated/cxx + # Remove casadi directory + rm -rf casadi + + - name: Check local changes due to bindings generation + run: | + git status + + - name: Create Pull Request + id: cpr + uses: peter-evans/create-pull-request@v3 + with: + commit-message: 'update matlab bindings' + committer: GitHub + branch: regenerate-matlab-bindings + delete-branch: true + title: 'update matlab bindings' + body: | + This is a PR that regenerated the MATLAB/Octave CasADi bindings. + + For more info, check the documentation of this repo. + + - name: Check outputs + run: | + echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" + echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"