Skip to content

Commit 2149097

Browse files
author
Steven Silvester
committed
handle already published workspace packages
1 parent 8285f2d commit 2149097

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

jupyter_releaser/lib.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
import os
44
import os.path as osp
55
import re
6-
import shlex
76
import shutil
8-
import sys
97
import uuid
108
from datetime import datetime
119
from glob import glob
1210
from pathlib import Path
11+
from subprocess import CalledProcessError
1312
from tempfile import TemporaryDirectory
1413

1514
import requests
@@ -372,7 +371,12 @@ def publish_assets(dist_dir, npm_token, npm_cmd, twine_cmd, dry_run, use_checkou
372371
util.run(f"{twine_cmd} {name}", cwd=dist_dir)
373372
found = True
374373
elif suffix == ".tgz":
375-
util.run(f"{npm_cmd} {name}", cwd=dist_dir)
374+
# Ignore already published versions
375+
try:
376+
util.run(f"{npm_cmd} {name}", cwd=dist_dir, quiet=True)
377+
except CalledProcessError as e:
378+
if "EPUBLISHCONFLICT" not in e.stderr.decode("utf-8"):
379+
raise e
376380
found = True
377381
else:
378382
util.log(f"Nothing to upload for {name}")

jupyter_releaser/tests/test_cli.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,35 @@ def wrapped(cmd, **kwargs):
519519
assert called == 3, called
520520

521521

522+
def test_publish_assets_npm_exists(npm_dist, runner, mocker):
523+
dist_dir = npm_dist / util.CHECKOUT_NAME / "dist"
524+
called = 0
525+
526+
def wrapped(cmd, **kwargs):
527+
nonlocal called
528+
if cmd.startswith("npm publish --dry-run"):
529+
err = CalledProcessError(1, "foo")
530+
err.stderr = "EPUBLISHCONFLICT".encode("UTF-8")
531+
called += 1
532+
raise err
533+
534+
mock_run = mocker.patch("jupyter_releaser.util.run", wraps=wrapped)
535+
536+
runner(
537+
[
538+
"publish-assets",
539+
"--npm-token",
540+
"abc",
541+
"--npm-cmd",
542+
"npm publish --dry-run",
543+
"--dist-dir",
544+
dist_dir,
545+
]
546+
)
547+
548+
assert called == 3, called
549+
550+
522551
def test_publish_release(npm_dist, runner, mocker, open_mock):
523552
open_mock.side_effect = [MockHTTPResponse([REPO_DATA]), MockHTTPResponse()]
524553
dist_dir = npm_dist / util.CHECKOUT_NAME / "dist"

0 commit comments

Comments
 (0)