Skip to content

Commit 01fb60a

Browse files
authored
This has your changes to make html_url optional (#15)
* Update action.yml: pass in url to the release Signed-off-by: vsoch <[email protected]> Co-authored-by: eeholmes <[email protected]>
1 parent 9b36ca6 commit 01fb60a

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on release, and without needing to enable admin webhooks. To get this working yo
1111

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

14-
```
14+
```console
1515
doi https://doi.org/10.5281/zenodo.6326823
1616
conceptdoi https://doi.org/10.5281/zenodo.6326822
1717
conceptbadge https://zenodo.org/badge/doi/10.5281/zenodo.6326822.svg
@@ -84,7 +84,7 @@ jobs:
8484
# Archiving the zipball will cause Zenodo to show a preview of the contents of the zipball while using tarball will not.
8585
run: |
8686
name=$(basename ${zipball}).zip
87-
curl -L $tarball > $name
87+
curl -L $zipball > $name
8888
echo "archive=${name}" >> $GITHUB_ENV
8989
9090
- name: Run Zenodo Deploy
@@ -93,6 +93,7 @@ jobs:
9393
token: ${{ secrets.ZENODO_TOKEN }}
9494
version: ${{ github.event.release.tag_name }}
9595
zenodo_json: .zenodo.json # optional
96+
html_url: ${{ github.event.release.html_url }} # optional to include link to the GitHub release
9697
archive: ${{ env.archive }}
9798

9899
# Optional DOI for all versions. Leaving this blank (the default) will create

action.yml

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ inputs:
1010
version:
1111
description: the release version
1212
required: true
13+
html_url:
14+
description: The HTML url to appear with the release (optional)
1315
zenodo_json:
1416
description: Path to zenodo.json to upload with metadata (must exist)
1517
doi:
@@ -54,6 +56,7 @@ runs:
5456
zenodo_json: ${{ inputs.zenodo_json }}
5557
archive: ${{ inputs.archive }}
5658
version: ${{ inputs.version }}
59+
html_url: ${{ inputs.html_url }}
5760
ACTION_PATH: ${{ github.action_path }}
5861
ZENODO_TOKEN: ${{ inputs.token }}
5962
doi: ${{ inputs.doi }}
@@ -65,6 +68,9 @@ runs:
6568
if [[ "${zenodo_json}" != "" ]]; then
6669
command="$command --zenodo-json ${zenodo_json}"
6770
fi
71+
if [[ "${html_url}" != "" ]]; then
72+
command="$command --html-url ${html_url}"
73+
fi
6874
printf "$command\n"
6975
$command
7076

scripts/deploy.py

+26-9
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77

88

99
import argparse
10-
import os
1110
import json
11+
import os
1212
import sys
13-
from glob import glob
1413
from datetime import datetime
14+
from glob import glob
15+
1516
import requests
1617

1718

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

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

195195
def publish(self, data):
@@ -208,7 +208,7 @@ def publish(self, data):
208208
for k, v in published["links"].items():
209209
set_env_and_output(k, v)
210210

211-
def upload_metadata(self, upload, zenodo_json, version):
211+
def upload_metadata(self, upload, zenodo_json, version, html_url=None):
212212
"""
213213
Given an upload response and zenodo json, upload new data
214214
@@ -220,13 +220,24 @@ def upload_metadata(self, upload, zenodo_json, version):
220220
if zenodo_json:
221221
metadata.update(read_json(zenodo_json))
222222
metadata["version"] = version
223-
metadata["publication_date"] = str(datetime.today().strftime('%Y-%m-%d'))
223+
metadata["publication_date"] = str(datetime.today().strftime("%Y-%m-%d"))
224224

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

230+
# Update the related info to use the url to the current release
231+
if html_url:
232+
metadata["related_identifiers"] = [
233+
{
234+
"identifier": html_url,
235+
"relation": "isSupplementTo",
236+
"resource_type": "software",
237+
"scheme": "url",
238+
}
239+
]
240+
230241
# Make the deposit!
231242
url = "https://zenodo.org/api/deposit/depositions/%s" % upload["id"]
232243
response = requests.put(
@@ -243,7 +254,9 @@ def upload_metadata(self, upload, zenodo_json, version):
243254
return response.json()
244255

245256

246-
def upload_archive(archive, version, zenodo_json=None, doi=None, sandbox=False):
257+
def upload_archive(
258+
archive, version, html_url=None, zenodo_json=None, doi=None, sandbox=False
259+
):
247260
"""
248261
Upload an archive to an existing Zenodo "versions DOI"
249262
"""
@@ -265,7 +278,7 @@ def upload_archive(archive, version, zenodo_json=None, doi=None, sandbox=False):
265278
cli.upload_archive(upload, path)
266279

267280
# Finally, load .zenodo.json and add version
268-
data = cli.upload_metadata(upload, zenodo_json, version)
281+
data = cli.upload_metadata(upload, zenodo_json, version, html_url)
269282

270283
# Finally, publish
271284
cli.publish(data)
@@ -288,6 +301,9 @@ def get_parser():
288301
)
289302
upload.add_argument("--version", help="version to upload")
290303
upload.add_argument("--doi", help="an existing DOI to add a new version to")
304+
upload.add_argument(
305+
"--html-url", dest="html_url", help="url to use for the release"
306+
)
291307
return parser
292308

293309

@@ -316,6 +332,7 @@ def help(return_code=0):
316332
zenodo_json=args.zenodo_json,
317333
version=args.version,
318334
doi=args.doi,
335+
html_url=args.html_url,
319336
)
320337

321338
# We should not get here :)

0 commit comments

Comments
 (0)