diff --git a/.circleci/config.yml b/.circleci/config.yml index 79d895ce..2fcbde38 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,6 +3,7 @@ version: 2.1 orbs: slack: circleci/slack@4.4.2 + gh: circleci/github-cli@2.1.0 jobs: build_test: @@ -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: diff --git a/scripts/print_version_changelog.py b/scripts/print_version_changelog.py new file mode 100644 index 00000000..4e090675 --- /dev/null +++ b/scripts/print_version_changelog.py @@ -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()