diff --git a/README.md b/README.md index b971b90..44dab32 100644 --- a/README.md +++ b/README.md @@ -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 @@ -84,7 +84,7 @@ jobs: # Archiving the zipball will cause Zenodo to show a preview of the contents of the zipball while using tarball will not. run: | name=$(basename ${zipball}).zip - curl -L $tarball > $name + curl -L $zipball > $name echo "archive=${name}" >> $GITHUB_ENV - name: Run Zenodo Deploy @@ -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 to include link to the GitHub release archive: ${{ env.archive }} # Optional DOI for all versions. Leaving this blank (the default) will create diff --git a/action.yml b/action.yml index 1a266e7..67ff84f 100644 --- a/action.yml +++ b/action.yml @@ -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: @@ -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 }} @@ -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 diff --git a/scripts/deploy.py b/scripts/deploy.py index e0317ee..ce80295 100644 --- a/scripts/deploy.py +++ b/scripts/deploy.py @@ -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 @@ -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: @@ -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): @@ -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 @@ -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( @@ -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" """ @@ -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) @@ -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 @@ -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 :)