diff --git a/.github/workflows/test-matlab.yml b/.github/workflows/test-matlab.yml new file mode 100644 index 000000000..49efb0ec4 --- /dev/null +++ b/.github/workflows/test-matlab.yml @@ -0,0 +1,69 @@ +name: 'Test MATLAB-based tutorials' + +on: + schedule: + - cron: "0 3 * * WED" + timezone: "Europe/Berlin" + workflow_dispatch: + push: + paths: + - '**/*matlab/**' + +jobs: + test-matlab: + name: Test MATLAB-based tutorials + runs-on: ubuntu-latest + container: + image: precice/precice:nightly + strategy: + fail-fast: true + steps: + - name: Checkout the tutorials repository + uses: actions/checkout@v7 + - name: Install Dependencies + run: | + apt-get -qq update + apt-get -qq install wget + rm -rf /var/lib/apt/lists/* + - name: Set up MATLAB + uses: matlab-actions/setup-matlab@v3 + with: + release: R2024a + - name: Get the matlab-bindings repository + run: | + git clone --depth=1 https://github.com/precice/matlab-bindings.git + cd matlab-bindings && git status + - name: Run compilation script + uses: matlab-actions/run-command@v3 + with: + command: "addpath('matlab-bindings'), compile_matlab_bindings_for_precice" + - name: Get run-matlab-command + run: | + wget -O /usr/local/bin/run-matlab-command https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2/glnxa64/run-matlab-command + chmod +x /usr/local/bin/run-matlab-command + - name: Run resonant-circuit + working-directory: resonant-circuit + env: + LD_PRELOAD: /usr/lib/x86_64-linux-gnu/libstdc++.so.6:/usr/lib/x86_64-linux-gnu/libgfortran.so.5 + run: | + sed -i 's%% %g' precice-config.xml && + cd coil-matlab/ && run-matlab-command "addpath('../../matlab-bindings'), coil" & + cd capacitor-matlab/ && run-matlab-command "addpath('../../matlab-bindings'), capacitor" + - name: Archive logs + if: ${{ always() }} + uses: actions/upload-artifact@v7 + with: + name: test-matlab-logs + path: | + resonant-circuit/*.log + resonant-circuit/*/*.log + resonant-circuit/capacitor-matlab/Curves.png + if-no-files-found: warn + - name: Archive exports + if: ${{ always() }} + uses: actions/upload-artifact@v7 + with: + name: test-matlab-exports + path: | + resonant-circuit/precice-exports/* + if-no-files-found: warn \ No newline at end of file diff --git a/changelog-entries/942.md b/changelog-entries/942.md new file mode 100644 index 000000000..6af7c23d8 --- /dev/null +++ b/changelog-entries/942.md @@ -0,0 +1 @@ +- Added a CI workflow to test MATLAB-based tutorials [#942](https://github.com/precice/tutorials/pull/942) \ No newline at end of file diff --git a/resonant-circuit/capacitor-matlab/capacitor.m b/resonant-circuit/capacitor-matlab/capacitor.m index e56f93bf3..e513b8545 100644 --- a/resonant-circuit/capacitor-matlab/capacitor.m +++ b/resonant-circuit/capacitor-matlab/capacitor.m @@ -104,3 +104,10 @@ save('outputs.mat', 'I', 'U') saveas(gcf, 'Curves.png') + +% Error thresholds based on a reference run +if error_I > 0.47 || error_U > 0.12 + error("Voltage or current differs more than expected from the analytical solution."); + quit(1) +end + diff --git a/resonant-circuit/capacitor-matlab/run.sh b/resonant-circuit/capacitor-matlab/run.sh index 906b25220..c69894470 100755 --- a/resonant-circuit/capacitor-matlab/run.sh +++ b/resonant-circuit/capacitor-matlab/run.sh @@ -1,4 +1,10 @@ #!/usr/bin/env bash +set -e -u + +. ../../tools/log.sh +exec > >(tee --append "$LOGFILE") 2>&1 # Run MATLAB code without GUI matlab -nodisplay -r "capacitor;exit;" + +close_log \ No newline at end of file diff --git a/resonant-circuit/coil-matlab/run.sh b/resonant-circuit/coil-matlab/run.sh index 085ae73f2..c189e82ee 100755 --- a/resonant-circuit/coil-matlab/run.sh +++ b/resonant-circuit/coil-matlab/run.sh @@ -1,4 +1,10 @@ #!/usr/bin/env bash +set -e -u + +. ../../tools/log.sh +exec > >(tee --append "$LOGFILE") 2>&1 # Run MATLAB code without GUI matlab -nodisplay -r "coil;exit;" + +close_log \ No newline at end of file