mirror of
https://github.com/drewcassidy/yaclog.git
synced 2024-09-01 14:58:58 +00:00
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
0666f7f593 | |||
51e28e4ef0 | |||
a7cbacb687 | |||
3fa529a05c | |||
396960fae0 | |||
c661be05dc | |||
2f4124c0fc | |||
465b818ca2 | |||
32f20e677e | |||
8421d38164 | |||
c5030b6060 | |||
4ce3de25c7 | |||
6bc99c585b | |||
32abd7bc6b | |||
06df766f9f |
6
.github/workflows/python-publish.yml
vendored
6
.github/workflows/python-publish.yml
vendored
@ -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" ]
|
||||||
click-version: [ "click~=7.0", "click~=8.0" ]
|
click-version: [ "click~=7.0", "click~=8.0" ]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- 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@v4.4.0
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python-version }}
|
python-version: ${{ matrix.python-version }}
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v3.1.1
|
uses: actions/setup-python@v4.4.0
|
||||||
with:
|
with:
|
||||||
python-version: '3.x'
|
python-version: '3.x'
|
||||||
|
|
||||||
|
21
CHANGELOG.md
21
CHANGELOG.md
@ -2,6 +2,27 @@
|
|||||||
|
|
||||||
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.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
|
||||||
|
@ -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 = [
|
||||||
@ -32,7 +31,9 @@ requires-python = ">= 3.8"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"Click >= 7.0",
|
"Click >= 7.0",
|
||||||
"GitPython >= 3",
|
"GitPython >= 3",
|
||||||
"packaging >= 20"
|
"packaging >= 20",
|
||||||
|
"tomlkit >= 0.11"
|
||||||
|
|
||||||
]
|
]
|
||||||
dynamic = ["version"]
|
dynamic = ["version"]
|
||||||
|
|
||||||
|
@ -217,6 +217,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):
|
||||||
|
|
||||||
|
@ -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."""
|
||||||
@ -199,9 +198,11 @@ 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.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):
|
||||||
"""
|
"""
|
||||||
Release VERSION, or a version incremented from the last release.
|
Release VERSION, or a version incremented from the last release.
|
||||||
|
|
||||||
@ -213,7 +214,7 @@ 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
|
||||||
|
|
||||||
@ -246,7 +247,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 +265,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))
|
||||||
|
|
||||||
@ -277,10 +291,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
33
yaclog/cli/cargo_toml.py
Normal 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()
|
Reference in New Issue
Block a user