2018-05-23 23:06:05 +00:00
|
|
|
import io
|
2021-01-05 14:56:33 +00:00
|
|
|
from pathlib import Path
|
2018-05-24 05:10:50 +00:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2018-05-23 23:06:05 +00:00
|
|
|
from release import cibuild
|
|
|
|
|
2021-01-05 14:56:33 +00:00
|
|
|
root = Path(__file__).parent.parent.parent
|
|
|
|
|
2018-05-23 23:06:05 +00:00
|
|
|
|
2018-05-24 05:10:50 +00:00
|
|
|
def test_buildenviron_live():
|
|
|
|
be = cibuild.BuildEnviron.from_env()
|
|
|
|
assert be.release_dir
|
|
|
|
|
|
|
|
|
2018-05-23 23:06:05 +00:00
|
|
|
def test_buildenviron_common():
|
|
|
|
be = cibuild.BuildEnviron(
|
2018-06-02 19:37:44 +00:00
|
|
|
system="Linux",
|
2021-01-05 14:56:33 +00:00
|
|
|
root_dir=root,
|
2021-03-16 15:17:27 +00:00
|
|
|
branch="main",
|
2018-05-23 23:06:05 +00:00
|
|
|
)
|
2021-01-05 14:56:33 +00:00
|
|
|
assert be.release_dir == be.root_dir / "release"
|
|
|
|
assert be.dist_dir == be.root_dir / "release" / "dist"
|
|
|
|
assert be.build_dir == be.root_dir / "release" / "build"
|
2018-05-24 05:10:50 +00:00
|
|
|
assert not be.has_docker_creds
|
2018-05-23 23:06:05 +00:00
|
|
|
|
|
|
|
cs = io.StringIO()
|
|
|
|
be.dump_info(cs)
|
|
|
|
assert cs.getvalue()
|
|
|
|
|
2018-05-24 05:10:50 +00:00
|
|
|
be = cibuild.BuildEnviron(
|
2018-06-02 19:37:44 +00:00
|
|
|
system="Unknown",
|
2021-01-05 14:56:33 +00:00
|
|
|
root_dir=root,
|
2018-05-24 05:10:50 +00:00
|
|
|
)
|
|
|
|
with pytest.raises(cibuild.BuildError):
|
|
|
|
be.version
|
|
|
|
with pytest.raises(cibuild.BuildError):
|
|
|
|
be.platform_tag
|
|
|
|
|
2018-05-23 23:06:05 +00:00
|
|
|
|
2021-01-05 14:56:33 +00:00
|
|
|
def test_buildenviron_pr(monkeypatch):
|
2018-05-24 10:32:31 +00:00
|
|
|
# Simulates a PR. We build everything, but don't have access to secret
|
|
|
|
# credential env variables.
|
2021-01-05 14:56:33 +00:00
|
|
|
monkeypatch.setenv("GITHUB_REF", "refs/pull/42/merge")
|
|
|
|
monkeypatch.setenv("CI_BUILD_WHEEL", "1")
|
|
|
|
monkeypatch.setenv("GITHUB_EVENT_NAME", "pull_request")
|
2019-11-19 17:15:08 +00:00
|
|
|
|
2021-01-05 14:56:33 +00:00
|
|
|
be = cibuild.BuildEnviron.from_env()
|
|
|
|
assert be.branch == "pr-42"
|
|
|
|
assert be.is_pull_request
|
|
|
|
assert be.should_build_wheel
|
|
|
|
assert not be.should_upload_pypi
|
2018-05-23 23:06:05 +00:00
|
|
|
|
|
|
|
|
2018-05-24 09:59:45 +00:00
|
|
|
def test_buildenviron_commit():
|
2018-05-24 10:32:31 +00:00
|
|
|
# Simulates an ordinary commit on the master branch.
|
2018-05-24 09:59:45 +00:00
|
|
|
be = cibuild.BuildEnviron(
|
2021-01-05 14:56:33 +00:00
|
|
|
system="Linux",
|
|
|
|
root_dir=root,
|
2021-03-16 15:17:27 +00:00
|
|
|
branch="main",
|
2021-01-05 14:56:33 +00:00
|
|
|
is_pull_request=False,
|
2018-06-02 19:37:44 +00:00
|
|
|
should_build_wheel=True,
|
|
|
|
should_build_pyinstaller=True,
|
|
|
|
should_build_docker=True,
|
|
|
|
docker_username="foo",
|
|
|
|
docker_password="bar",
|
2019-11-19 17:15:08 +00:00
|
|
|
has_aws_creds=True,
|
2018-05-24 09:59:45 +00:00
|
|
|
)
|
2018-05-25 00:42:59 +00:00
|
|
|
assert be.docker_tag == "mitmproxy/mitmproxy:dev"
|
2018-05-24 10:15:55 +00:00
|
|
|
assert be.should_upload_docker
|
|
|
|
assert not be.should_upload_pypi
|
2018-05-24 10:32:31 +00:00
|
|
|
assert be.should_upload_docker
|
2019-11-19 17:15:08 +00:00
|
|
|
assert be.should_upload_aws
|
2018-05-24 22:50:48 +00:00
|
|
|
assert not be.is_prod_release
|
2018-06-16 03:09:34 +00:00
|
|
|
assert not be.is_maintenance_branch
|
2018-05-24 09:59:45 +00:00
|
|
|
|
|
|
|
|
2018-06-02 19:37:44 +00:00
|
|
|
def test_buildenviron_releasetag():
|
2018-05-24 10:32:31 +00:00
|
|
|
# Simulates a tagged release on a release branch.
|
2018-05-23 23:06:05 +00:00
|
|
|
be = cibuild.BuildEnviron(
|
2018-06-02 19:37:44 +00:00
|
|
|
system="Linux",
|
2021-01-05 14:56:33 +00:00
|
|
|
root_dir=root,
|
|
|
|
tag="v0.0.1",
|
2018-06-02 19:37:44 +00:00
|
|
|
should_build_wheel=True,
|
|
|
|
should_build_docker=True,
|
|
|
|
should_build_pyinstaller=True,
|
|
|
|
has_twine_creds=True,
|
|
|
|
docker_username="foo",
|
|
|
|
docker_password="bar",
|
2018-05-23 23:06:05 +00:00
|
|
|
)
|
2018-06-15 21:41:15 +00:00
|
|
|
assert be.tag == "v0.0.1"
|
2021-01-05 14:56:33 +00:00
|
|
|
assert be.branch is None
|
2018-05-23 23:06:05 +00:00
|
|
|
assert be.version == "0.0.1"
|
|
|
|
assert be.upload_dir == "0.0.1"
|
2018-05-25 00:42:59 +00:00
|
|
|
assert be.docker_tag == "mitmproxy/mitmproxy:0.0.1"
|
2018-05-24 10:15:55 +00:00
|
|
|
assert be.should_upload_pypi
|
2018-05-24 10:32:31 +00:00
|
|
|
assert be.should_upload_docker
|
2018-05-24 22:50:48 +00:00
|
|
|
assert be.is_prod_release
|
2018-06-16 03:09:34 +00:00
|
|
|
assert not be.is_maintenance_branch
|
2018-05-23 23:06:05 +00:00
|
|
|
|
2018-05-25 00:42:59 +00:00
|
|
|
|
2018-06-15 21:41:15 +00:00
|
|
|
def test_buildenviron_namedtag():
|
|
|
|
# Simulates a non-release tag on a branch.
|
|
|
|
be = cibuild.BuildEnviron(
|
|
|
|
system="Linux",
|
2021-01-05 14:56:33 +00:00
|
|
|
root_dir=root,
|
|
|
|
tag="anyname",
|
2018-06-15 21:41:15 +00:00
|
|
|
should_build_wheel=True,
|
|
|
|
should_build_docker=True,
|
|
|
|
should_build_pyinstaller=True,
|
|
|
|
has_twine_creds=True,
|
|
|
|
docker_username="foo",
|
|
|
|
docker_password="bar",
|
|
|
|
)
|
|
|
|
assert be.tag == "anyname"
|
2021-01-05 14:56:33 +00:00
|
|
|
assert be.branch is None
|
2018-06-15 21:41:15 +00:00
|
|
|
assert be.version == "anyname"
|
|
|
|
assert be.upload_dir == "anyname"
|
|
|
|
assert be.docker_tag == "mitmproxy/mitmproxy:anyname"
|
|
|
|
assert not be.should_upload_pypi
|
|
|
|
assert not be.should_upload_docker
|
|
|
|
assert not be.is_prod_release
|
2018-06-16 03:09:34 +00:00
|
|
|
assert not be.is_maintenance_branch
|
2018-06-15 21:41:15 +00:00
|
|
|
|
|
|
|
|
2018-06-16 03:09:34 +00:00
|
|
|
def test_buildenviron_dev_branch():
|
2018-06-15 21:41:15 +00:00
|
|
|
# Simulates a commit on a development branch on the main repo
|
2018-05-23 23:06:05 +00:00
|
|
|
be = cibuild.BuildEnviron(
|
2018-06-02 19:37:44 +00:00
|
|
|
system="Linux",
|
2021-01-05 14:56:33 +00:00
|
|
|
root_dir=root,
|
|
|
|
branch="mybranch",
|
2018-06-02 19:37:44 +00:00
|
|
|
should_build_wheel=True,
|
|
|
|
should_build_docker=True,
|
|
|
|
should_build_pyinstaller=True,
|
|
|
|
has_twine_creds=True,
|
|
|
|
docker_username="foo",
|
|
|
|
docker_password="bar",
|
2018-05-23 23:06:05 +00:00
|
|
|
)
|
2021-01-05 14:56:33 +00:00
|
|
|
assert be.tag is None
|
2018-05-24 10:32:31 +00:00
|
|
|
assert be.branch == "mybranch"
|
|
|
|
assert be.version == "mybranch"
|
|
|
|
assert be.upload_dir == "branches/mybranch"
|
|
|
|
assert not be.should_upload_pypi
|
|
|
|
assert not be.should_upload_docker
|
2018-06-16 03:09:34 +00:00
|
|
|
assert not be.is_maintenance_branch
|
|
|
|
|
|
|
|
|
|
|
|
def test_buildenviron_maintenance_branch():
|
|
|
|
# Simulates a commit on a release maintenance branch on the main repo
|
|
|
|
be = cibuild.BuildEnviron(
|
|
|
|
system="Linux",
|
2021-01-05 14:56:33 +00:00
|
|
|
root_dir=root,
|
|
|
|
branch="v0.x",
|
2018-06-16 03:09:34 +00:00
|
|
|
should_build_wheel=True,
|
|
|
|
should_build_docker=True,
|
|
|
|
should_build_pyinstaller=True,
|
|
|
|
has_twine_creds=True,
|
|
|
|
docker_username="foo",
|
|
|
|
docker_password="bar",
|
|
|
|
)
|
2021-01-05 14:56:33 +00:00
|
|
|
assert be.tag is None
|
2018-06-16 03:09:34 +00:00
|
|
|
assert be.branch == "v0.x"
|
|
|
|
assert be.version == "v0.x"
|
|
|
|
assert be.upload_dir == "branches/v0.x"
|
|
|
|
assert not be.should_upload_pypi
|
|
|
|
assert not be.should_upload_docker
|
|
|
|
assert be.is_maintenance_branch
|
2018-05-23 23:06:05 +00:00
|
|
|
|
|
|
|
|
2021-01-05 14:56:33 +00:00
|
|
|
def test_buildenviron_osx(tmp_path):
|
2018-05-23 23:06:05 +00:00
|
|
|
be = cibuild.BuildEnviron(
|
2018-06-02 19:37:44 +00:00
|
|
|
system="Darwin",
|
2021-01-05 14:56:33 +00:00
|
|
|
root_dir=root,
|
|
|
|
tag="v0.0.1",
|
2018-05-23 23:06:05 +00:00
|
|
|
)
|
|
|
|
assert be.platform_tag == "osx"
|
2021-01-05 14:56:33 +00:00
|
|
|
assert be.archive_path == be.dist_dir / "mitmproxy-0.0.1-osx.tar.gz"
|
2018-05-23 23:06:05 +00:00
|
|
|
|
2021-01-05 14:56:33 +00:00
|
|
|
with be.archive(tmp_path / "arch"):
|
|
|
|
pass
|
|
|
|
assert (tmp_path / "arch").exists()
|
2018-05-23 23:06:05 +00:00
|
|
|
|
2018-05-24 05:10:50 +00:00
|
|
|
|
2021-01-05 14:56:33 +00:00
|
|
|
def test_buildenviron_windows(tmp_path):
|
2018-05-23 23:06:05 +00:00
|
|
|
be = cibuild.BuildEnviron(
|
2018-06-02 19:37:44 +00:00
|
|
|
system="Windows",
|
2021-01-05 14:56:33 +00:00
|
|
|
root_dir=root,
|
|
|
|
tag="v0.0.1",
|
2018-05-23 23:06:05 +00:00
|
|
|
)
|
|
|
|
assert be.platform_tag == "windows"
|
2021-01-05 14:56:33 +00:00
|
|
|
assert be.archive_path == be.dist_dir / "mitmproxy-0.0.1-windows.zip"
|
2018-05-24 05:10:50 +00:00
|
|
|
|
2021-01-05 14:56:33 +00:00
|
|
|
with be.archive(tmp_path / "arch"):
|
|
|
|
pass
|
|
|
|
assert (tmp_path / "arch").exists()
|
2018-06-02 19:37:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("version, tag, ok", [
|
|
|
|
("3.0.0.dev", "", True), # regular snapshot
|
2018-06-15 21:41:15 +00:00
|
|
|
("3.0.0.dev", "v3.0.0", False), # forgot to remove ".dev" on bump
|
2018-06-02 19:37:44 +00:00
|
|
|
("3.0.0", "", False), # forgot to re-add ".dev"
|
2018-06-15 21:41:15 +00:00
|
|
|
("3.0.0", "v4.0.0", False), # version mismatch
|
|
|
|
("3.0.0", "v3.0.0", True), # regular release
|
|
|
|
("3.0.0.rc1", "v3.0.0.rc1", False), # non-canonical.
|
|
|
|
("3.0.0.dev", "anyname", True), # tagged test/dev release
|
2018-06-15 22:17:59 +00:00
|
|
|
("3.0.0", "3.0.0", False), # tagged, but without v prefix
|
2018-06-02 19:37:44 +00:00
|
|
|
])
|
|
|
|
def test_buildenviron_check_version(version, tag, ok, tmpdir):
|
|
|
|
tmpdir.mkdir("mitmproxy").join("version.py").write(f'VERSION = "{version}"')
|
|
|
|
|
|
|
|
be = cibuild.BuildEnviron(
|
|
|
|
root_dir=tmpdir,
|
2021-01-05 14:56:33 +00:00
|
|
|
system="Windows",
|
|
|
|
tag=tag,
|
2018-06-02 19:37:44 +00:00
|
|
|
)
|
|
|
|
if ok:
|
|
|
|
be.check_version()
|
|
|
|
else:
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
be.check_version()
|
2019-11-19 17:15:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_bool_from_env(monkeypatch):
|
|
|
|
monkeypatch.setenv("FOO", "1")
|
|
|
|
assert cibuild.bool_from_env("FOO")
|
|
|
|
|
|
|
|
monkeypatch.setenv("FOO", "0")
|
|
|
|
assert not cibuild.bool_from_env("FOO")
|
|
|
|
|
|
|
|
monkeypatch.setenv("FOO", "false")
|
|
|
|
assert not cibuild.bool_from_env("FOO")
|
|
|
|
|
|
|
|
monkeypatch.setenv("FOO", "")
|
|
|
|
assert not cibuild.bool_from_env("FOO")
|
|
|
|
|
|
|
|
monkeypatch.delenv("FOO")
|
|
|
|
assert not cibuild.bool_from_env("FOO")
|