From 786bc8cb5803120c2feaa1b5d1a115a3a54e2c76 Mon Sep 17 00:00:00 2001 From: Gunnar Atli Thoroddsen Date: Thu, 21 Apr 2022 14:29:25 +0200 Subject: [PATCH 1/3] Create script to output target changelog --- .circleci/config.yml | 4 +++ scripts/print_version_changelog.py | 48 ++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 scripts/print_version_changelog.py diff --git a/.circleci/config.yml b/.circleci/config.yml index 79d895ce..a7f5e088 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -98,6 +98,10 @@ jobs: exit 1 fi poetry publish --username=$PYPI_USERNAME --password=$PYPI_PASSWORD + - run: + name: Publish Github Release + command: | + 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() From 39d1a471c22032f7d1870296908ccbd8156218f3 Mon Sep 17 00:00:00 2001 From: Gunnar Atli Thoroddsen Date: Thu, 21 Apr 2022 14:53:01 +0200 Subject: [PATCH 2/3] Need to auth and push release with gh CLI --- .circleci/config.yml | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a7f5e088..c0be95b2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -90,17 +90,23 @@ jobs: name: Build command: | # install env dependencies poetry build - - 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 +# - 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 - run: name: Publish Github Release command: | + poetry install + 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 + echo $GH_TOKEN | gh auth login --with-token + gh release create v$PKG_VERSION dist/* -F ./version_changelog.md + workflows: nightly_build_test: From 4defb66b4b67814914a7b63783d172bc0fb74672 Mon Sep 17 00:00:00 2001 From: Gunnar Atli Thoroddsen Date: Thu, 21 Apr 2022 15:40:07 +0200 Subject: [PATCH 3/3] WIP --- .circleci/config.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c0be95b2..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,6 +91,9 @@ jobs: name: Build command: | # install env dependencies poetry build + # 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: | @@ -98,13 +102,10 @@ jobs: # exit 1 # fi # poetry publish --username=$PYPI_USERNAME --password=$PYPI_PASSWORD - - run: + - gh/release: name: Publish Github Release command: | - poetry install - 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 - echo $GH_TOKEN | gh auth login --with-token + echo $GITHUB_WRITE_TOKEN | gh auth login --with-token gh release create v$PKG_VERSION dist/* -F ./version_changelog.md