Skip to content

Commit 5162a75

Browse files
committed
feat: add Zenodo DOI also to new metadata file if present
1 parent 2be4f40 commit 5162a75

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

Jenkinsfile

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ pipeline {
332332
}
333333
}
334334
}
335-
stage('Update metadata.json') {
335+
stage('Update metadata files') {
336336
when {
337337
expression {env.MODULES.contains(env.THIS_REPO)}
338338
expression {need_zenodo_retrigger}
@@ -349,22 +349,45 @@ pipeline {
349349
// Create a new branch, using shell, append a random suffix
350350
sh "git checkout -b zenodo-integration-${BUILD_NUMBER}"
351351

352+
// V1 metadata
352353
meta = readJSON file: "metadata.json"
353354

354355
// If Zenodo DOI is not in metadata.json, add it
355356
if (!meta["sources"].containsKey("zenodo_doi")) {
356357
meta["sources"]["zenodo_doi"] = zenodo_doi
357358

359+
if (!meta.containsKey("doi"))
360+
meta["doi"] = zenodo_doi.split("/")[-2] + "/" + zenodo_doi.split("/")[-1]
361+
}
362+
358363
writeJSON file: "metadata.json", json: meta, pretty: 4
359364
}
360365

366+
// V2 metadata
367+
// Check if .ai4-metadata.json exists
368+
if (fileExists(".ai4-metadata.json")) {
369+
meta = readJSON file: ".ai4-metadata.json"
370+
371+
// If Zenodo DOI is not in metadata.json, add it
372+
if (!meta["sources"].containsKey("zenodo_doi")) {
373+
meta["sources"]["zenodo_doi"] = zenodo_doi
374+
375+
if (!meta.containsKey("doi"))
376+
meta["doi"] = zenodo_doi.split("/")[-2] + "/" + zenodo_doi.split("/")[-1]
377+
}
378+
379+
writeJSON file: ".ai4-metadata.json", json: meta, pretty: 4
380+
}
381+
382+
}
383+
361384
// Setup git user
362385
sh "git config --global user.email '[email protected]'"
363386
sh "git config --global user.name 'AI4EOSC Jenkins user'"
364387

365388
// Now commit the changes
366-
sh "git add metadata.json"
367-
sh "git commit -m 'Add Zenodo DOI to metadata.json'"
389+
sh "git add metadata.json .ai4-metadata.json"
390+
sh "git commit -m 'Add Zenodo DOI to metadata file(s)'"
368391

369392
// Push the changes to the repository
370393
withCredentials([
@@ -381,7 +404,7 @@ pipeline {
381404

382405

383406
// Now, crete a PR using GitHub API
384-
pr_body = "This is an automated change.\\n\\nThis pull request includes the Zenodo DOI in the metadata.json file. The obtained Zenodo DOI is ${zenodo_doi}, please verify that this DOI corresponds to your repository, carefully review the changes and, if they are correct, merge the PR."
407+
pr_body = "This is an automated change.\\n\\nThis pull request includes the Zenodo DOI in the metadata file(s). The obtained Zenodo DOI is ${zenodo_doi}, please verify that this DOI corresponds to your repository, carefully review the changes and, if they are correct, merge the PR."
385408
pr_title = "Add Zenodo DOI to metadata.json"
386409
pr_head = "zenodo-integration-${BUILD_NUMBER}"
387410
pr = """{

0 commit comments

Comments
 (0)