diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9731870..bfbe734 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 @@ -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 diff --git a/tools/tasks/updateCodeMetaFile.m b/tools/tasks/updateCodeMetaFile.m new file mode 100644 index 0000000..71229e1 --- /dev/null +++ b/tools/tasks/updateCodeMetaFile.m @@ -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..' ) +end \ No newline at end of file