From 214909770857621f871379978fc33ddb9fa22596 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 28 Jun 2021 11:15:30 -0500 Subject: [PATCH] handle already published workspace packages --- jupyter_releaser/lib.py | 10 +++++++--- jupyter_releaser/tests/test_cli.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/jupyter_releaser/lib.py b/jupyter_releaser/lib.py index 29e9f1dd..eaddfe3e 100644 --- a/jupyter_releaser/lib.py +++ b/jupyter_releaser/lib.py @@ -3,13 +3,12 @@ import os import os.path as osp import re -import shlex import shutil -import sys import uuid from datetime import datetime from glob import glob from pathlib import Path +from subprocess import CalledProcessError from tempfile import TemporaryDirectory import requests @@ -372,7 +371,12 @@ def publish_assets(dist_dir, npm_token, npm_cmd, twine_cmd, dry_run, use_checkou util.run(f"{twine_cmd} {name}", cwd=dist_dir) found = True elif suffix == ".tgz": - util.run(f"{npm_cmd} {name}", cwd=dist_dir) + # Ignore already published versions + try: + util.run(f"{npm_cmd} {name}", cwd=dist_dir, quiet=True) + except CalledProcessError as e: + if "EPUBLISHCONFLICT" not in e.stderr.decode("utf-8"): + raise e found = True else: util.log(f"Nothing to upload for {name}") diff --git a/jupyter_releaser/tests/test_cli.py b/jupyter_releaser/tests/test_cli.py index f36f2fe4..0eeeeab6 100644 --- a/jupyter_releaser/tests/test_cli.py +++ b/jupyter_releaser/tests/test_cli.py @@ -519,6 +519,35 @@ def wrapped(cmd, **kwargs): assert called == 3, called +def test_publish_assets_npm_exists(npm_dist, runner, mocker): + dist_dir = npm_dist / util.CHECKOUT_NAME / "dist" + called = 0 + + def wrapped(cmd, **kwargs): + nonlocal called + if cmd.startswith("npm publish --dry-run"): + err = CalledProcessError(1, "foo") + err.stderr = "EPUBLISHCONFLICT".encode("UTF-8") + called += 1 + raise err + + mock_run = mocker.patch("jupyter_releaser.util.run", wraps=wrapped) + + runner( + [ + "publish-assets", + "--npm-token", + "abc", + "--npm-cmd", + "npm publish --dry-run", + "--dist-dir", + dist_dir, + ] + ) + + assert called == 3, called + + def test_publish_release(npm_dist, runner, mocker, open_mock): open_mock.side_effect = [MockHTTPResponse([REPO_DATA]), MockHTTPResponse()] dist_dir = npm_dist / util.CHECKOUT_NAME / "dist"