Exemplo n.º 1
0
def upload_asset(release: GitRelease,
                 path: _PathLike,
                 replace: bool = False,
                 text: bool = False,
                 content: bytes = None) -> None:
    path = Path(path)
    basename = os.path.basename(str(path))
    asset_name = get_gh_asset_name(basename, text)
    asset_label = basename

    for asset in get_release_assets(release, include_incomplete=True):
        if asset_name == asset.name:
            # We want to tread incomplete assets as if they weren't there
            # so replace them always
            if replace or not asset_is_complete(asset):
                asset.delete_asset()
            else:
                print(
                    f"Skipping upload for {asset_name} as {asset_label}, already exists"
                )
                return

    if content is None:
        release.upload_asset(str(path), label=asset_label, name=asset_name)
    else:
        with io.BytesIO(content) as fileobj:
            release.upload_asset_from_memory(  # type: ignore
                fileobj,
                len(content),
                label=asset_label,
                name=asset_name)
    print(f"Uploaded {asset_name} as {asset_label}")
Exemplo n.º 2
0
def upload_asset(release: GitRelease,
                 path: _PathLike,
                 replace: bool = False) -> None:
    # type_: msys/mingw/failed
    if not environ.get("CI"):
        print("WARNING: upload skipped, not running in CI")
        return
    path = Path(path)

    basename = os.path.basename(str(path))
    asset_name = get_gh_asset_name(basename)
    asset_label = basename

    for asset in get_release_assets(release, include_incomplete=True):
        if asset_name == asset.name:
            # We want to tread incomplete assets as if they weren't there
            # so replace them always
            if replace or not asset_is_complete(asset):
                asset.delete_asset()
            else:
                print(
                    f"Skipping upload for {asset_name} as {asset_label}, already exists"
                )
                return

    release.upload_asset(str(path), label=asset_label, name=asset_name)
    print(f"Uploaded {asset_name} as {asset_label}")
Exemplo n.º 3
0
def add_binaries_to_github_release(github_release: GitRelease) -> None:
    """
    Add binaries to a GitHub release.
    """
    # We need to make the artifacts just after creating a tag so that the
    # --version output is exactly the one of the tag.
    # We fetch the latest tags, including the one which was just created.
    for args in (
        ['git', 'fetch', '--tags'],
        ['git', 'merge', 'origin/master'],
        ['git', 'status'],
    ):
        subprocess.run(args=args, check=True)

    linux_artifacts = make_linux_binaries(repo_root=Path('.'))
    for installer_path in linux_artifacts:
        github_release.upload_asset(
            path=str(installer_path),
            label=installer_path.name + '-linux',
        )
        # Remove the installer so that it is not later uploaded by twine.
        installer_path.unlink()