Skip to content

Commit

Permalink
This has your changes to make html_url optional (#15)
Browse files Browse the repository at this point in the history
* Update action.yml: pass in url to the release

Signed-off-by: vsoch <[email protected]>
Co-authored-by: eeholmes <[email protected]>
  • Loading branch information
eeholmes and eeholmes authored Mar 13, 2024
1 parent 9b36ca6 commit 01fb60a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
5 changes: 3 additions & 2 deletions 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 @@ -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
Expand All @@ -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
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

0 comments on commit 01fb60a

Please sign in to comment.