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

add url to the release in the supplementary material #14

Closed
wants to merge 9 commits into from
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on release, and without needing to enable admin webhooks. To get this working yo

[Here is an example](https://doi.org/10.5281/zenodo.6326822) of an "all releases" DOI created by this action, and the metadata associated:

```
```console
doi https://doi.org/10.5281/zenodo.6326823
conceptdoi https://doi.org/10.5281/zenodo.6326822
conceptbadge https://zenodo.org/badge/doi/10.5281/zenodo.6326822.svg
Expand Down Expand Up @@ -93,6 +93,7 @@ jobs:
token: ${{ secrets.ZENODO_TOKEN }}
version: ${{ github.event.release.tag_name }}
zenodo_json: .zenodo.json # optional
html_url: ${{ github.event.release.html_url }} # optional
archive: ${{ env.archive }}

# Optional DOI for all versions. Leaving this blank (the default) will create
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ inputs:
version:
description: the release version
required: true
html_url:
description: The HTML url to appear with the release (optional)
zenodo_json:
description: Path to zenodo.json to upload with metadata (must exist)
doi:
Expand Down Expand Up @@ -54,6 +56,7 @@ runs:
zenodo_json: ${{ inputs.zenodo_json }}
archive: ${{ inputs.archive }}
version: ${{ inputs.version }}
html_url: ${{ inputs.html_url }}
ACTION_PATH: ${{ github.action_path }}
ZENODO_TOKEN: ${{ inputs.token }}
doi: ${{ inputs.doi }}
Expand All @@ -65,6 +68,9 @@ runs:
if [[ "${zenodo_json}" != "" ]]; then
command="$command --zenodo-json ${zenodo_json}"
fi
if [[ "${html_url}" != "" ]]; then
command="$command --html-url ${html_url}"
fi
printf "$command\n"
$command

Expand Down
35 changes: 26 additions & 9 deletions scripts/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@


import argparse
import os
import json
import os
import sys
from glob import glob
from datetime import datetime
from glob import glob

import requests


Expand Down Expand Up @@ -177,7 +178,6 @@ def upload_archive(self, upload, archive):
"""
# Using requests files indicates multipart/form-data
# Here we are uploading the new release file
url = "https://zenodo.org/api/deposit/depositions/%s/files" % upload["id"]
bucket_url = upload["links"]["bucket"]

with open(archive, "rb") as fp:
Expand All @@ -188,8 +188,8 @@ def upload_archive(self, upload, archive):
)
if response.status_code not in [200, 201]:
sys.exit(
"Trouble uploading artifact %s to bucket with response code %s" %
(archive, response.status_code)
"Trouble uploading artifact %s to bucket with response code %s"
% (archive, response.status_code)
)

def publish(self, data):
Expand All @@ -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):
def upload_metadata(self, upload, zenodo_json, version, html_url=None):
"""
Given an upload response and zenodo json, upload new data

Expand All @@ -220,13 +220,24 @@ def upload_metadata(self, upload, zenodo_json, version):
if zenodo_json:
metadata.update(read_json(zenodo_json))
metadata["version"] = version
metadata["publication_date"] = str(datetime.today().strftime('%Y-%m-%d'))
metadata["publication_date"] = str(datetime.today().strftime("%Y-%m-%d"))

# New .zenodo.json may be missing this
if "upload_type" not in metadata:
metadata["upload_type"] = "software"
self.headers.update({"Content-Type": "application/json"})

# Update the related info to use the url to the current release
if html_url:
metadata["related_identifiers"] = [
{
"identifier": html_url,
"relation": "isSupplementTo",
"resource_type": "software",
"scheme": "url",
}
]

# Make the deposit!
url = "https://zenodo.org/api/deposit/depositions/%s" % upload["id"]
response = requests.put(
Expand All @@ -243,7 +254,9 @@ def upload_metadata(self, upload, zenodo_json, version):
return response.json()


def upload_archive(archive, version, zenodo_json=None, doi=None, sandbox=False):
def upload_archive(
archive, version, html_url=None, zenodo_json=None, doi=None, sandbox=False
):
"""
Upload an archive to an existing Zenodo "versions DOI"
"""
Expand All @@ -265,7 +278,7 @@ def upload_archive(archive, version, zenodo_json=None, doi=None, sandbox=False):
cli.upload_archive(upload, path)

# Finally, load .zenodo.json and add version
data = cli.upload_metadata(upload, zenodo_json, version)
data = cli.upload_metadata(upload, zenodo_json, version, html_url)

# Finally, publish
cli.publish(data)
Expand All @@ -288,6 +301,9 @@ def get_parser():
)
upload.add_argument("--version", help="version to upload")
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"
)
return parser


Expand Down Expand Up @@ -316,6 +332,7 @@ def help(return_code=0):
zenodo_json=args.zenodo_json,
version=args.version,
doi=args.doi,
html_url=args.html_url,
)

# We should not get here :)
Expand Down