From d53ed18f10a689f59af9e25e3848f86f61252257 Mon Sep 17 00:00:00 2001 From: Mathew Topper Date: Wed, 18 Sep 2024 16:53:53 +0100 Subject: [PATCH 1/7] Find the envelope of MATLAB products for all tests and try to cache installation --- .github/workflows/all-tests-reusable.yml | 3 +++ .github/workflows/changed-tests.yml | 3 +++ .github/workflows/run-tests-reusable.yml | 6 +++++- getTestTargets.m | 16 +++++++++++----- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.github/workflows/all-tests-reusable.yml b/.github/workflows/all-tests-reusable.yml index 0c61edb3..c4f576eb 100644 --- a/.github/workflows/all-tests-reusable.yml +++ b/.github/workflows/all-tests-reusable.yml @@ -16,6 +16,7 @@ jobs: folder: ${{ steps.output.outputs.folder }} head_ref: ${{ fromJSON(inputs.client_payload).branch }} include: ${{ steps.output.outputs.include }} + products: ${{ steps.output.outputs.products }} repository: ${{ github.repository }} steps: - run: echo "Triggered by WEC-Sim commit ${{ fromJSON(inputs.client_payload).sha }}" @@ -37,6 +38,7 @@ jobs: run: | echo "folder=$(cat folder.json | jq -cr)" >> $GITHUB_OUTPUT echo "include=$(cat include.json | jq -cr)" >> $GITHUB_OUTPUT + echo "products=$(cat products.json | jq -cr)" >> $GITHUB_OUTPUT run_tests: name: Run tests needs: targets @@ -46,4 +48,5 @@ jobs: folder: ${{ needs.targets.outputs.folder }} head_ref: ${{ needs.targets.outputs.head_ref }} include: ${{ needs.targets.outputs.include }} + products: ${{ needs.targets.outputs.products }} repository: ${{ needs.targets.outputs.repository }} diff --git a/.github/workflows/changed-tests.yml b/.github/workflows/changed-tests.yml index 90826591..33e12323 100644 --- a/.github/workflows/changed-tests.yml +++ b/.github/workflows/changed-tests.yml @@ -20,6 +20,7 @@ jobs: head_ref: ${{ github.head_ref || github.ref_name }} folder: ${{ steps.output.outputs.folder }} include: ${{ steps.output.outputs.include }} + products: ${{ steps.output.outputs.products }} repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }} if: github.event_name != 'repository_dispatch' steps: @@ -47,6 +48,7 @@ jobs: run: | echo "folder=$(cat folder.json | jq -cr)" >> $GITHUB_OUTPUT echo "include=$(cat include.json | jq -cr)" >> $GITHUB_OUTPUT + echo "products=$(cat products.json | jq -cr)" >> $GITHUB_OUTPUT run_tests: name: Run tests needs: targets @@ -56,5 +58,6 @@ jobs: head_ref: ${{ needs.targets.outputs.head_ref }} folder: ${{ needs.targets.outputs.folder }} include: ${{ needs.targets.outputs.include }} + products: ${{ needs.targets.outputs.products }} repository: ${{ needs.targets.outputs.repository }} if: ${{ needs.targets.outputs.folder != '[]'}} diff --git a/.github/workflows/run-tests-reusable.yml b/.github/workflows/run-tests-reusable.yml index 017a1911..df2a2c71 100644 --- a/.github/workflows/run-tests-reusable.yml +++ b/.github/workflows/run-tests-reusable.yml @@ -15,6 +15,9 @@ on: include: required: true type: string + products: + required: true + type: string repository: required: true type: string @@ -65,8 +68,9 @@ jobs: - name: Install MATLAB uses: matlab-actions/setup-matlab@v2 with: - products: ${{ matrix.products }} + products: ${{ fromJSON(inputs.products) }} release: ${{ matrix.release }} + cache: true - name: Start display server (Desalination on Linux) if: matrix.folder == 'Desalination' && matrix.os == 'ubuntu-latest' run: | diff --git a/getTestTargets.m b/getTestTargets.m index 0fe27d00..b204725f 100644 --- a/getTestTargets.m +++ b/getTestTargets.m @@ -21,7 +21,12 @@ function getTestTargets(diffFile) fclose(fid); products = getProducts(targets); - include_struct = struct('folder', targets, 'products', products); + filename = 'products.json'; + fid = fopen(filename, 'w'); + fprintf(fid, '%s', jsonencode(products)); + fclose(fid); + + include_struct = struct('folder', targets); include = num2cell(include_struct); filename = 'include.json'; @@ -31,13 +36,13 @@ function getTestTargets(diffFile) end -function products = getProducts(targets) - arguments +function product = getProducts(targets) + arguments (Input) targets (1,:) cell end arguments (Output) - products (1, :) cell + product (1, :) string end function products = loadProductFiles(product_file, file_exists) @@ -49,7 +54,7 @@ function getTestTargets(diffFile) fileID = fopen(product_file); C = textscan(fileID,'%s'); fclose(fileID); - products = strjoin(C{:, 1}); + products = convertCharsToStrings(C{:, 1}).'; end @@ -58,6 +63,7 @@ function getTestTargets(diffFile) product_files, ... isfile(product_files), ... 'UniformOutput', 0); + product = unique(horzcat(products{:})); end From 46370e35a66647641e7159c173a6a6f4d5142a5d Mon Sep 17 00:00:00 2001 From: Mathew Topper Date: Wed, 18 Sep 2024 17:01:16 +0100 Subject: [PATCH 2/7] Always use all apps for calculating envelope Also add a basic change to trigger a test --- Cable/README.md | 12 ++++++------ getTestTargets.m | 26 ++++++++++++++------------ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Cable/README.md b/Cable/README.md index 10cd2500..80236b52 100644 --- a/Cable/README.md +++ b/Cable/README.md @@ -1,13 +1,13 @@ # Cable -**Author:** Dominic Forbush +**Author:** Dominic Forbush -**Version:** WEC-Sim v4.4 +**Version:** WEC-Sim v4.4 -**Geometry:** MBARI-WEC, and open-source WEC from Monterey Bay Aquarium Research Institute. +**Geometry:** MBARI-WEC, and open-source WEC from Monterey Bay Aquarium Research Institute. -**Dependency:** N/A +**Dependency:** N/A -**Note:** More WEC information can be found: https://link.springer.com/article/10.1007/s40722-021-00197-9 +**Note:** More WEC information can be found: https://link.springer.com/article/10.1007/s40722-021-00197-9 -Example using WEC-Sim to simulate a [Cable](http://wec-sim.github.io/WEC-Sim/advanced_features.html) connecting two rigid bodies for the MBARI geometry. +Example using WEC-Sim to simulate a [Cable](http://wec-sim.github.io/WEC-Sim/advanced_features.html) connecting two rigid bodies for the MBARI geometry. diff --git a/getTestTargets.m b/getTestTargets.m index b204725f..e382985a 100644 --- a/getTestTargets.m +++ b/getTestTargets.m @@ -9,29 +9,31 @@ function getTestTargets(diffFile) % file 'include.json'. A JSON formatted diff file can be passed as an % argument, otherwise all valid test directories are returned. + all_targets = getAllTargets(); + if (diffFile ~= "") targets = getDiffTargets(diffFile); else - targets = getAllTargets(); + targets = all_targets; end - filename = 'folder.json'; - fid = fopen(filename, 'w'); - fprintf(fid, '%s', jsonencode(targets)); + filename = 'folder.json'; + fid = fopen(filename, 'w'); + fprintf(fid, '%s', jsonencode(targets)); fclose(fid); - products = getProducts(targets); - filename = 'products.json'; - fid = fopen(filename, 'w'); - fprintf(fid, '%s', jsonencode(products)); + products = getProducts(all_targets); + filename = 'products.json'; + fid = fopen(filename, 'w'); + fprintf(fid, '%s', jsonencode(products)); fclose(fid); - + include_struct = struct('folder', targets); include = num2cell(include_struct); - filename = 'include.json'; - fid = fopen(filename, 'w'); - fprintf(fid, '%s', jsonencode(include)); + filename = 'include.json'; + fid = fopen(filename, 'w'); + fprintf(fid, '%s', jsonencode(include)); fclose(fid); end From f9e06890098dff4de482bfd8a2a02e82e901ff1e Mon Sep 17 00:00:00 2001 From: Mathew Topper Date: Wed, 18 Sep 2024 17:08:35 +0100 Subject: [PATCH 3/7] products needs to be a basic string not array --- .github/workflows/all-tests-reusable.yml | 2 +- .github/workflows/changed-tests.yml | 2 +- .github/workflows/run-tests-reusable.yml | 2 +- getTestTargets.m | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/all-tests-reusable.yml b/.github/workflows/all-tests-reusable.yml index c4f576eb..dd57b91d 100644 --- a/.github/workflows/all-tests-reusable.yml +++ b/.github/workflows/all-tests-reusable.yml @@ -38,7 +38,7 @@ jobs: run: | echo "folder=$(cat folder.json | jq -cr)" >> $GITHUB_OUTPUT echo "include=$(cat include.json | jq -cr)" >> $GITHUB_OUTPUT - echo "products=$(cat products.json | jq -cr)" >> $GITHUB_OUTPUT + echo "products=$(cat products.txt)" >> $GITHUB_OUTPUT run_tests: name: Run tests needs: targets diff --git a/.github/workflows/changed-tests.yml b/.github/workflows/changed-tests.yml index 33e12323..5a857335 100644 --- a/.github/workflows/changed-tests.yml +++ b/.github/workflows/changed-tests.yml @@ -48,7 +48,7 @@ jobs: run: | echo "folder=$(cat folder.json | jq -cr)" >> $GITHUB_OUTPUT echo "include=$(cat include.json | jq -cr)" >> $GITHUB_OUTPUT - echo "products=$(cat products.json | jq -cr)" >> $GITHUB_OUTPUT + echo "products=$(cat products.txt)" >> $GITHUB_OUTPUT run_tests: name: Run tests needs: targets diff --git a/.github/workflows/run-tests-reusable.yml b/.github/workflows/run-tests-reusable.yml index df2a2c71..f9ab326f 100644 --- a/.github/workflows/run-tests-reusable.yml +++ b/.github/workflows/run-tests-reusable.yml @@ -68,7 +68,7 @@ jobs: - name: Install MATLAB uses: matlab-actions/setup-matlab@v2 with: - products: ${{ fromJSON(inputs.products) }} + products: ${{ inputs.products }} release: ${{ matrix.release }} cache: true - name: Start display server (Desalination on Linux) diff --git a/getTestTargets.m b/getTestTargets.m index e382985a..3c9ff07a 100644 --- a/getTestTargets.m +++ b/getTestTargets.m @@ -23,9 +23,9 @@ function getTestTargets(diffFile) fclose(fid); products = getProducts(all_targets); - filename = 'products.json'; + filename = 'products.txt'; fid = fopen(filename, 'w'); - fprintf(fid, '%s', jsonencode(products)); + fprintf(fid, '%s', strjoin(products)); fclose(fid); include_struct = struct('folder', targets); From 322faad7a85aa309e6ac1317de18161cd24a391a Mon Sep 17 00:00:00 2001 From: Mathew Topper Date: Wed, 18 Sep 2024 18:03:40 +0100 Subject: [PATCH 4/7] Cache the target finding step MATLAB also --- .github/workflows/all-tests-reusable.yml | 1 + .github/workflows/changed-tests.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/all-tests-reusable.yml b/.github/workflows/all-tests-reusable.yml index dd57b91d..f0b5bc93 100644 --- a/.github/workflows/all-tests-reusable.yml +++ b/.github/workflows/all-tests-reusable.yml @@ -29,6 +29,7 @@ jobs: uses: matlab-actions/setup-matlab@v2 with: release: R2024a + cache: true - name: Get test target folder uses: matlab-actions/run-command@v2 with: diff --git a/.github/workflows/changed-tests.yml b/.github/workflows/changed-tests.yml index 5a857335..a4eb9bb8 100644 --- a/.github/workflows/changed-tests.yml +++ b/.github/workflows/changed-tests.yml @@ -39,6 +39,7 @@ jobs: uses: matlab-actions/setup-matlab@v2 with: release: R2024a + cache: true - name: Get test target folder uses: matlab-actions/run-command@v2 with: From 8ba95dcd03ca13a2063a54d524d857fda85bb5ec Mon Sep 17 00:00:00 2001 From: Mathew Topper Date: Thu, 19 Sep 2024 11:30:53 +0100 Subject: [PATCH 5/7] Trigger a build to get time with cache for folders step --- Cable/TestCable.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Cable/TestCable.m b/Cable/TestCable.m index 13c2704f..1843b232 100644 --- a/Cable/TestCable.m +++ b/Cable/TestCable.m @@ -8,7 +8,6 @@ outName = 'mbari.out' end - methods (Access = 'public') function obj = TestCable obj.testDir = fileparts(mfilename('fullpath')); @@ -44,7 +43,7 @@ function runBemio(testCase) function checkVisibilityRestored(testCase) set(0, 'DefaultFigureVisible', testCase.OriginalDefault); testCase.assertEqual(get(0, 'DefaultFigureVisible'), ... - testCase.OriginalDefault); + testCase.OriginalDefault); end end From 24046ec166bd7859277d1bf9b8f4f0b1a3b4467b Mon Sep 17 00:00:00 2001 From: Mathew Topper Date: Thu, 14 Nov 2024 09:25:30 +0000 Subject: [PATCH 6/7] Move timeout into test step --- .github/workflows/run-tests-reusable.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests-reusable.yml b/.github/workflows/run-tests-reusable.yml index f9ab326f..079e63cc 100644 --- a/.github/workflows/run-tests-reusable.yml +++ b/.github/workflows/run-tests-reusable.yml @@ -36,7 +36,6 @@ jobs: - os: ubuntu-latest folder: Mooring name: "${{ matrix.folder }} - ${{ matrix.os }} - ${{ matrix.release }}" - timeout-minutes: 45 steps: - name: Check out repository uses: actions/checkout@v4 @@ -79,6 +78,7 @@ jobs: echo "DISPLAY=:99" >> $GITHUB_ENV - name: Install WEC-Sim, run tests and generate artifacts uses: matlab-actions/run-command@v2 + timeout-minutes: 45 with: command: | addpath(genpath('WEC-Sim/source')); From a9ce564ee381d904dc9f89bf268ccf5f064381d1 Mon Sep 17 00:00:00 2001 From: Mathew Topper Date: Thu, 14 Nov 2024 09:50:30 +0000 Subject: [PATCH 7/7] Use a test that actually works --- Cable/README.md | 12 ++++++------ Cable/TestCable.m | 3 ++- Controls/TestControls.m | 28 ++++++++++++++-------------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/Cable/README.md b/Cable/README.md index 80236b52..10cd2500 100644 --- a/Cable/README.md +++ b/Cable/README.md @@ -1,13 +1,13 @@ # Cable -**Author:** Dominic Forbush +**Author:** Dominic Forbush -**Version:** WEC-Sim v4.4 +**Version:** WEC-Sim v4.4 -**Geometry:** MBARI-WEC, and open-source WEC from Monterey Bay Aquarium Research Institute. +**Geometry:** MBARI-WEC, and open-source WEC from Monterey Bay Aquarium Research Institute. -**Dependency:** N/A +**Dependency:** N/A -**Note:** More WEC information can be found: https://link.springer.com/article/10.1007/s40722-021-00197-9 +**Note:** More WEC information can be found: https://link.springer.com/article/10.1007/s40722-021-00197-9 -Example using WEC-Sim to simulate a [Cable](http://wec-sim.github.io/WEC-Sim/advanced_features.html) connecting two rigid bodies for the MBARI geometry. +Example using WEC-Sim to simulate a [Cable](http://wec-sim.github.io/WEC-Sim/advanced_features.html) connecting two rigid bodies for the MBARI geometry. diff --git a/Cable/TestCable.m b/Cable/TestCable.m index 1843b232..13c2704f 100644 --- a/Cable/TestCable.m +++ b/Cable/TestCable.m @@ -8,6 +8,7 @@ outName = 'mbari.out' end + methods (Access = 'public') function obj = TestCable obj.testDir = fileparts(mfilename('fullpath')); @@ -43,7 +44,7 @@ function runBemio(testCase) function checkVisibilityRestored(testCase) set(0, 'DefaultFigureVisible', testCase.OriginalDefault); testCase.assertEqual(get(0, 'DefaultFigureVisible'), ... - testCase.OriginalDefault); + testCase.OriginalDefault); end end diff --git a/Controls/TestControls.m b/Controls/TestControls.m index 821c7071..b7e6ebc1 100644 --- a/Controls/TestControls.m +++ b/Controls/TestControls.m @@ -6,12 +6,12 @@ h5Dir = '../_Common_Input_Files/Sphere/hydroData/' h5Name = 'sphere.h5' outName = 'sphere.out' - end + end - methods (Access = 'public') + methods (Access = 'public') function obj = TestControls obj.testDir = fileparts(mfilename('fullpath')); - end + end end methods (TestMethodSetup) @@ -32,7 +32,7 @@ function runBemio(testCase) bemio end cd(testCase.testDir) - end + end end methods(TestMethodTeardown) @@ -41,38 +41,38 @@ function returnHome(testCase) end end - methods(TestClassTeardown) + methods(TestClassTeardown) function checkVisibilityRestored(testCase) set(0,'DefaultFigureVisible',testCase.OriginalDefault); testCase.assertEqual(get(0,'DefaultFigureVisible'), ... testCase.OriginalDefault); - end + end end - methods(Test) + methods(Test) function testPassive(testCase) cd('Passive (P)') wecSim - end + end function testReactive(testCase) cd('Reactive (PI)') wecSim - end + end function testLatching(testCase) cd('Latching') wecSim - end + end function testDeclutching(testCase) cd('Declutching') wecSim - end + end function testMPC(testCase) cd('MPC') wecSim - end + end function testReactiveWithPTO(testCase) cd('ReactiveWithPTO') wecSim - end - end + end + end end