Skip to content
Merged
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
1 change: 0 additions & 1 deletion .github/badges/code_issues.svg

This file was deleted.

73 changes: 73 additions & 0 deletions .github/workflows/code-analysis-latest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Code analysis (latest MATLAB)

# Runs the same check as code-analysis.yml on the latest MATLAB
# release. code-analysis.yml uses a fixed release so that its result, and
# the README badge, change only when the code changes. A failure here means
# a newer release reports issues that the fixed release does not: resolve
# them, then raise matlab_release in code-analysis.yml.
#
# The analysis is skipped while the latest release is the one pinned in
# code-analysis.yml, because that workflow already covers it.

on:
# Weekly, Monday 04:00 UTC
schedule:
- cron: '0 4 * * 1'
workflow_dispatch:
inputs:
force:
description: Run the analysis even if the latest release is the pinned release
type: boolean
default: false

jobs:
compare-releases:
name: Compare latest and pinned MATLAB release
runs-on: ubuntu-latest
outputs:
latest_release: ${{ steps.compare.outputs.latest_release }}
run_analysis: ${{ steps.compare.outputs.run_analysis }}
steps:
- name: Check out code-analysis.yml
uses: actions/checkout@v6
with:
sparse-checkout: .github/workflows/code-analysis.yml
sparse-checkout-cone-mode: false

# setup-matlab resolves "latest" from the same MathWorks URL, which
# returns a lowercase release name such as r2026b
- name: Compare releases
id: compare
env:
FORCE: ${{ inputs.force || false }}
run: |
latest=$(curl -fsS --retry 3 https://ssd.mathworks.com/supportfiles/ci/matlab-release/v0/latest \
| tr '[:upper:]' '[:lower:]')
pinned=$(grep -oE '^[[:space:]]*matlab_release:[[:space:]]*R[0-9]{4}[ab]' .github/workflows/code-analysis.yml \
| grep -oE 'R[0-9]{4}[ab]' || true)
if [[ -z "$pinned" ]]; then
echo "::error::No matlab_release of the form R2026b found in code-analysis.yml"
exit 1
fi
pinned=$(echo "$pinned" | tr '[:upper:]' '[:lower:]')

if [[ "$latest" != "$pinned" || "$FORCE" == "true" ]]; then
runAnalysis=true
else
runAnalysis=false
fi

echo "latest_release=$latest" >> "$GITHUB_OUTPUT"
echo "run_analysis=$runAnalysis" >> "$GITHUB_OUTPUT"
echo "Latest release: $latest, pinned release: $pinned, run analysis: $runAnalysis" \
| tee -a "$GITHUB_STEP_SUMMARY"

code-analysis:
name: Code analysis (latest MATLAB)
needs: compare-releases
if: needs.compare-releases.outputs.run_analysis == 'true'
uses: ehennestad/matbox-actions/.github/workflows/check-code-workflow.yml@v1
with:
source_directory: "."
matlab_release: ${{ needs.compare-releases.outputs.latest_release }}
update_badges: false
35 changes: 35 additions & 0 deletions .github/workflows/code-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Code analysis

# Runs MATLAB Code Analyzer on every .m file in the repository. The job
# fails when an issue of severity warning or error remains (see
# tools/tasks/codecheckToolbox.m). The README shows this workflow's status
# as the code analysis badge.

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
code-analysis:
name: Code analysis
uses: ehennestad/matbox-actions/.github/workflows/check-code-workflow.yml@v1
with:
# Check the whole repository, including the tools folder
source_directory: "."

# A fixed release, so the result changes only when the code changes.
# The ignoredFiles setting in code/resources/codeAnalyzerConfiguration.json
# needs R2026b or later.
matlab_release: R2026b
matlab_use_cache: true

# The README shows this workflow's status, so no badge file is
# generated or committed
update_badges: false
35 changes: 0 additions & 35 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,6 @@ jobs:
release: ${{ matrix.MATLABVersion }}
cache: true

# Check for MATLAB code issues in the project.
- name: Check for MATLAB code issues
if: matrix.MATLABVersion == env.LatestMATLABVersion
uses: matlab-actions/run-command@v3
with:
command: addpath(genpath("tools")); codecheckToolbox()

# Upload code issues report
- name: Upload SARIF file
if: matrix.MATLABVersion == env.LatestMATLABVersion
uses: github/codeql-action/upload-sarif@v3
with:
# Path to SARIF file relative to the root of the repository
sarif_file: docs/reports/code_issues.sarif

# The interoperability test builds the same collection with the
# Python reference implementation and compares the two exports. A
# pull request runs against a pinned release, so it cannot go red
Expand Down Expand Up @@ -111,26 +96,6 @@ jobs:
addpath(genpath("tools"));
testToolbox()

# Commit the updated code issues badge (if changed).
# Push events only, so badge commits land on main and nowhere else:
# committing them on a pull_request event rewrites the PR head branch
# and breaks any stack built on top of it.
- name: Commit svg badges if updated
if: matrix.MATLABVersion == env.LatestMATLABVersion && github.event_name == 'push'
continue-on-error: true
run: |
git config user.name "${{ github.workflow }} by ${{ github.actor }}"
git config user.email "${{ secrets.COMMIT_EMAIL_ADDRESS }}"
git fetch

if [[ $(git add .github/badges/* --dry-run | wc -l) -gt 0 ]]; then
git add .github/badges/*
git commit -m "Update code issues badge"
git push -f
else
echo "Nothing to commit"
fi

- name: Upload code coverage report to Codecov (https://app.codecov.io/gh/openMetadataInitiative/openMINDS_MATLAB)
if: matrix.MATLABVersion == env.LatestMATLABVersion
uses: codecov/codecov-action@v6
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[![View openMINDS_MATLAB on File Exchange](https://github.com/openMetadataInitiative/openMINDS_MATLAB/blob/gh-badges/.github/badges/matlab-file-exchange.svg)](https://se.mathworks.com/matlabcentral/fileexchange/134212-openminds_matlab)
[![Run tests](https://github.com/openMetadataInitiative/openMINDS_MATLAB/actions/workflows/run_tests.yml/badge.svg)](https://github.com/openMetadataInitiative/openMINDS_MATLAB/actions/workflows/run_tests.yml)
[![codecov](https://codecov.io/gh/openMetadataInitiative/openMINDS_MATLAB/graph/badge.svg?token=FTD5FHZSFA)](https://codecov.io/gh/openMetadataInitiative/openMINDS_MATLAB)
[![MATLAB Code Issues](.github/badges/code_issues.svg)](https://github.com/openMetadataInitiative/openMINDS_MATLAB/security/code-scanning)
[![Code analysis](https://github.com/openMetadataInitiative/openMINDS_MATLAB/actions/workflows/code-analysis.yml/badge.svg)](https://github.com/openMetadataInitiative/openMINDS_MATLAB/actions/workflows/code-analysis.yml)

<p align="center">
<a href="#installation">Installation</a> •
Expand Down
8 changes: 8 additions & 0 deletions code/resources/codeAnalyzerConfiguration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "openMINDS_MATLAB",
"description": "Excludes generated classes where the openMINDS type and one of its properties share a name, which Code Analyzer reports as REDEF.",
"ignoredFiles": [
"generated/resources/v1.0/types/+openminds/+core/+miscellaneous/URL.m",
"generated/resources/v2.0/types/+openminds/+core/+miscellaneous/URL.m"
]
}
32 changes: 29 additions & 3 deletions tools/tasks/codecheckToolbox.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
function issues = codecheckToolbox()
function issues = codecheckToolbox(options)
% codecheckToolbox - Identify code issues for openMINDS_MATLAB toolbox
%
% issues = codecheckToolbox() checks every .m file in the repository and
% throws an error if an issue of severity warning or error remains.
%
% issues = codecheckToolbox(FoldersToCheck=folders) checks only the .m
% files in the given folders, which are relative to the repository root.
% The ehennestad/matbox-actions check-code action passes this argument.
%
% The ignoredFiles setting in code/resources/codeAnalyzerConfiguration.json
% lists files that Code Analyzer skips (MATLAB R2026b or later).

arguments
options.FoldersToCheck (1,:) string = string.empty
end

ommtools.installMatBox("commit")
projectRootDirectory = ommtools.projectdir();


if isempty(options.FoldersToCheck)
foldersToCheck = string.empty;
else
foldersToCheck = fullfile(projectRootDirectory, options.FoldersToCheck);
end

% ShowIssues prints the table of remaining issues, so a failed CI run
% shows which files to fix. The status of the Code analysis workflow is
% the README badge, so no badge file is created.
issues = matbox.tasks.codecheckToolbox(projectRootDirectory, ...
"CreateBadge", true);
FoldersToCheck=foldersToCheck, ...
CreateBadge=false, ...
RequireIssuesResolved=true, ...
ShowIssues=true);
end
4 changes: 2 additions & 2 deletions tools/tests/oneOffs/personArray.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"contactInformation", contacts(person.email) };

if ommtest.oneoffs.currentSchemaMajorVersion() >= 5
personArguments = [personArguments, { ...
"preferredName", join([person.givenName, person.familyName], " ")}];
preferredName = join([person.givenName, person.familyName], " ");
personArguments = [personArguments, {"preferredName", preferredName}]; %#ok<AGROW>
end

persons(end+1) = openminds.core.Person(personArguments{:}); %#ok<AGROW>
Expand Down
Loading