Skip to content

Commit a9c8870

Browse files
authored
Fix missing command arguments (#17)
* add title and description support + do not override related_identifiers if some exists * fix invalid format args * pass down title/description to command * add quotes around action parameters * undo quotes for zenodo json param * undo quotes for doi param * provide '--description-file' alternative parameter for zenodo record description * add missing 'description_file' forwarding * replace single quotes by escaped double quotes to avoid unresolved file path with literal quote in string parameter + use argparse.FileType to raise unresolved file immediately * adjust commands to avoid weird literal single/double quotes parsing
1 parent 59b48fd commit a9c8870

File tree

2 files changed

+69
-14
lines changed

2 files changed

+69
-14
lines changed

action.yml

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ inputs:
1919
title:
2020
description: zenodo title (optional)
2121
description:
22-
description: zenodo description (optional)
22+
description: zenodo description as plain text (optional)
23+
description_file:
24+
description: zenodo description from a file (optional)
2325

2426
outputs:
2527
badge:
@@ -64,18 +66,29 @@ runs:
6466
ACTION_PATH: ${{ github.action_path }}
6567
ZENODO_TOKEN: ${{ inputs.token }}
6668
doi: ${{ inputs.doi }}
69+
title: ${{ inputs.title }}
70+
description: ${{ inputs.description }}
71+
description_file: ${{ inputs.description_file }}
6772
run: |
68-
command="python ${{ github.action_path }}/scripts/deploy.py upload ${archive} --version ${version}"
69-
if [[ "${doi}" != "" ]]; then
70-
command="$command --doi ${doi}"
73+
command=("python" "${{ github.action_path }}/scripts/deploy.py" "upload" "${archive}" "--version" "${version}")
74+
if [[ -n "${doi}" ]]; then
75+
command+=("--doi" "${doi}")
7176
fi
72-
if [[ "${zenodo_json}" != "" ]]; then
73-
command="$command --zenodo-json ${zenodo_json}"
77+
if [[ -n "${title}" ]]; then
78+
command+=("--title" "${title}")
7479
fi
75-
if [[ "${html_url}" != "" ]]; then
76-
command="$command --html-url ${html_url}"
80+
if [[ -n "${description}" ]]; then
81+
command+=("--description" "${description}")
82+
elif [[ -n "${description_file}" ]]; then
83+
command+=("--description-file" "${description_file}")
7784
fi
78-
printf "$command\n"
79-
$command
85+
if [[ -n "${zenodo_json}" ]]; then
86+
command+=("--zenodo-json" "${zenodo_json}")
87+
fi
88+
if [[ -n "${html_url}" ]]; then
89+
command+=("--html-url" "${html_url}")
90+
fi
91+
printf "%s " "${command[@]}"
92+
"${command[@]}"
8093
8194
shell: bash

scripts/deploy.py

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@
1212
import sys
1313
from datetime import datetime
1414
from glob import glob
15+
from typing import TYPE_CHECKING
1516

1617
import requests
1718

19+
if TYPE_CHECKING:
20+
import io
21+
from typing import Any, Dict, Optional
22+
1823

1924
def read_file(filename):
2025
with open(filename, "r") as fd:
@@ -208,7 +213,16 @@ def publish(self, data):
208213
for k, v in published["links"].items():
209214
set_env_and_output(k, v)
210215

211-
def upload_metadata(self, upload, zenodo_json, version, html_url=None, title=None, description=None):
216+
def upload_metadata(
217+
self,
218+
upload, # type: Dict[str, Any]
219+
zenodo_json, # type: str
220+
version, # type: str
221+
html_url=None, # type: Optional[str]
222+
title=None, # type: Optional[str]
223+
description=None, # type: Optional[str]
224+
description_file=None, # type: Optional[io.TextIOBase]
225+
): # type: (...) -> Dict[str, Any]
212226
"""
213227
Given an upload response and zenodo json, upload new data
214228
@@ -244,6 +258,8 @@ def upload_metadata(self, upload, zenodo_json, version, html_url=None, title=Non
244258

245259
if description is not None:
246260
metadata["description"] = description
261+
elif description_file:
262+
metadata["description"] = description_file.read()
247263

248264
# Make the deposit!
249265
url = "https://zenodo.org/api/deposit/depositions/%s" % upload["id"]
@@ -261,7 +277,15 @@ def upload_metadata(self, upload, zenodo_json, version, html_url=None, title=Non
261277

262278

263279
def upload_archive(
264-
archive, version, html_url=None, zenodo_json=None, doi=None, sandbox=False, title=None, description=None,
280+
archive,
281+
version,
282+
html_url=None,
283+
zenodo_json=None,
284+
doi=None,
285+
sandbox=False,
286+
title=None,
287+
description=None,
288+
description_file=None,
265289
):
266290
"""
267291
Upload an archive to an existing Zenodo "versions DOI"
@@ -284,7 +308,15 @@ def upload_archive(
284308
cli.upload_archive(upload, path)
285309

286310
# Finally, load .zenodo.json and add version
287-
data = cli.upload_metadata(upload, zenodo_json, version, html_url, title=title, description=description)
311+
data = cli.upload_metadata(
312+
upload,
313+
zenodo_json,
314+
version,
315+
html_url,
316+
title=title,
317+
description=description,
318+
description_file=description_file,
319+
)
288320

289321
# Finally, publish
290322
cli.publish(data)
@@ -307,7 +339,16 @@ def get_parser():
307339
)
308340
upload.add_argument("--version", help="version to upload")
309341
upload.add_argument("--title", help="Title to override in upload")
310-
upload.add_argument("--description", help="Description to override in upload (allows HTML)")
342+
upload_desc = upload.add_mutually_exclusive_group()
343+
upload_desc.add_argument(
344+
"--description",
345+
help="Description to override in upload as plain text (allows HTML, but be careful about escaping)",
346+
)
347+
upload_desc.add_argument(
348+
"--description-file",
349+
help="Description to override in upload from a file.",
350+
type=argparse.FileType("r", encoding="utf-8"),
351+
)
311352
upload.add_argument("--doi", help="an existing DOI to add a new version to")
312353
upload.add_argument(
313354
"--html-url", dest="html_url", help="url to use for the release"
@@ -343,6 +384,7 @@ def help(return_code=0):
343384
html_url=args.html_url,
344385
title=args.title,
345386
description=args.description,
387+
description_file=args.description_file,
346388
)
347389

348390
# We should not get here :)

0 commit comments

Comments
 (0)