Skip to content

Commit

Permalink
Add task in release workflow for updating codemeta
Browse files Browse the repository at this point in the history
  • Loading branch information
ehennestad committed Oct 30, 2024
1 parent 3e44d14 commit 9f35980
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ jobs:
name: openMINDS_MATLAB_${{ env.versionNumber }}.mltbx
path: releases/openMINDS_MATLAB_${{ env.versionNumber }}.mltbx

- name: Update codemeta.json
uses: matlab-actions/run-command@v2
with:
command: |
addpath(genpath("tools"));
updateCodeMetaFile("${{ github.ref_name }}")
# Commit the updated Contents.m
- name: Commit updated Contents.m file
continue-on-error: true
Expand All @@ -123,6 +130,7 @@ jobs:
git config user.email "<>"
git status
git add code/Contents.m
git add codemeta.json
git commit -m "Final checkins for release ${{ github.ref_name }}"
git fetch
git push
Expand Down
38 changes: 38 additions & 0 deletions tools/tasks/updateCodeMetaFile.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
function codeMetaInfo = updateCodeMetaFile(versionString)

arguments
versionString (1,1) string {mustBeTextScalar, mustBeValidVersionString}
end

if startsWith(versionString, "v")
versionStringNumeric = extractAfter(versionString, 1);
else
error('Expected versionString to start with "v"')
end

projectRootDirectory = ommtools.projectdir();

codeMetaFilePath = fullfile(projectRootDirectory, 'codemeta.json');
codeMetaInfo = jsondecode( fileread(codeMetaFilePath) );

codeMetaInfo.version = versionStringNumeric;
codeMetaInfo.downloadUrl = sprintf("https://github.com/openMetadataInitiative/openMINDS_MATLAB/releases/download/%s/openMINDS_MATLAB_%s.mltbx", ...
versionString, strrep(versionString, '.', '_'));
codeMetaInfo.dateModified = string(datetime('today', 'Format', 'yyyy-MM-dd'));

jsonStr = jsonencode(codeMetaInfo, 'PrettyPrint', true);

% Fix json-ld @props
jsonStr = strrep(jsonStr, 'x_context', '@context');
jsonStr = strrep(jsonStr, 'x_type', '@type');
jsonStr = strrep(jsonStr, 'x_id', '@id');

fid = fopen(codeMetaFilePath, 'wt');
fwrite(fid, jsonStr);
fclose(fid);
end

function mustBeValidVersionString(versionString)
pattern = 'v\d+\.\d+\.\d+';
assert( ~ismissing( regexp(versionString, pattern, 'match', 'once')), 'Invalid version string. Must be formatted as v<major>.<minor>.<patch>' )
end

0 comments on commit 9f35980

Please sign in to comment.