31 Commits

Author SHA1 Message Date
1f01bda2f4 dogfood own action 2024-08-20 00:28:48 -07:00
629d931979 Don't trample over existing python installs 2024-08-20 00:28:38 -07:00
d2296fb926 name and description 2024-08-19 23:31:42 -07:00
80e35de136 Add github action for getting version info and making releases 2024-08-19 23:30:45 -07:00
d6da31b6ff Release Version 1.3.0
### Added

- added a `--version` option to `yaclog show` that prints just the version number

### Changed

- removed support for Click 7 as a dependency
2024-08-08 00:51:31 -07:00
d4f477a544 Update build dependencies 2024-08-08 00:50:37 -07:00
a392f09a51 drop support for Click 7.0 2024-08-08 00:50:37 -07:00
683ccbf916 Bump actions/setup-python from 5.1.0 to 5.1.1
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 5.1.0 to 5.1.1.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v5.1.0...v5.1.1)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-08-08 00:44:10 -07:00
2a67f6edc7 Infer version number for unreleased versions
increment the patch number. not always whats intended but at least produces something unique
2024-08-08 00:43:16 -07:00
c4be5d2420 add "--version" option to yaclog show 2024-08-08 00:30:18 -07:00
30947769e1 Readthedocs broke their dang config schema? 2024-04-16 00:08:25 -07:00
6589a91d7e Update CI workflow some more 2024-04-16 00:03:35 -07:00
802633b9a7 Update CI workflow 2024-04-16 00:02:09 -07:00
47d4b595f8 Release Version 1.2.0
### Added

- added the `-s` option to `yaclog release` to increment arbitrary version segments 
- added the `-n` option to `yaclog release` to create a new release instead of releasing a new one
- added the `-y` option to `yaclog release` to answer "yes" to all confirmation dialogs. Use with caution!
2024-04-15 23:49:30 -07:00
fdf30bc14c also make -y apply to git commit confirmations 2024-04-15 23:49:14 -07:00
72126c8dca Add -s, -n, and -y options to release 2024-04-15 23:45:24 -07:00
0666f7f593 Release Version 1.1.2
### Changed

- yaclog now only tries to use git when invoked with a command that needs it, meaning most sub commands can now be used on systems without git
2022-12-29 00:34:58 -08:00
51e28e4ef0 cleanup 2022-12-29 00:34:27 -08:00
a7cbacb687 Update changelog 2022-12-28 20:49:58 -08:00
3fa529a05c Bump actions/setup-python from 4.3.1 to 4.4.0
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.3.1 to 4.4.0.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v4.3.1...v4.4.0)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-12-27 20:26:05 -08:00
396960fae0 Only import toml and gitpython when necessary
Allows for using most commands on platforms without git installed (like the a-shell app on ios where gitpython doesnt quite work)
2022-12-27 20:21:18 -08:00
c661be05dc Bump actions/setup-python from 4.2.0 to 4.3.1
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.2.0 to 4.3.1.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v4.2.0...v4.3.1)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-12-12 23:34:48 -08:00
2f4124c0fc Test with python 3.11 2022-12-12 23:33:48 -08:00
465b818ca2 Release Version 1.1.1
### Fixed

- Fixed `yaclog release -C -c` not committing changes to cargo.toml
2022-08-14 17:39:12 -07:00
32f20e677e Release Version 1.1.0
### Added

- Added a flag to update Rust Cargo.toml files when releasing a new version
2022-08-13 20:03:24 -07:00
8421d38164 Add cargo.toml support
Added a flag to update Rust Cargo.toml files when releasing a new version
2022-08-13 20:02:45 -07:00
c5030b6060 Bump actions/setup-python from 4.0.0 to 4.2.0
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.0.0 to 4.2.0.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v4.0.0...v4.2.0)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-08-04 23:57:53 -07:00
4ce3de25c7 Bump actions/setup-python from 3.1.2 to 4.0.0
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 3.1.2 to 4.0.0.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v3.1.2...v4.0.0)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-09 23:15:47 -07:00
6bc99c585b Merge pull request #3 from drewcassidy/dependabot/github_actions/actions/setup-python-3.1.2
Bump actions/setup-python from 3.1.1 to 3.1.2
2022-04-12 18:24:29 -07:00
32abd7bc6b Bump actions/setup-python from 3.1.1 to 3.1.2
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 3.1.1 to 3.1.2.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v3.1.1...v3.1.2)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-12 11:18:19 +00:00
06df766f9f Remove license metadata (troves are fine)
oops: https://cybre.space/@cinebox/108095181597001366
2022-04-08 00:13:06 -07:00
8 changed files with 284 additions and 40 deletions

View File

@ -9,14 +9,14 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
python-version: [ "3.8", "3.9", "3.10" ] python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
click-version: [ "click~=7.0", "click~=8.0" ] click-version: [ "click~=8.0" ]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }} - name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3.1.1 uses: actions/setup-python@v5.1.1
with: with:
python-version: ${{ matrix.python-version }} python-version: ${{ matrix.python-version }}
@ -40,23 +40,22 @@ jobs:
run: python -m unittest -v run: python -m unittest -v
deploy: deploy:
needs: test # needs: test
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') # if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- name: Set up Python - name: Set up Python
uses: actions/setup-python@v3.1.1 uses: actions/setup-python@v5.1.1
with: with:
python-version: '3.x' python-version: '>=3.8'
- name: Install dependencies - name: Install dependencies
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
python -m pip install setuptools wheel twine python -m pip install setuptools wheel twine
python -m pip install . # Self hosting!
- name: Install pypa/build - name: Install pypa/build
run: python -m pip install build --user run: python -m pip install build --user
@ -64,10 +63,9 @@ jobs:
- name: Build a binary wheel and source tarball - name: Build a binary wheel and source tarball
run: python -m build --sdist --wheel --outdir dist/ run: python -m build --sdist --wheel --outdir dist/
- name: Get version name and body - name: Get version info
run: | id: yaclog-show
echo "VERSION_TILE=$(yaclog show -n)" >> $GITHUB_ENV uses: ./
echo "$(yaclog show -mb)" >> RELEASE.md
- name: Publish to PyPI - name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1 uses: pypa/gh-action-pypi-publish@release/v1
@ -75,10 +73,10 @@ jobs:
password: ${{ secrets.PYPI_API_TOKEN }} password: ${{ secrets.PYPI_API_TOKEN }}
- name: Publish to Github - name: Publish to Github
uses: softprops/action-gh-release@v1 uses: softprops/action-gh-release@v2
with: with:
files: dist/* files: dist/*
name: ${{ env.VERSION_TITLE }} name: ${{ steps.yaclog-show.outputs.name }}
body_path: RELEASE.md body_path: ${{ steps.yaclog-show.outputs.body_file }}
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -5,6 +5,12 @@
# Required # Required
version: 2 version: 2
# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.12"
# Build documentation in the docs/ directory with Sphinx # Build documentation in the docs/ directory with Sphinx
sphinx: sphinx:
configuration: docs/conf.py configuration: docs/conf.py
@ -16,7 +22,6 @@ formats:
# Optionally set the version of Python and requirements required to build your docs # Optionally set the version of Python and requirements required to build your docs
python: python:
version: 3.8
install: install:
- method: pip - method: pip
path: . path: .

View File

@ -2,6 +2,47 @@
All notable changes to this project will be documented in this file All notable changes to this project will be documented in this file
## Version 1.3.0 - 2024-08-08
### Added
- added a `--version` option to `yaclog show` that prints just the version number
### Changed
- removed support for Click 7 as a dependency
## Version 1.2.0 - 2024-04-16
### Added
- added the `-s` option to `yaclog release` to increment arbitrary version segments
- added the `-n` option to `yaclog release` to create a new release instead of releasing a new one
- added the `-y` option to `yaclog release` to answer "yes" to all confirmation dialogs. Use with caution!
## Version 1.1.2 - 2022-12-29
### Changed
- yaclog now only tries to use git when invoked with a command that needs it, meaning most sub commands can now be used on systems without git
## Version 1.1.1 - 2022-08-15
### Fixed
- Fixed `yaclog release -C -c` not committing changes to cargo.toml
## Version 1.1.0 - 2022-08-14
### Added
- Added a flag to update Rust Cargo.toml files when releasing a new version
## Version 1.0.4 - 2022-04-08 ## Version 1.0.4 - 2022-04-08
### Fixed ### Fixed

87
action.yaml Normal file
View File

@ -0,0 +1,87 @@
name: 'Yaclog'
description: 'Get version information from a changelog, and optionally create a new release'
branding:
icon: file-text
color: blue
inputs:
markdown:
description: If outputs should be in markdown format or not
default: 'true'
release:
description: >
Creates a new release and commits it if set. Directly passed to the arguments of `yaclog release`.
Can be a version number or an increment tag like `--major`, `--minor`, or `--patch`.
The resulting commit and tag will be pushed back to the repo, but the workflow must have write permissions.
Add
```yaml
permissions:
contents: write
```
to your workflow to allow this.
outputs:
name:
description: "The current version name. For example, `Version 1.3.0`"
value: ${{ steps.yaclog-show.outputs.name}}
header:
description: "The entire header for the current version. For example, `Version 1.3.0 - 2024-08-08`"
value: ${{ steps.yaclog-show.outputs.header }}
version:
description: "The current version number. For example, `1.3.0`"
value: ${{ steps.yaclog-show.outputs.version }}
body_file:
description: "Path to a temporary file containing the version body"
value: ${{ steps.yaclog-show.outputs.body_file }}
changelog:
description: "Path to the entire changelog file."
value: ${{ steps.yaclog-show.outputs.changelog }}
runs:
using: "composite"
steps:
- id: setup-python
uses: actions/setup-python@v5
with:
python-version: '3.10'
update-environment: 'false'
- name: Setup Yaclog
shell: bash
run: |
${{ steps.setup-python.outputs.python-path }} -m pip install ${{ github.action_path }}
# now make it available in $PATH
# this whole rigamarole is because we are using a python root that isnt in $PATH as to not step over other actions
mkdir -p "$GITHUB_ACTION_PATH/bin"
echo '${{ steps.setup-python.outputs.python-path }} -m yaclog.cli $@' > "$GITHUB_ACTION_PATH/bin/yaclog"
chmod +x "$GITHUB_ACTION_PATH/bin/yaclog"
echo "$GITHUB_ACTION_PATH/bin" > "$GITHUB_PATH"
- name: Create New Release
shell: bash
if: ${{ inputs.release }}
run: yaclog release --yes --commit ${{ inputs.release }}
- name: Get Version Information
id: yaclog-show
shell: bash
run: |
yaclog show ---gh-actions ${{ inputs.markdown && '--markdown' }} >> "$GITHUB_OUTPUT"
# output like so:
# name=Version 1.3.0
# header=Version 1.3.0 - 2024-08-08
# version=1.3.0
# body_file={path to file containing version body}
# changelog={path to changelog}
- name: Push Changes
if: ${{ inputs.release }}
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
git config --global user.name "github-actions"
git config --global user.email "github-actions@github.com"
git push
git push --tags

View File

@ -1,7 +1,7 @@
[build-system] [build-system]
requires = [ requires = [
"setuptools>=61", "setuptools>=64",
"setuptools_scm>=6.2", "setuptools_scm>=8",
"wheel" "wheel"
] ]
build-backend = "setuptools.build_meta" build-backend = "setuptools.build_meta"
@ -10,7 +10,6 @@ build-backend = "setuptools.build_meta"
name = "yaclog" name = "yaclog"
description = "Yet another changelog CLI tool." description = "Yet another changelog CLI tool."
readme = "README.md" readme = "README.md"
license = { file = "LICENSE.md" }
authors = [{ name = "Andrew Cassidy", email = "drewcassidy@me.com" }] authors = [{ name = "Andrew Cassidy", email = "drewcassidy@me.com" }]
keywords = ["changelog", "commandline", "markdown"] keywords = ["changelog", "commandline", "markdown"]
classifiers = [ classifiers = [
@ -30,9 +29,11 @@ classifiers = [
requires-python = ">= 3.8" requires-python = ">= 3.8"
dependencies = [ dependencies = [
"Click >= 7.0", "Click >= 8.0",
"GitPython >= 3", "GitPython >= 3",
"packaging >= 20" "packaging >= 20",
"tomlkit >= 0.11"
] ]
dynamic = ["version"] dynamic = ["version"]

View File

@ -153,6 +153,11 @@ class TestRelease(unittest.TestCase):
self.assertEqual(yaclog.read(location).versions[0].name, '1.0.1') self.assertEqual(yaclog.read(location).versions[0].name, '1.0.1')
self.assertIn('1.0.1', result.output) self.assertIn('1.0.1', result.output)
result = runner.invoke(cli, ['release', '-y', '-s', 2])
check_result(self, result)
self.assertEqual(yaclog.read(location).versions[0].name, '1.0.2')
self.assertIn('1.0.2', result.output)
runner.invoke(cli, ['entry', '-b', 'entry number 3']) runner.invoke(cli, ['entry', '-b', 'entry number 3'])
result = runner.invoke(cli, ['release', '-m']) result = runner.invoke(cli, ['release', '-m'])
@ -194,6 +199,12 @@ class TestRelease(unittest.TestCase):
self.assertEqual(yaclog.read(location).versions[0].name, '3.0.0') self.assertEqual(yaclog.read(location).versions[0].name, '3.0.0')
self.assertIn('3.0.0', result.output) self.assertIn('3.0.0', result.output)
result = runner.invoke(cli, ['release', '-p', '-n'])
check_result(self, result)
self.assertEqual(yaclog.read(location).versions[0].name, '3.0.1')
self.assertEqual(yaclog.read(location).versions[1].name, '3.0.0')
self.assertIn('3.0.1', result.output)
def test_commit(self): def test_commit(self):
"""Test committing and tagging releases""" """Test committing and tagging releases"""
runner = CliRunner() runner = CliRunner()
@ -217,6 +228,31 @@ class TestRelease(unittest.TestCase):
self.assertIn(repo.head.commit.hexsha[0:7], result.output) self.assertIn(repo.head.commit.hexsha[0:7], result.output)
self.assertEqual(repo.tags[0].name, '1.0.0') self.assertEqual(repo.tags[0].name, '1.0.0')
def test_cargo(self):
"""Test updating cargo.toml files"""
runner = CliRunner()
with runner.isolated_filesystem():
with open("Cargo.toml", "w") as fp:
fp.write((
'[package]\n'
'name = "dummy"\n'
'version = "0.3.4"\n'
'authors = ["Andrew Cassidy <drewcassidy@me.com>"]\n'
'description = "A dummy crate used for testing yaclog"\n'
'keywords = ["does", "not", "exist"]\n'
'edition = "2018"\n'
))
runner.invoke(cli, ['init']) # create the changelog
runner.invoke(cli, ['entry', '-b', 'entry number 1'])
result = runner.invoke(cli, ['release', 'Version 1.0.0', '-C'])
check_result(self, result)
with open("Cargo.toml", "r") as fp:
self.assertIn('version = "1.0.0"', fp.read())
# we're just going to trust tomlkit not to mangle everything else
class TestShow(unittest.TestCase): class TestShow(unittest.TestCase):

View File

@ -18,7 +18,6 @@ import datetime
import os.path import os.path
import click import click
import git
import yaclog.version import yaclog.version
from yaclog.changelog import Changelog from yaclog.changelog import Changelog
@ -51,7 +50,7 @@ def init(obj: Changelog):
click.echo(f'Created new changelog file at {obj.path}') click.echo(f'Created new changelog file at {obj.path}')
@cli.command('format') # dont accidentally hide the `format` python builtin @cli.command('format') # don't accidentally hide the `format` python builtin
@click.pass_obj @click.pass_obj
def reformat(obj: Changelog): def reformat(obj: Changelog):
"""Reformat the changelog file.""" """Reformat the changelog file."""
@ -71,9 +70,12 @@ def reformat(obj: Changelog):
help='Show only the version body.') help='Show only the version body.')
@click.option('--header', '-h', 'mode', flag_value='header', @click.option('--header', '-h', 'mode', flag_value='header',
help='Show only the version header.') help='Show only the version header.')
@click.option('--version', '-v', 'mode', flag_value='version', help='Show only the version number. If the current version is unreleased, '
'this is inferred by incrementing the patch number of the last released version')
@click.option('---gh-actions', 'gh_actions', is_flag=True, hidden=True)
@click.argument('version_names', metavar='VERSIONS', type=str, nargs=-1) @click.argument('version_names', metavar='VERSIONS', type=str, nargs=-1)
@click.pass_obj @click.pass_obj
def show(obj: Changelog, all_versions, markdown, mode, version_names): def show(obj: Changelog, all_versions, markdown, mode, version_names, gh_actions):
""" """
Show the changes for VERSIONS. Show the changes for VERSIONS.
@ -85,15 +87,22 @@ def show(obj: Changelog, all_versions, markdown, mode, version_names):
'name': (lambda v, k: v.name), 'name': (lambda v, k: v.name),
'body': (lambda v, k: v.body(**k)), 'body': (lambda v, k: v.body(**k)),
'header': (lambda v, k: v.header(**k)), 'header': (lambda v, k: v.header(**k)),
'version': (lambda v, k: str(v.version))
} }
str_func = functions[mode] str_func = functions[mode]
kwargs = {'md': markdown, 'color': True}
try: try:
if all_versions: if all_versions:
versions = obj.versions versions = obj.versions
elif len(version_names) == 0: elif len(version_names) == 0:
versions = [obj.current_version()] versions = [obj.current_version()]
if mode == 'version' and versions[0].name == 'Unreleased':
latest = obj.current_version(released=True).version
inferred = yaclog.version.increment_version(str(latest), 2, '')
print(str(inferred))
return
else: else:
versions = [obj.get_version(name) for name in version_names] versions = [obj.get_version(name) for name in version_names]
except KeyError as k: except KeyError as k:
@ -101,9 +110,21 @@ def show(obj: Changelog, all_versions, markdown, mode, version_names):
except ValueError as v: except ValueError as v:
raise click.ClickException(str(v)) raise click.ClickException(str(v))
kwargs = {'md': markdown, 'color': True}
sep = '\n\n' if mode == 'body' or mode == 'full' else '\n' sep = '\n\n' if mode == 'body' or mode == 'full' else '\n'
if gh_actions:
import tempfile
all_modes = [ 'name', 'header', 'version' ]
outputs = [f'{mode}={sep.join([functions[mode](v, kwargs) for v in versions])}' for mode in all_modes]
click.echo('\n'.join(outputs))
body_fd, body_file = tempfile.mkstemp(text=True)
with os.fdopen(body_fd, 'w') as f:
f.write(sep.join([functions['body'](v, kwargs) for v in versions]))
click.echo(f'body_file={body_file}')
click.echo(f'changelog={obj.path}')
return
click.echo(sep.join([str_func(v, kwargs) for v in versions])) click.echo(sep.join([str_func(v, kwargs) for v in versions]))
@ -188,6 +209,8 @@ def entry(obj: Changelog, bullets, paragraphs, section_name, version_name):
help='Increment minor version number.') help='Increment minor version number.')
@click.option('-p', '--patch', 'rel_seg', flag_value=2, type=int, @click.option('-p', '--patch', 'rel_seg', flag_value=2, type=int,
help='Increment patch number.') help='Increment patch number.')
@click.option('-s', '--segment', 'rel_seg', type=int,
help='Increment nth segment of the version. For example, `--segment 2` is equivalent to `--patch`')
@click.option('-a', '--alpha', 'pre_seg', flag_value='a', type=str, default=None, @click.option('-a', '--alpha', 'pre_seg', flag_value='a', type=str, default=None,
help='Increment alpha version number.') help='Increment alpha version number.')
@click.option('-b', '--beta', 'pre_seg', flag_value='b', type=str, @click.option('-b', '--beta', 'pre_seg', flag_value='b', type=str,
@ -199,9 +222,15 @@ def entry(obj: Changelog, bullets, paragraphs, section_name, version_name):
@click.option('-c', '--commit', is_flag=True, @click.option('-c', '--commit', is_flag=True,
help='Create a git commit tagged with the new version number. ' help='Create a git commit tagged with the new version number. '
'If there are no changes to commit, the current commit will be tagged instead.') 'If there are no changes to commit, the current commit will be tagged instead.')
@click.option('-C', '--cargo', '-🦀', is_flag=True,
help='Update the version in a Rust cargo.toml manifest file.')
@click.option('-y', '--yes', is_flag=True,
help='Answer "yes" to all confirmation dialogs')
@click.option('-n', '--new', is_flag=True,
help = 'Create a new version instead of renaming an existing one')
@click.argument('version_name', metavar='VERSION', type=str, default=None, required=False) @click.argument('version_name', metavar='VERSION', type=str, default=None, required=False)
@click.pass_obj @click.pass_obj
def release(obj: Changelog, version_name, rel_seg, pre_seg, commit): def release(obj: Changelog, version_name, rel_seg, pre_seg, commit, cargo, yes, new):
""" """
Release VERSION, or a version incremented from the last release. Release VERSION, or a version incremented from the last release.
@ -213,11 +242,14 @@ def release(obj: Changelog, version_name, rel_seg, pre_seg, commit):
other kinds of prerelease. other kinds of prerelease.
""" """
if rel_seg is None and pre_seg is None and not version_name and not commit: if rel_seg is None and pre_seg is None and not version_name and not commit and not cargo:
click.echo('Nothing to release!') click.echo('Nothing to release!')
raise click.Abort raise click.Abort
cur_version = obj.current_version() if new:
cur_version = obj.add_version()
else:
cur_version = obj.current_version()
old_name = cur_version.name old_name = cur_version.name
if version_name: if version_name:
@ -234,11 +266,11 @@ def release(obj: Changelog, version_name, rel_seg, pre_seg, commit):
new_name = yaclog.version.increment_version(new_name, rel_seg, pre_seg) new_name = yaclog.version.increment_version(new_name, rel_seg, pre_seg)
if new_name != old_name: if new_name != old_name:
if yaclog.version.is_release(old_name): if yaclog.version.is_release(old_name) and not yes:
click.confirm( click.confirm(
f"Rename release version {click.style(old_name, fg='blue')} " f"Rename release version {click.style(old_name, fg='blue')} "
f"to {click.style(new_name, fg='blue')}?", f"to {click.style(new_name, fg='blue')}?",
abort=True) abort=True)
cur_version.name = new_name cur_version.name = new_name
cur_version.date = datetime.datetime.utcnow().date() cur_version.date = datetime.datetime.utcnow().date()
@ -246,7 +278,17 @@ def release(obj: Changelog, version_name, rel_seg, pre_seg, commit):
obj.write() obj.write()
click.echo(f"Renamed {click.style(old_name, fg='blue')} to {click.style(new_name, fg='blue')}") click.echo(f"Renamed {click.style(old_name, fg='blue')} to {click.style(new_name, fg='blue')}")
short_version, *_ = yaclog.version.extract_version(cur_version.name)
if not short_version:
short_version = cur_version.name.replace(' ', '-')
if cargo:
from ..cli import cargo_toml
cargo_toml.set_version("Cargo.toml", str(short_version))
click.echo("Updated Cargo.toml")
if commit: if commit:
import git
repo = git.Repo(os.curdir) repo = git.Repo(os.curdir)
if repo.bare: if repo.bare:
@ -254,6 +296,9 @@ def release(obj: Changelog, version_name, rel_seg, pre_seg, commit):
repo.index.add(obj.path) repo.index.add(obj.path)
if cargo:
repo.index.add("Cargo.toml")
tracked = len(repo.index.diff(repo.head.commit)) tracked = len(repo.index.diff(repo.head.commit))
untracked = len(repo.index.diff(None)) untracked = len(repo.index.diff(None))
@ -269,7 +314,8 @@ def release(obj: Changelog, version_name, rel_seg, pre_seg, commit):
f"You have {untracked} untracked file{'s'[:untracked]} that will not be included!", f"You have {untracked} untracked file{'s'[:untracked]} that will not be included!",
fg='red', bold=True)) fg='red', bold=True))
click.confirm(' '.join(message), abort=True) if not yes:
click.confirm(' '.join(message), abort=True)
if tracked > 0: if tracked > 0:
commit = repo.index.commit(f'Release {cur_version.name}\n\n{cur_version.body()}') commit = repo.index.commit(f'Release {cur_version.name}\n\n{cur_version.body()}')
@ -277,10 +323,7 @@ def release(obj: Changelog, version_name, rel_seg, pre_seg, commit):
else: else:
commit = repo.head.commit commit = repo.head.commit
short_version, *_ = yaclog.version.extract_version(cur_version.name) # noinspection PyTypeChecker
if not short_version:
short_version = cur_version.name.replace(' ', '-')
repo_tag = repo.create_tag(short_version, ref=commit, message=cur_version.body(False)) repo_tag = repo.create_tag(short_version, ref=commit, message=cur_version.body(False))
click.echo(f"Created tag {click.style(repo_tag.name, fg='green')}.") click.echo(f"Created tag {click.style(repo_tag.name, fg='green')}.")

33
yaclog/cli/cargo_toml.py Normal file
View File

@ -0,0 +1,33 @@
# yaclog: yet another changelog tool
# Copyright (c) 2022. Andrew Cassidy
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from tomlkit import dumps
from tomlkit import parse
def set_version(path, version):
"""
Set the version string in a cargo.toml file
:param path: path-like file location
:param version: version string to overwrite with
"""
with open(path, 'r+') as fp:
toml = parse(fp.read())
toml['package']['version'] = version
fp.seek(0)
fp.write(dumps(toml))
fp.truncate()