Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use MATLAB caching in GitHub Actions #74

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/all-tests-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand All @@ -28,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:
Expand All @@ -37,6 +39,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.txt)" >> $GITHUB_OUTPUT
run_tests:
name: Run tests
needs: targets
Expand All @@ -46,4 +49,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 }}
4 changes: 4 additions & 0 deletions .github/workflows/changed-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -38,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:
Expand All @@ -47,6 +49,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.txt)" >> $GITHUB_OUTPUT
run_tests:
name: Run tests
needs: targets
Expand All @@ -56,5 +59,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 != '[]'}}
8 changes: 6 additions & 2 deletions .github/workflows/run-tests-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ on:
include:
required: true
type: string
products:
required: true
type: string
repository:
required: true
type: string
Expand All @@ -33,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
Expand Down Expand Up @@ -65,8 +67,9 @@ jobs:
- name: Install MATLAB
uses: matlab-actions/setup-matlab@v2
with:
products: ${{ matrix.products }}
products: ${{ inputs.products }}
release: ${{ matrix.release }}
cache: true
- name: Start display server (Desalination on Linux)
if: matrix.folder == 'Desalination' && matrix.os == 'ubuntu-latest'
run: |
Expand All @@ -75,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'));
Expand Down
28 changes: 14 additions & 14 deletions Controls/TestControls.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -32,7 +32,7 @@ function runBemio(testCase)
bemio
end
cd(testCase.testDir)
end
end
end

methods(TestMethodTeardown)
Expand All @@ -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
34 changes: 21 additions & 13 deletions getTestTargets.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,42 @@ 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(all_targets);
filename = 'products.txt';
fid = fopen(filename, 'w');
fprintf(fid, '%s', strjoin(products));
fclose(fid);

products = getProducts(targets);
include_struct = struct('folder', targets, 'products', products);
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

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)
Expand All @@ -49,7 +56,7 @@ function getTestTargets(diffFile)
fileID = fopen(product_file);
C = textscan(fileID,'%s');
fclose(fileID);
products = strjoin(C{:, 1});
products = convertCharsToStrings(C{:, 1}).';

end

Expand All @@ -58,6 +65,7 @@ function getTestTargets(diffFile)
product_files, ...
isfile(product_files), ...
'UniformOutput', 0);
product = unique(horzcat(products{:}));

end

Expand Down