From 2367a77e2f391c024f6e6525f813e0f6263d1ce1 Mon Sep 17 00:00:00 2001 From: Yuta Kasai Date: Thu, 21 Nov 2024 11:45:11 +0900 Subject: [PATCH 1/7] NO-ISSUE Stop using __LINE_BOT_SDK_PYTHON_VERSION__ --- .github/workflows/auto-testing.yml | 19 ++++++------------- .github/workflows/publish-to-pypi.yml | 2 +- linebot/__about__.py | 2 +- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/.github/workflows/auto-testing.yml b/.github/workflows/auto-testing.yml index 3951df9ef..8ba0bafe7 100644 --- a/.github/workflows/auto-testing.yml +++ b/.github/workflows/auto-testing.yml @@ -33,12 +33,6 @@ jobs: - name: Ensure generate-code.py doesn't throw any error run: | python generate-code.py - - name: Update version in linebot/__about__.py - run: | - VERSION="12.3.0" - VERSION=${VERSION#v} - sed -i "s/__version__ = '__LINE_BOT_SDK_PYTHON_VERSION__'/__version__ = '$VERSION'/g" linebot/__about__.py - cat linebot/__about__.py - name: Test with pytest run: | tox @@ -47,6 +41,12 @@ jobs: pip install readme-renderer python -m readme_renderer README.rst >/dev/null + - name: Update version in linebot/__about__.py + run: | + VERSION="123.456.789" + sed -i "s/__version__ = '.*'/__version__ = '$VERSION'/g" linebot/__about__.py + cat linebot/__about__.py + check-import: runs-on: ubuntu-latest strategy: @@ -64,13 +64,6 @@ jobs: uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - - name: Update version in linebot/__about__.py - run: | - VERSION="12.3.0" - VERSION=${VERSION#v} - sed -i "s/__version__ = '__LINE_BOT_SDK_PYTHON_VERSION__'/__version__ = '$VERSION'/g" linebot/__about__.py - cat linebot/__about__.py - - name: Install dependencies & lib run: | python -m pip install --upgrade pip diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index b29e353f2..b24f2a541 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -28,7 +28,7 @@ jobs: run: | VERSION=${{ github.event.release.tag_name }} VERSION=${VERSION#v} - sed -i "s/__version__ = '__LINE_BOT_SDK_PYTHON_VERSION__'/__version__ = '$VERSION'/g" linebot/__about__.py + sed -i "s/__version__ = '.*'/__version__ = '$VERSION'/g" linebot/__about__.py cat linebot/__about__.py - name: Build and publish env: diff --git a/linebot/__about__.py b/linebot/__about__.py index dbce609c0..5b9cd1e09 100644 --- a/linebot/__about__.py +++ b/linebot/__about__.py @@ -15,7 +15,7 @@ """Meta data of line-bot-sdk.""" -__version__ = '__LINE_BOT_SDK_PYTHON_VERSION__' +__version__ = '1.0.0-test' __author__ = 'LINE Corporation' __copyright__ = 'Copyright 2016, LINE Corporation' __license__ = 'Apache 2.0' From eae415fb67dc2a7de36e3546022c48f1dfe27fe2 Mon Sep 17 00:00:00 2001 From: Yuta Kasai Date: Thu, 21 Nov 2024 11:48:00 +0900 Subject: [PATCH 2/7] NO-ISSUE Fix --- linebot/__about__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linebot/__about__.py b/linebot/__about__.py index 5b9cd1e09..b8ea48d3a 100644 --- a/linebot/__about__.py +++ b/linebot/__about__.py @@ -15,7 +15,7 @@ """Meta data of line-bot-sdk.""" -__version__ = '1.0.0-test' +__version__ = '1.0.0a1' __author__ = 'LINE Corporation' __copyright__ = 'Copyright 2016, LINE Corporation' __license__ = 'Apache 2.0' From f4ebfe5365c32fc060fe5f156bb9ec6dd3f929c1 Mon Sep 17 00:00:00 2001 From: Yuta Kasai Date: Thu, 21 Nov 2024 12:27:04 +0900 Subject: [PATCH 3/7] Add script to update and verify version --- .github/workflows/auto-testing.yml | 3 +- .github/workflows/publish-to-pypi.yml | 15 ++++-- tools/update_version.py | 66 +++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 5 deletions(-) create mode 100755 tools/update_version.py diff --git a/.github/workflows/auto-testing.yml b/.github/workflows/auto-testing.yml index 8ba0bafe7..35c374ece 100644 --- a/.github/workflows/auto-testing.yml +++ b/.github/workflows/auto-testing.yml @@ -44,8 +44,7 @@ jobs: - name: Update version in linebot/__about__.py run: | VERSION="123.456.789" - sed -i "s/__version__ = '.*'/__version__ = '$VERSION'/g" linebot/__about__.py - cat linebot/__about__.py + python tools/update_version.py $VERSION check-import: runs-on: ubuntu-latest diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index b24f2a541..8b2c35bab 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -6,6 +6,11 @@ name: Upload Python Package on: release: types: [published] + workflow_dispatch: + inputs: + version: + description: 'The version to release' + required: true jobs: deploy: @@ -26,10 +31,14 @@ jobs: pip install setuptools wheel twine - name: Update version in linebot/__about__.py run: | - VERSION=${{ github.event.release.tag_name }} + if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then + VERSION=${{ github.event.inputs.version }} + else + VERSION=${{ github.event.release.tag_name }} + fi + VERSION=${VERSION#v} - sed -i "s/__version__ = '.*'/__version__ = '$VERSION'/g" linebot/__about__.py - cat linebot/__about__.py + python tools/update_and_verify_version.py $VERSION - name: Build and publish env: TWINE_USERNAME: ${{ secrets.PYPI_API_USER }} diff --git a/tools/update_version.py b/tools/update_version.py new file mode 100755 index 000000000..db3fe0f42 --- /dev/null +++ b/tools/update_version.py @@ -0,0 +1,66 @@ +import sys +import re +import subprocess + +def update_and_verify_version(new_version): + file_path = 'linebot/__about__.py' + + # Update version + with open(file_path, 'r') as file: + content = file.read() + + new_content = re.sub( + r"__version__ = '.*?'", + f"__version__ = '{new_version}'", + content + ) + + with open(file_path, 'w') as file: + file.write(new_content) + + print(f"Updated version to {new_version} in {file_path}") + + # verify version + match = re.search(r"__version__ = '(.*?)'", new_content) + if not match: + raise ValueError("Version string not found in the file.") + + actual_version = match.group(1) + if actual_version != new_version: + raise ValueError(f"Version mismatch: expected {new_version}, found {actual_version}") + + print(f"Version verified: {actual_version}") + + # diff check just in case + try: + result = subprocess.run(['git', 'diff', '--numstat', file_path], capture_output=True, text=True, check=True) + changed_lines = result.stdout.strip().split('\n') + added_lines = 0 + deleted_lines = 0 + + for line in changed_lines: + added, deleted = map(int, line.split('\t')[:2]) + added_lines += added + deleted_lines += deleted + + if added_lines != 1 or deleted_lines != 1: + raise ValueError(f"Unexpected number of changed lines: expected 1 added and 1 deleted, found {added_lines} added and {deleted_lines} deleted") + + print('Git diff verification passed: 1 line added and 1 line deleted.') + + except subprocess.CalledProcessError as e: + print(f"Error during git diff verification: {e}") + sys.exit(1) + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("Usage: python update_and_verify_version.py ") + sys.exit(1) + + new_version = sys.argv[1] + + try: + update_and_verify_version(new_version) + except ValueError as e: + print(e) + sys.exit(1) From 5eb82cd4d3dd2b6583ae66f833b17c4a91fe7579 Mon Sep 17 00:00:00 2001 From: Yuta Kasai Date: Thu, 21 Nov 2024 12:32:38 +0900 Subject: [PATCH 4/7] Add useful output --- tools/update_version.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/update_version.py b/tools/update_version.py index db3fe0f42..c83f9f826 100755 --- a/tools/update_version.py +++ b/tools/update_version.py @@ -48,6 +48,10 @@ def update_and_verify_version(new_version): print('Git diff verification passed: 1 line added and 1 line deleted.') + # Show diff + diff_result = subprocess.run(['git', 'diff', '--color=always', file_path], capture_output=True, text=True, check=True) + print('Git diff output:\n', diff_result.stdout) + except subprocess.CalledProcessError as e: print(f"Error during git diff verification: {e}") sys.exit(1) From eff9517f0c6fd0f6ce5291af458d2c71970a26bc Mon Sep 17 00:00:00 2001 From: Yuta Kasai Date: Thu, 21 Nov 2024 12:39:01 +0900 Subject: [PATCH 5/7] NO-ISSUE Delete test --- .github/workflows/auto-testing.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/auto-testing.yml b/.github/workflows/auto-testing.yml index 35c374ece..59808e6e0 100644 --- a/.github/workflows/auto-testing.yml +++ b/.github/workflows/auto-testing.yml @@ -41,11 +41,6 @@ jobs: pip install readme-renderer python -m readme_renderer README.rst >/dev/null - - name: Update version in linebot/__about__.py - run: | - VERSION="123.456.789" - python tools/update_version.py $VERSION - check-import: runs-on: ubuntu-latest strategy: From e3ca659558f16d0c5d72207a02d4a2eff284f7e5 Mon Sep 17 00:00:00 2001 From: Yuta Kasai Date: Mon, 25 Nov 2024 10:15:32 +0900 Subject: [PATCH 6/7] Update .github/workflows/publish-to-pypi.yml Co-authored-by: Yuta Euchi <63095160+eucyt@users.noreply.github.com> --- .github/workflows/publish-to-pypi.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 8b2c35bab..8c31725f6 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -38,7 +38,7 @@ jobs: fi VERSION=${VERSION#v} - python tools/update_and_verify_version.py $VERSION + python tools/update_version.py $VERSION - name: Build and publish env: TWINE_USERNAME: ${{ secrets.PYPI_API_USER }} From b5607c7610368d04350b6c0e0c8ccf32c954d2f4 Mon Sep 17 00:00:00 2001 From: Yuta Kasai Date: Mon, 25 Nov 2024 10:15:37 +0900 Subject: [PATCH 7/7] Update tools/update_version.py Co-authored-by: Yuta Euchi <63095160+eucyt@users.noreply.github.com> --- tools/update_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/update_version.py b/tools/update_version.py index c83f9f826..ba928ddf7 100755 --- a/tools/update_version.py +++ b/tools/update_version.py @@ -58,7 +58,7 @@ def update_and_verify_version(new_version): if __name__ == "__main__": if len(sys.argv) != 2: - print("Usage: python update_and_verify_version.py ") + print("Usage: python update_version.py ") sys.exit(1) new_version = sys.argv[1]