From 59b48fdca8fee5882fef2e4dd66ed132768df1c6 Mon Sep 17 00:00:00 2001 From: Francis Charette-Migneault Date: Tue, 3 Dec 2024 20:53:28 -0500 Subject: [PATCH] metadata improvemens (#16) * add title and description support + do not override related_identifiers if some exists * fix invalid format args --- .gitignore | 3 +++ README.md | 3 ++- action.yml | 4 ++++ scripts/deploy.py | 24 +++++++++++++++++------- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 4c49bd7..0e4ddee 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ .env +.vscode +.idea +.run diff --git a/README.md b/README.md index 44dab32..98c5760 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,8 @@ jobs: zenodo_json: .zenodo.json # optional html_url: ${{ github.event.release.html_url }} # optional to include link to the GitHub release archive: ${{ env.archive }} + title: ${{ github.repository }}:${{ github.event.release.tag_name }} # optional title to override + description:

${{ github.event.release.tag_name }}

# optional release description (allows HTML) # Optional DOI for all versions. Leaving this blank (the default) will create # a new DOI on every release. Use a DOI that represents all versions will @@ -207,4 +209,3 @@ export ZENODO_TOKEN=xxxxxxxxxxxxxxxxxxxx # archive # multi-version DOI # new version $ python scripts/deploy.py upload 0.0.0.tar.gz --doi 10.5281/zenodo.6326822 --version 0.0.0 ``` - diff --git a/action.yml b/action.yml index 67ff84f..cf4587c 100644 --- a/action.yml +++ b/action.yml @@ -16,6 +16,10 @@ inputs: description: Path to zenodo.json to upload with metadata (must exist) doi: descripton: The DOI to create a new version from + title: + description: zenodo title (optional) + description: + description: zenodo description (optional) outputs: badge: diff --git a/scripts/deploy.py b/scripts/deploy.py index ce80295..9cd23bc 100644 --- a/scripts/deploy.py +++ b/scripts/deploy.py @@ -208,7 +208,7 @@ def publish(self, data): for k, v in published["links"].items(): set_env_and_output(k, v) - def upload_metadata(self, upload, zenodo_json, version, html_url=None): + def upload_metadata(self, upload, zenodo_json, version, html_url=None, title=None, description=None): """ Given an upload response and zenodo json, upload new data @@ -229,14 +229,21 @@ def upload_metadata(self, upload, zenodo_json, version, html_url=None): # Update the related info to use the url to the current release if html_url: - metadata["related_identifiers"] = [ + metadata.setdefault("related_identifiers", []) + metadata["related_identifiers"].append( { "identifier": html_url, "relation": "isSupplementTo", "resource_type": "software", "scheme": "url", } - ] + ) + + if title is not None: + metadata["title"] = title + + if description is not None: + metadata["description"] = description # Make the deposit! 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): ) if response.status_code != 200: sys.exit( - "Trouble uploading metadata %s, %s" % response.status_code, - response.json(), + "Trouble uploading metadata %s, %s" % (response.status_code, response.json()) ) return response.json() def upload_archive( - archive, version, html_url=None, zenodo_json=None, doi=None, sandbox=False + archive, version, html_url=None, zenodo_json=None, doi=None, sandbox=False, title=None, description=None, ): """ Upload an archive to an existing Zenodo "versions DOI" @@ -278,7 +284,7 @@ def upload_archive( cli.upload_archive(upload, path) # Finally, load .zenodo.json and add version - data = cli.upload_metadata(upload, zenodo_json, version, html_url) + data = cli.upload_metadata(upload, zenodo_json, version, html_url, title=title, description=description) # Finally, publish cli.publish(data) @@ -300,6 +306,8 @@ def get_parser(): help="path to .zenodo.json (defaults to .zenodo.json)", ) upload.add_argument("--version", help="version to upload") + upload.add_argument("--title", help="Title to override in upload") + upload.add_argument("--description", help="Description to override in upload (allows HTML)") upload.add_argument("--doi", help="an existing DOI to add a new version to") upload.add_argument( "--html-url", dest="html_url", help="url to use for the release" @@ -333,6 +341,8 @@ def help(return_code=0): version=args.version, doi=args.doi, html_url=args.html_url, + title=args.title, + description=args.description, ) # We should not get here :)