Skip to content

Commit 59b48fd

Browse files
authored
metadata improvemens (#16)
* add title and description support + do not override related_identifiers if some exists * fix invalid format args
1 parent 01fb60a commit 59b48fd

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
.env
2+
.vscode
3+
.idea
4+
.run

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ jobs:
9595
zenodo_json: .zenodo.json # optional
9696
html_url: ${{ github.event.release.html_url }} # optional to include link to the GitHub release
9797
archive: ${{ env.archive }}
98+
title: ${{ github.repository }}:${{ github.event.release.tag_name }} # optional title to override
99+
description: <h1>${{ github.event.release.tag_name }}</h1> # optional release description (allows HTML)
98100

99101
# Optional DOI for all versions. Leaving this blank (the default) will create
100102
# a new DOI on every release. Use a DOI that represents all versions will
@@ -207,4 +209,3 @@ export ZENODO_TOKEN=xxxxxxxxxxxxxxxxxxxx
207209
# archive # multi-version DOI # new version
208210
$ python scripts/deploy.py upload 0.0.0.tar.gz --doi 10.5281/zenodo.6326822 --version 0.0.0
209211
```
210-

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ inputs:
1616
description: Path to zenodo.json to upload with metadata (must exist)
1717
doi:
1818
descripton: The DOI to create a new version from
19+
title:
20+
description: zenodo title (optional)
21+
description:
22+
description: zenodo description (optional)
1923

2024
outputs:
2125
badge:

scripts/deploy.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def publish(self, data):
208208
for k, v in published["links"].items():
209209
set_env_and_output(k, v)
210210

211-
def upload_metadata(self, upload, zenodo_json, version, html_url=None):
211+
def upload_metadata(self, upload, zenodo_json, version, html_url=None, title=None, description=None):
212212
"""
213213
Given an upload response and zenodo json, upload new data
214214
@@ -229,14 +229,21 @@ def upload_metadata(self, upload, zenodo_json, version, html_url=None):
229229

230230
# Update the related info to use the url to the current release
231231
if html_url:
232-
metadata["related_identifiers"] = [
232+
metadata.setdefault("related_identifiers", [])
233+
metadata["related_identifiers"].append(
233234
{
234235
"identifier": html_url,
235236
"relation": "isSupplementTo",
236237
"resource_type": "software",
237238
"scheme": "url",
238239
}
239-
]
240+
)
241+
242+
if title is not None:
243+
metadata["title"] = title
244+
245+
if description is not None:
246+
metadata["description"] = description
240247

241248
# Make the deposit!
242249
url = "https://zenodo.org/api/deposit/depositions/%s" % upload["id"]
@@ -248,14 +255,13 @@ def upload_metadata(self, upload, zenodo_json, version, html_url=None):
248255
)
249256
if response.status_code != 200:
250257
sys.exit(
251-
"Trouble uploading metadata %s, %s" % response.status_code,
252-
response.json(),
258+
"Trouble uploading metadata %s, %s" % (response.status_code, response.json())
253259
)
254260
return response.json()
255261

256262

257263
def upload_archive(
258-
archive, version, html_url=None, zenodo_json=None, doi=None, sandbox=False
264+
archive, version, html_url=None, zenodo_json=None, doi=None, sandbox=False, title=None, description=None,
259265
):
260266
"""
261267
Upload an archive to an existing Zenodo "versions DOI"
@@ -278,7 +284,7 @@ def upload_archive(
278284
cli.upload_archive(upload, path)
279285

280286
# Finally, load .zenodo.json and add version
281-
data = cli.upload_metadata(upload, zenodo_json, version, html_url)
287+
data = cli.upload_metadata(upload, zenodo_json, version, html_url, title=title, description=description)
282288

283289
# Finally, publish
284290
cli.publish(data)
@@ -300,6 +306,8 @@ def get_parser():
300306
help="path to .zenodo.json (defaults to .zenodo.json)",
301307
)
302308
upload.add_argument("--version", help="version to upload")
309+
upload.add_argument("--title", help="Title to override in upload")
310+
upload.add_argument("--description", help="Description to override in upload (allows HTML)")
303311
upload.add_argument("--doi", help="an existing DOI to add a new version to")
304312
upload.add_argument(
305313
"--html-url", dest="html_url", help="url to use for the release"
@@ -333,6 +341,8 @@ def help(return_code=0):
333341
version=args.version,
334342
doi=args.doi,
335343
html_url=args.html_url,
344+
title=args.title,
345+
description=args.description,
336346
)
337347

338348
# We should not get here :)

0 commit comments

Comments
 (0)