Skip to content

Commit

Permalink
Merge pull request #49 from blink1073/fix-already-published
Browse files Browse the repository at this point in the history
Handle already published workspace packages
  • Loading branch information
Steven Silvester authored Jun 29, 2021
2 parents 64c8461 + 2149097 commit f15fa65
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
10 changes: 7 additions & 3 deletions jupyter_releaser/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")
Expand Down
29 changes: 29 additions & 0 deletions jupyter_releaser/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit f15fa65

Please sign in to comment.