예제 #1
0
def test_forwardport_changelog_no_new(npm_package, runner, mocker, open_mock,
                                      git_prep):

    open_mock.side_effect = [MockHTTPResponse([REPO_DATA]), MockHTTPResponse()]

    # Create a branch with a changelog entry
    util.run("git checkout -b backport_branch", cwd=util.CHECKOUT_NAME)
    util.run("git push origin backport_branch", cwd=util.CHECKOUT_NAME)
    mock_changelog_entry(npm_package, runner, mocker)
    util.run('git commit -a -m "Add changelog entry"', cwd=util.CHECKOUT_NAME)
    util.run(f"git tag v{VERSION_SPEC}", cwd=util.CHECKOUT_NAME)

    # Run the forwardport workflow against default branch
    os.chdir(util.CHECKOUT_NAME)
    url = os.getcwd()
    runner(["forwardport-changelog", HTML_URL, "--git-url", url])

    assert len(open_mock.mock_calls) == 1

    expected = """
<!-- <START NEW CHANGELOG ENTRY> -->

## 1.0.1
"""
    assert expected in Path("CHANGELOG.md").read_text(encoding="utf-8")
예제 #2
0
def test_forwardport_changelog_has_new(npm_package, runner, mocker, open_mock,
                                       git_prep):

    open_mock.side_effect = [MockHTTPResponse([REPO_DATA]), MockHTTPResponse()]
    current = util.run("git branch --show-current")

    # Create a branch with a changelog entry
    util.run("git checkout -b backport_branch", cwd=util.CHECKOUT_NAME)
    util.run("git push origin backport_branch", cwd=util.CHECKOUT_NAME)
    util.run(f"git checkout {current}")
    mock_changelog_entry(npm_package, runner, mocker)
    util.run(f'git commit -a -m "Add changelog entry {VERSION_SPEC}"',
             cwd=util.CHECKOUT_NAME)
    util.run(f"git tag v{VERSION_SPEC}", cwd=util.CHECKOUT_NAME)
    util.run(f"git checkout {current}", cwd=util.CHECKOUT_NAME)
    util.run("git push origin backport_branch --tags", cwd=util.CHECKOUT_NAME)

    # Add a new changelog entry in main branch
    util.run("git checkout backport_branch", cwd=str(npm_package))
    util.run(f"git checkout {current}", cwd=util.CHECKOUT_NAME)
    mock_changelog_entry(npm_package, runner, mocker, version_spec="2.0.0")
    util.run('git commit -a -m "Add changelog entry v2.0.0"',
             cwd=util.CHECKOUT_NAME)
    util.run("git tag v2.0.0", cwd=util.CHECKOUT_NAME)
    util.run("git checkout backport_branch", cwd=npm_package)
    util.run(f"git push origin {current} --tags", cwd=util.CHECKOUT_NAME)

    # Run the forwardport workflow against default branch
    url = osp.abspath(npm_package)
    os.chdir(npm_package)
    runner([
        "forwardport-changelog", HTML_URL, "--git-url", url, "--branch",
        current
    ])

    assert len(open_mock.call_args) == 2
    util.run(f"git checkout {current}", cwd=npm_package)

    expected = """
<!-- <START NEW CHANGELOG ENTRY> -->

## 2.0.0
"""
    text = Path("CHANGELOG.md").read_text(encoding="utf-8")
    assert expected in text, text

    expect = """
<!-- <END NEW CHANGELOG ENTRY> -->

## 1.0.1
"""
    assert expected in text, text
def py_dist(py_package, runner, mocker, build_mock, git_prep):
    changelog_entry = testutil.mock_changelog_entry(py_package, runner, mocker)

    # Create the dist files
    util.run("python -m build .", cwd=util.CHECKOUT_NAME)

    # Finalize the release
    runner(["tag-release"])

    return py_package
def npm_dist(workspace_package, runner, mocker, git_prep):
    changelog_entry = testutil.mock_changelog_entry(workspace_package, runner,
                                                    mocker)

    # Create the dist files
    runner(["build-npm"])

    # Finalize the release
    runner(["tag-release"])

    return workspace_package
def test_check_changelog(py_package, tmp_path, mocker, runner, git_prep):
    changelog_entry = mock_changelog_entry(py_package, runner, mocker)
    output = "output.md"

    # prep the release
    bump_version(VERSION_SPEC)

    runner(
        ["check-changelog", "--changelog-path", changelog_entry, "--output", output],
    )

    output = Path(util.CHECKOUT_NAME) / output
    assert PR_ENTRY in output.read_text(encoding="utf-8")
    changelog_entry = Path(util.CHECKOUT_NAME) / changelog_entry
    text = changelog_entry.read_text(encoding="utf-8")
    assert f"{changelog.START_MARKER}\n\n## {VERSION_SPEC}" in text
    assert changelog.END_MARKER in text
예제 #6
0
def test_publish_assets_py(py_package, runner, mocker, git_prep):
    # Create the dist files
    changelog_entry = mock_changelog_entry(py_package, runner, mocker)
    run("python -m build .", cwd=util.CHECKOUT_NAME)

    orig_run = util.run
    called = 0

    def wrapped(cmd, **kwargs):
        nonlocal called
        if cmd.startswith("twine upload"):
            called += 1
        return orig_run(cmd, **kwargs)

    mock_run = mocker.patch("jupyter_releaser.util.run", wraps=wrapped)

    dist_dir = py_package / util.CHECKOUT_NAME / "dist"
    runner(["publish-assets", "--dist-dir", dist_dir, "--dry-run"])
    assert called == 2, called
예제 #7
0
def test_extract_dist_py(py_package, runner, mocker, open_mock, tmp_path,
                         git_prep):
    changelog_entry = mock_changelog_entry(py_package, runner, mocker)

    # Create the dist files
    run("python -m build .", cwd=util.CHECKOUT_NAME)

    # Finalize the release
    runner(["tag-release"])

    os.makedirs("staging")
    shutil.move(f"{util.CHECKOUT_NAME}/dist", "staging")

    def helper(path, **kwargs):
        return MockRequestResponse(f"staging/dist/{path}")

    get_mock = mocker.patch("requests.get", side_effect=helper)

    tag_name = f"v{VERSION_SPEC}"

    dist_names = [osp.basename(f) for f in glob("staging/dist/*.*")]
    releases = [
        dict(
            tag_name=tag_name,
            target_commitish=util.get_branch(),
            assets=[
                dict(name=dist_name, url=dist_name) for dist_name in dist_names
            ],
        )
    ]
    sha = run("git rev-parse HEAD", cwd=util.CHECKOUT_NAME)

    tags = [dict(ref=f"refs/tags/{tag_name}", object=dict(sha=sha))]
    url = normalize_path(osp.join(os.getcwd(), util.CHECKOUT_NAME))
    open_mock.side_effect = [
        MockHTTPResponse(releases),
        MockHTTPResponse(tags),
        MockHTTPResponse(dict(html_url=url)),
    ]

    runner(["extract-release", HTML_URL])
    assert len(open_mock.mock_calls) == 3
    assert len(get_mock.mock_calls) == len(dist_names) == 2
def test_publish_release_py(py_package, runner, mocker, open_mock, git_prep):
    open_mock.side_effect = [MockHTTPResponse([REPO_DATA]), MockHTTPResponse()]

    # Create the dist files
    changelog_entry = mock_changelog_entry(py_package, runner, mocker)
    run("python -m build .", cwd=util.CHECKOUT_NAME)

    orig_run = util.run
    called = 0

    def wrapped(cmd, **kwargs):
        nonlocal called
        if cmd.startswith("twine upload"):
            called += 1
        return orig_run(cmd, **kwargs)

    mock_run = mocker.patch("jupyter_releaser.util.run", wraps=wrapped)

    dist_dir = py_package / util.CHECKOUT_NAME / "dist"
    runner(["publish-release", HTML_URL, "--dist-dir", dist_dir, "--dry-run"])
    assert len(open_mock.call_args) == 2
    assert called == 2, called
def test_draft_changelog_lerna(workspace_package, mocker, runner, open_mock, git_prep):
    mock_changelog_entry(workspace_package, runner, mocker)
    runner(["draft-changelog", "--version-spec", VERSION_SPEC])
    open_mock.assert_called_once()
def test_draft_changelog_dry_run(npm_package, mocker, runner, git_prep):
    mock_changelog_entry(npm_package, runner, mocker)
    runner(["draft-changelog", "--dry-run", "--version-spec", VERSION_SPEC])