Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Obsolete] Automatically publish release #346

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
version: 2.1
orbs:
slack: circleci/[email protected]
gh: circleci/[email protected]

jobs:
build_test:
Expand Down Expand Up @@ -90,14 +91,24 @@ jobs:
name: Build
command: | # install env dependencies
poetry build
- run:
name: Publish to PyPI
# Output changelog
PKG_VERSION=$(sed -n 's/^version = //p' pyproject.toml | sed -e 's/^"//' -e 's/"$//')
poetry run python scripts/print_version_changelog.py > ./version_changelog.md
# - run:
# name: Publish to PyPI
# command: |
# if test -z "${PYPI_USERNAME}" || test -z "${PYPI_PASSWORD}" ; then
# echo "ERROR: Please assign PYPI_USERNAME and PYPI_PASSWORD as environment variables"
# exit 1
# fi
# poetry publish --username=$PYPI_USERNAME --password=$PYPI_PASSWORD
- gh/release:
name: Publish Github Release
command: |
if test -z "${PYPI_USERNAME}" || test -z "${PYPI_PASSWORD}" ; then
echo "ERROR: Please assign PYPI_USERNAME and PYPI_PASSWORD as environment variables"
exit 1
fi
poetry publish --username=$PYPI_USERNAME --password=$PYPI_PASSWORD
echo $GITHUB_WRITE_TOKEN | gh auth login --with-token
gh release create v$PKG_VERSION dist/* -F ./version_changelog.md


workflows:
nightly_build_test:
triggers:
Expand Down
48 changes: 48 additions & 0 deletions scripts/print_version_changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os.path

import click


def is_release_head(line):
if line.startswith("## ["):
return True
else:
return False


def check_if_start_of_line_factory(version):
if version is None:
return lambda line: is_release_head(line)
else:
return lambda line: is_release_head(line) and version in line


@click.command("find-version")
@click.option(
"--version", help="Target version to output, if none, the topmost"
)
@click.option(
"--changelog-path",
default="./CHANGELOG.md",
help="Path to changelog, defaults to ./CHANGELOG.md (works if you run it from root of repo)",
)
def find_version_changelog(version, changelog_path):
target_changes = []
in_version = False
is_start_of_version = check_if_start_of_line_factory(version)
with open(os.path.expanduser(changelog_path), "r") as ch_file:
content = ch_file.read()
for line in content.splitlines():
if is_release_head(line) and in_version:
break
elif is_start_of_version(line):
in_version = True
if in_version:
target_changes.append(line)

changes = "\n".join(target_changes)
click.echo(changes)


if __name__ == "__main__":
find_version_changelog()