Skip to content

release_setup

new_changelog(changelog_contents, owner, repo, new_ver, first_sha)

Modify the contents of a CHANGELOG.

It adds a new entry with the new version the new changelog contents.

Parameters:

Name Type Description Default
changelog_contents str

The current contents of the CHANGELOG file.

required
owner str

The repo owner.

required
repo str

The repo name.

required
new_ver str

The new version.

required
first_sha str

The very first commit sha of the repo.

required

Returns:

Type Description
Res[str]

The new contents of the CHANGELOG.

Source code in m/ci/release_setup.py
def new_changelog(
    changelog_contents: str,
    owner: str,
    repo: str,
    new_ver: str,
    first_sha: str,
) -> Res[str]:
    """Modify the contents of a CHANGELOG.

    It adds a new entry with the new version the new changelog contents.

    Args:
        changelog_contents: The current contents of the CHANGELOG file.
        owner: The repo owner.
        repo: The repo name.
        new_ver: The new version.
        first_sha: The very first commit sha of the repo.

    Returns:
        The new contents of the CHANGELOG.
    """
    parts = changelog_contents.split('## [Unreleased]')
    if len(parts) != 2:
        return issue('missing "Unreleased" link')

    header, main = parts
    entries = main.split('[unreleased]:')[0]
    versions = _get_versions(entries.split('\n'), new_ver, first_sha)

    compare_url = compare_sha_url(owner, repo, new_ver, 'HEAD')
    links = [f'[unreleased]: {compare_url}']
    for i in range(len(versions) - 1):
        link = compare_sha_url(owner, repo, versions[i + 1], versions[i])
        links.append(f'[{versions[i]}]: {link}')

    date = datetime.now().strftime('%B %d, %Y')
    ver_anchor = _version_anchor(new_ver)
    return Good(''.join([
        header,
        '## [Unreleased]\n\n',
        f'## [{new_ver}] {ver_anchor} {date}\n\n',
        entries,
        '\n'.join(links),
        '\n',
    ]))

release_setup(m_dir, config_inst, new_ver, changelog='CHANGELOG.md')

Modify all the necessary files to create a release.

These include: CHANGELOG.md and the m configuration file.

Parameters:

Name Type Description Default
m_dir str

The directory with the m configuration.

required
config_inst Config | None

If provided it skips reading the configuration.

required
new_ver str

The new version to write in the m configuration.

required
changelog str

The name of the changelog file (defaults to CHANGELOG.md)

'CHANGELOG.md'

Returns:

Type Description
Res[None]

None if successful, otherwise an issue.

Source code in m/ci/release_setup.py
def release_setup(
    m_dir: str,
    config_inst: Config | None,
    new_ver: str,
    changelog: str = 'CHANGELOG.md',
) -> Res[None]:
    """Modify all the necessary files to create a release.

    These include: CHANGELOG.md and the m configuration file.

    Args:
        m_dir: The directory with the m configuration.
        config_inst: If provided it skips reading the configuration.
        new_ver: The new version to write in the m configuration.
        changelog: The name of the changelog file (defaults to CHANGELOG.md)

    Returns:
        None if successful, otherwise an issue.
    """
    return one_of(lambda: [
        None
        for config in _read_config(m_dir, config_inst)
        for first_sha in get_first_commit_sha()
        for _ in update_version(m_dir, new_ver)
        for _ in update_changelog_file(
            config.owner,
            config.repo,
            new_ver,
            first_sha,
            changelog,
        )
        for _ in _success_release_setup(config, new_ver)
    ])

update_changelog_file(owner, repo, new_ver, first_sha, filename='CHANGELOG.md')

Add the new version entry to be released to the CHANGELOG.

Parameters:

Name Type Description Default
owner str

The repo owner.

required
repo str

The repo name.

required
new_ver str

The version that is being released.

required
first_sha str

The first sha ever committed on the repo.

required
filename str

Specify the CHANGELOG file (defaults to CHANGELOG.md)

'CHANGELOG.md'

Returns:

Type Description
Res[int]

0 if successful, an issue otherwise.

Source code in m/ci/release_setup.py
def update_changelog_file(
    owner: str,
    repo: str,
    new_ver: str,
    first_sha: str,
    filename: str = 'CHANGELOG.md',
) -> Res[int]:
    """Add the new version entry to be released to the CHANGELOG.

    Args:
        owner: The repo owner.
        repo: The repo name.
        new_ver: The version that is being released.
        first_sha: The first sha ever committed on the repo.
        filename: Specify the CHANGELOG file (defaults to CHANGELOG.md)

    Returns:
        0 if successful, an issue otherwise.
    """
    return one_of(lambda: [
        0
        for text in rw.read_file(filename)
        for new_data in new_changelog(text, owner, repo, new_ver, first_sha)
        for _ in rw.write_file(filename, new_data)
        for _ in logger.info(f'updated {filename}')
    ])

update_version(root, version)

Update the version property in m configuration file.

Parameters:

Name Type Description Default
root str

The directory with the m configuration file.

required
version str

The new version to write in the m configuration.

required

Returns:

Type Description
Res[int]

0 if successful or an issue.

Source code in m/ci/release_setup.py
def update_version(
    root: str,
    version: str,
) -> Res[int]:
    """Update the version property in m configuration file.

    Args:
        root: The directory with the m configuration file.
        version: The new version to write in the m configuration.

    Returns:
        0 if successful or an issue.
    """
    return one_of(lambda: [
        0
        for filename in get_m_filename(root)
        for config_contents in rw.read_file(filename)
        for new_data in _update_config_version(config_contents, version)
        for _ in rw.write_file(filename, new_data)
        for _ in logger.info(f'bumped version in {filename}')
    ])