callowayproject / bump-my-version

A small command line tool to simplify releasing software by updating all version strings in your source code by the correct increment and optionally commit and tag the changes.
https://callowayproject.github.io/bump-my-version/
MIT License
305 stars 19 forks source link

Can't show version as json anymore #222

Closed skymoore closed 1 month ago

skymoore commented 1 month ago

Description

I have a workflow that uses bump-my-version output to check for existing versions based on tags. Here is the workflow:

name: Check for existing version
run-name: Check for existing version

on:
  pull_request:
    branches:
      - main

jobs:
  versioning-check:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write
      packages: read

    steps:
      # Check out your repository
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      # Set up Python environment
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.12"

      # Install BMV
      - name: Install Bump My Version
        run: pip3 install bump-my-version==0.24.2

      # Check for existing version of package
      - name: Check for existing package version
        run: |
          PACKAGE_VERSION=$(bump-my-version show --format json | jq -r '.current_version')
          echo "version: $PACKAGE_VERSION"
          TAGS=$(git --no-pager tag --list)
          echo "tags: $TAGS"
          if echo "$TAGS" | grep -q "v$PACKAGE_VERSION"; then
            PR_COMMENT="Version $PACKAGE_VERSION already exists. Please bump the version according to semantic versioning."
            PR_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
            curl -X POST \
              -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
              -H "Accept: application/vnd.github+json" \
              "https://api.github.com/repos/${{ github.repository }}/issues/$PR_NUMBER/comments" \
              -d "{\"body\": \"$PR_COMMENT\"}" \
              -o /dev/null

            echo "Version v${PACKAGE_VERSION} already exists."
            exit 1
          else
            echo "Version v${PACKAGE_VERSION} does not exist." 
            exit 0
          fi

This works in 0.24.2 but now fails on 0.25.1. Here is the error output:

PACKAGE_VERSION=$(bump-my-version show --format json | jq -r '.current_version')
  Specified version (0.3.0) does not match last tagged version (0.2.1)
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.12.4/x64/bin/bump-my-version", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/site-packages/rich_click/rich_command.py", line 367, in __call__
    return super().__call__(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/site-packages/rich_click/rich_command.py", line 152, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/site-packages/bumpversion/cli.py", line 358, in show
    do_show("all", config=config, format_=format_, increment=increment)
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/site-packages/bumpversion/show.py", line 129, in do_show
    OUTPUTTERS.get(format_, OUTPUTTERS["default"])(show_items)
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/site-packages/bumpversion/show.py", line 44, in output_json
    print_info(json.dumps(value, sort_keys=True, indent=2, default=default_encoder))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
          ^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/json/encoder.py", line 202, in encode
    chunks = list(chunks)
             ^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/json/encoder.py", line 432, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/json/encoder.py", line 406, in _iterencode_dict
    yield from chunks
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/json/encoder.py", line 406, in _iterencode_dict
    yield from chunks
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/json/encoder.py", line 439, in _iterencode
    o = _default(o)
        ^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/site-packages/bumpversion/show.py", line 42, in default_encoder
    raise TypeError(f"Object of type {type(obj), str(obj)} is not JSON serializable")
TypeError: Object of type (<class 'pathlib.PosixPath'>, '/home/runner/work/my-repo/my-repo') is not JSON serializable
coordt commented 1 month ago

@skymoore Thank you for such a detailed report. SIGH I need to rework my tests so these things don't fall through.

I should be able to get it done today.

coordt commented 1 month ago

@skymoore Two things: