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

print-version missing in v8 #638

Closed
shooit opened this issue Jul 18, 2023 · 5 comments
Closed

print-version missing in v8 #638

shooit opened this issue Jul 18, 2023 · 5 comments
Assignees
Labels
bug Something isn't working properly

Comments

@shooit
Copy link

shooit commented Jul 18, 2023

The problem

v8.x no longer supports the print-version command or another path to get the current version of the project

Expected behavior

We have been using the print-version command to determine if a release was made in our CI processes. For example,

jobs:
  release:
    runs-on: ubuntu-latest
    concurrency:
      group: release
      cancel-in-progress: false
    steps:
      - id: pre-release
        name: get pre-release version
        run: echo "version=$(poetry run semantic-release print-version --current)" >> $GITHUB_OUTPUT
      - name: release
        run: poetry run semantic-release publish
        env:
          GH_TOKEN: ${{ secrets.GH_TOKEN }}
      - id: post-release
        name: get post-release version
        run: echo "version=$(poetry run semantic-release print-version --current)" >> $GITHUB_OUTPUT
      - if: steps.pre-release.outputs.version != steps.post-release.outputs.version
        run: my-post-release-jobs
@shooit shooit added the bug Something isn't working properly label Jul 18, 2023
@bernardcooke53
Copy link
Contributor

Hey @shooit - have you tried the following:

semantic-release --noop version --print

The --print option is new in v8.
It looks like you're using GitHub Actions and running semantic-release directly to set some outputs up for the workflow - just want to also mention that the GitHub Action now has outputs:

  • released, which looks a lot like your condition steps.pre-release.outputs.version != steps.post-release.outputs.version
  • version, which is what you're setting as output when doing poetry run semantic-release

so you might get some mileage/simplification out of that too.

@bernardcooke53 bernardcooke53 self-assigned this Jul 20, 2023
@shooit
Copy link
Author

shooit commented Jul 24, 2023

@bernardcooke53 thanks for the response

I tried semantic-release --noop version --print but it prints out what the new version would be rather than the exact version specified by my project (for me in pyproject.toml)

For example, my project is at version 2.11.4 and if I run that command on a branch with a feat: commit after the most recent release, the output is 2.12.0

@bernardcooke53
Copy link
Contributor

Ah, I see - there's no --current flag in the latest version. The main driving factor for that being that in v7, the version would be determined from source file and commit+tag history. We don't look at commits or source files to determine versions in v8. So the "current" version should just be whatever's stored in the locations you've configured - you can pull it out of the file directly.

For your use case there's a few useful one-liners with different tools:

toml get pyproject.toml project.version
  • pip + tomli
pip install tomli && python3 -c "import tomli; print(tomli.load(open('pyproject.toml'))['project']['version'])"
  • bash
cat pyproject.toml | grep "version *=" | sed -r 's/^version *= *"(.*)"$/\1/'

Possibly a useful feature would be a new command, list-versions, so that you could do:

semantic-release list-versions -n 1

to get the latest version. What do you think?

@cfxegbert
Copy link
Contributor

Printing the current version is addressed in pull request #852. You can choose to print the last released version number or tag.

@codejedi365
Copy link
Contributor

Released with v9.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working properly
Projects
None yet
Development

No branches or pull requests

4 participants