Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metadata improvemens #16

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.env
.vscode
.idea
.run
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <h1>${{ github.event.release.tag_name }}</h1> # 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
Expand Down Expand Up @@ -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
```

4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 17 additions & 7 deletions scripts/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"]
Expand All @@ -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"
Expand All @@ -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)
Expand All @@ -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"
Expand Down Expand Up @@ -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 :)
Expand Down