mirror of
https://github.com/drewcassidy/yaclog.git
synced 2024-09-01 14:58:58 +00:00
Compare commits
59 Commits
1.0.0
...
1f01bda2f4
Author | SHA1 | Date | |
---|---|---|---|
1f01bda2f4 | |||
629d931979 | |||
d2296fb926 | |||
80e35de136 | |||
d6da31b6ff | |||
d4f477a544 | |||
a392f09a51 | |||
683ccbf916 | |||
2a67f6edc7 | |||
c4be5d2420 | |||
30947769e1 | |||
6589a91d7e | |||
802633b9a7 | |||
47d4b595f8 | |||
fdf30bc14c | |||
72126c8dca | |||
0666f7f593 | |||
51e28e4ef0 | |||
a7cbacb687 | |||
3fa529a05c | |||
396960fae0 | |||
c661be05dc | |||
2f4124c0fc | |||
465b818ca2 | |||
32f20e677e | |||
8421d38164 | |||
c5030b6060 | |||
4ce3de25c7 | |||
6bc99c585b | |||
32abd7bc6b | |||
06df766f9f | |||
9b0ae90ee2 | |||
15e4d691f5 | |||
9a7e3da60d | |||
94f692e6c5 | |||
c7583388c6 | |||
fe9aa937d2 | |||
caa4560d6d | |||
03841ad07e | |||
aa2390312a | |||
07d76cdc09 | |||
8c79e158c8 | |||
21defeffce | |||
dccde1909b | |||
c25b780772 | |||
bf2e8f670f | |||
dc90731f3d | |||
5a6cb51d71 | |||
52fc36ab70 | |||
c696071b8f | |||
b0419dad80 | |||
2bfaa78053 | |||
524a1da4c6 | |||
acedf2b401 | |||
21b530c256 | |||
04a9c712f9 | |||
d35b7fee83 | |||
38560702f4 | |||
2d1cc4ede4 |
8
.github/dependabot.yml
vendored
Normal file
8
.github/dependabot.yml
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Set update schedule for GitHub Actions
|
||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
# Check for updates to GitHub Actions every weekday
|
||||||
|
interval: "daily"
|
32
.github/workflows/python-publish.yml
vendored
32
.github/workflows/python-publish.yml
vendored
@ -9,13 +9,14 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
python-version: [ 3.8, 3.9 ]
|
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
|
||||||
|
click-version: [ "click~=8.0" ]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Python ${{ matrix.python-version }}
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
uses: actions/setup-python@v2
|
uses: actions/setup-python@v5.1.1
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python-version }}
|
python-version: ${{ matrix.python-version }}
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
python -m pip install flake8
|
python -m pip install flake8
|
||||||
|
python -m pip install ${{ matrix.click-version }}
|
||||||
|
|
||||||
- name: Install module
|
- name: Install module
|
||||||
run: python -m pip install .
|
run: python -m pip install .
|
||||||
@ -38,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@v2
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v2
|
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
|
||||||
@ -62,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=Version $(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
|
||||||
@ -73,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 }}
|
||||||
|
@ -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: .
|
||||||
|
88
CHANGELOG.md
88
CHANGELOG.md
@ -2,7 +2,83 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file
|
All notable changes to this project will be documented in this file
|
||||||
|
|
||||||
## 1.0.0 - 2021-05-07
|
## 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
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed tests folder being installed as a package
|
||||||
|
|
||||||
|
|
||||||
|
## Version 1.0.3 - 2021-05-12
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed `show` command not working with Click version 8
|
||||||
|
- Fixed release message incorrectly stating if a commit will be created or not
|
||||||
|
|
||||||
|
|
||||||
|
## Version 1.0.2 - 2021-05-12
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Updated to support Click version 8
|
||||||
|
- Modified module documentation page titles to include a module role
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed tag names with spaces in versions
|
||||||
|
|
||||||
|
|
||||||
|
## Version 1.0.1 - 2021-05-10
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed broken header in new changelogs
|
||||||
|
- Improved consistency in command documentation metavars
|
||||||
|
|
||||||
|
|
||||||
|
## Version 1.0.0 - 2021-05-07
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
@ -25,7 +101,7 @@ All notable changes to this project will be documented in this file
|
|||||||
- Extra newlines are added between versions to improve readability of the raw markdown file.
|
- Extra newlines are added between versions to improve readability of the raw markdown file.
|
||||||
|
|
||||||
|
|
||||||
## 0.3.3 - 2021-04-27
|
## Version 0.3.3 - 2021-04-27
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
@ -40,7 +116,7 @@ All notable changes to this project will be documented in this file
|
|||||||
- `release` now works with logs that have only unreleased changes
|
- `release` now works with logs that have only unreleased changes
|
||||||
|
|
||||||
|
|
||||||
## 0.3.2 - 2021-04-24
|
## Version 0.3.2 - 2021-04-24
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
@ -56,7 +132,7 @@ All notable changes to this project will be documented in this file
|
|||||||
- `release` and `entry` commands now work using empty changelogs.
|
- `release` and `entry` commands now work using empty changelogs.
|
||||||
|
|
||||||
|
|
||||||
## 0.3.1 - 2021-04-24
|
## Version 0.3.1 - 2021-04-24
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
@ -69,7 +145,7 @@ All notable changes to this project will be documented in this file
|
|||||||
- `release` command for creating releases
|
- `release` command for creating releases
|
||||||
|
|
||||||
|
|
||||||
## 0.2.0 - 2021-04-19
|
## Version 0.2.0 - 2021-04-19
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
@ -83,7 +159,7 @@ All notable changes to this project will be documented in this file
|
|||||||
- Parser can now handle setext-style headers and H2s not conforming to the schema.
|
- Parser can now handle setext-style headers and H2s not conforming to the schema.
|
||||||
|
|
||||||
|
|
||||||
## 0.1.0 - 2021-04-16
|
## Version 0.1.0 - 2021-04-16
|
||||||
|
|
||||||
First release
|
First release
|
||||||
|
|
||||||
|
87
action.yaml
Normal file
87
action.yaml
Normal 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
|
@ -1,5 +1,5 @@
|
|||||||
Changelog Module
|
:py:mod:`changelog` Module
|
||||||
================
|
==========================
|
||||||
|
|
||||||
.. automodule:: yaclog.changelog
|
.. automodule:: yaclog.changelog
|
||||||
:members:
|
:members:
|
@ -1,5 +1,5 @@
|
|||||||
Markdown Module
|
:py:mod:`markdown` Module
|
||||||
===============
|
=========================
|
||||||
|
|
||||||
.. automodule:: yaclog.markdown
|
.. automodule:: yaclog.markdown
|
||||||
:members:
|
:members:
|
@ -1,5 +1,5 @@
|
|||||||
Version Module
|
:py:mod:`version` Module
|
||||||
==============
|
========================
|
||||||
|
|
||||||
.. automodule:: yaclog.version
|
.. automodule:: yaclog.version
|
||||||
:members:
|
:members:
|
@ -1,9 +1,59 @@
|
|||||||
[build-system]
|
[build-system]
|
||||||
requires = [
|
requires = [
|
||||||
"setuptools >= 35.0.2",
|
"setuptools>=64",
|
||||||
"setuptools_scm[toml] >= 3.4",
|
"setuptools_scm>=8",
|
||||||
"wheel"
|
"wheel"
|
||||||
]
|
]
|
||||||
build-backend = "setuptools.build_meta"
|
build-backend = "setuptools.build_meta"
|
||||||
|
|
||||||
[tool.setuptools_scm]
|
[project]
|
||||||
|
name = "yaclog"
|
||||||
|
description = "Yet another changelog CLI tool."
|
||||||
|
readme = "README.md"
|
||||||
|
authors = [{ name = "Andrew Cassidy", email = "drewcassidy@me.com" }]
|
||||||
|
keywords = ["changelog", "commandline", "markdown"]
|
||||||
|
classifiers = [
|
||||||
|
"Development Status :: 5 - Production/Stable",
|
||||||
|
"Intended Audience :: Developers",
|
||||||
|
"License :: OSI Approved :: GNU Affero General Public License v3",
|
||||||
|
"Operating System :: OS Independent",
|
||||||
|
"Programming Language :: Python :: 3 :: Only",
|
||||||
|
"Programming Language :: Python :: 3",
|
||||||
|
"Programming Language :: Python :: 3.8",
|
||||||
|
"Programming Language :: Python :: 3.9",
|
||||||
|
"Programming Language :: Python :: 3.10",
|
||||||
|
"Topic :: Text Processing :: Markup :: Markdown",
|
||||||
|
"Topic :: Software Development :: Version Control :: Git",
|
||||||
|
"Topic :: Utilities"
|
||||||
|
]
|
||||||
|
|
||||||
|
requires-python = ">= 3.8"
|
||||||
|
dependencies = [
|
||||||
|
"Click >= 8.0",
|
||||||
|
"GitPython >= 3",
|
||||||
|
"packaging >= 20",
|
||||||
|
"tomlkit >= 0.11"
|
||||||
|
|
||||||
|
]
|
||||||
|
dynamic = ["version"]
|
||||||
|
|
||||||
|
[project.optional-dependencies]
|
||||||
|
docs = [
|
||||||
|
"Sphinx >= 3.5",
|
||||||
|
"sphinx-click >= 2.7",
|
||||||
|
"sphinx-rtd-theme",
|
||||||
|
"myst-parser >= 0.14",
|
||||||
|
]
|
||||||
|
|
||||||
|
[project.scripts]
|
||||||
|
yaclog = "yaclog.cli.__main__:cli"
|
||||||
|
|
||||||
|
[project.urls]
|
||||||
|
Source = "https://github.com/drewcassidy/yaclog"
|
||||||
|
Changelog = "https://github.com/drewcassidy/yaclog/blob/main/CHANGELOG.md"
|
||||||
|
Docs = "https://yaclog.readthedocs.io/"
|
||||||
|
|
||||||
|
[tool.setuptools_scm]
|
||||||
|
|
||||||
|
[tool.setuptools.packages.find]
|
||||||
|
include = ["yaclog"]
|
50
setup.cfg
50
setup.cfg
@ -1,50 +0,0 @@
|
|||||||
[metadata]
|
|
||||||
# until setuptools supports PEP621, this will have to do
|
|
||||||
name = yaclog
|
|
||||||
description = Yet another changelog CLI tool.
|
|
||||||
author = Andrew Cassidy
|
|
||||||
license = AGPLv3
|
|
||||||
license_file = LICENSE.md
|
|
||||||
long_description = file: README.md
|
|
||||||
long_description_content_type = text/markdown
|
|
||||||
|
|
||||||
keywords = changelog, commandline, markdown
|
|
||||||
classifiers =
|
|
||||||
Development Status :: 5 - Production/Stable
|
|
||||||
Intended Audience :: Developers
|
|
||||||
License :: OSI Approved :: GNU Affero General Public License v3
|
|
||||||
Operating System :: OS Independent
|
|
||||||
Programming Language :: Python :: 3 :: Only
|
|
||||||
Programming Language :: Python :: 3
|
|
||||||
Programming Language :: Python :: 3.8
|
|
||||||
Programming Language :: Python :: 3.9
|
|
||||||
Topic :: Text Processing :: Markup :: Markdown
|
|
||||||
Topic :: Software Development :: Version Control :: Git
|
|
||||||
Topic :: Utilities
|
|
||||||
|
|
||||||
project_urls =
|
|
||||||
Source = https://github.com/drewcassidy/yaclog
|
|
||||||
Changelog = https://github.com/drewcassidy/yaclog/blob/main/CHANGELOG.md
|
|
||||||
Docs = https://yaclog.readthedocs.io/
|
|
||||||
|
|
||||||
[options]
|
|
||||||
install_requires =
|
|
||||||
Click ~= 7.0
|
|
||||||
GitPython >= 3
|
|
||||||
packaging >= 20
|
|
||||||
python_requires = >= 3.8
|
|
||||||
packages = find:
|
|
||||||
|
|
||||||
[options.extras_require]
|
|
||||||
docs =
|
|
||||||
Sphinx >= 3.5
|
|
||||||
sphinx-click >= 2.7
|
|
||||||
sphinx-rtd-theme
|
|
||||||
myst-parser >= 0.14
|
|
||||||
|
|
||||||
[options.entry_points]
|
|
||||||
console_scripts =
|
|
||||||
yaclog = yaclog.cli.__main__:cli
|
|
||||||
|
|
||||||
[options.packages.find]
|
|
||||||
exclude = tests.*
|
|
@ -28,6 +28,12 @@ class TestCreation(unittest.TestCase):
|
|||||||
self.assertTrue(os.path.exists(os.path.abspath(location)), 'yaclog init did not create a file')
|
self.assertTrue(os.path.exists(os.path.abspath(location)), 'yaclog init did not create a file')
|
||||||
self.assertIn(location, result.output, "yaclog init did not echo the file's correct location")
|
self.assertIn(location, result.output, "yaclog init did not echo the file's correct location")
|
||||||
|
|
||||||
|
with open(location, 'r') as fp:
|
||||||
|
self.assertEqual('# Changelog\n', fp.readline())
|
||||||
|
self.assertEqual('\n', fp.readline())
|
||||||
|
self.assertEqual('All notable changes to this project will be documented in this file',
|
||||||
|
fp.readline().rstrip())
|
||||||
|
|
||||||
with open(location, 'w') as fp:
|
with open(location, 'w') as fp:
|
||||||
fp.write(err_str)
|
fp.write(err_str)
|
||||||
|
|
||||||
@ -147,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'])
|
||||||
@ -188,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()
|
||||||
@ -204,13 +221,103 @@ class TestRelease(unittest.TestCase):
|
|||||||
runner.invoke(cli, ['init']) # create the changelog
|
runner.invoke(cli, ['init']) # create the changelog
|
||||||
runner.invoke(cli, ['entry', '-b', 'entry number 1'])
|
runner.invoke(cli, ['entry', '-b', 'entry number 1'])
|
||||||
|
|
||||||
result = runner.invoke(cli, ['release', '1.0.0', '-c'], input='y\n')
|
result = runner.invoke(cli, ['release', 'Version 1.0.0', '-c'], input='y\n')
|
||||||
check_result(self, result)
|
check_result(self, result)
|
||||||
self.assertIn('Created commit', result.output)
|
self.assertIn('Created commit', result.output)
|
||||||
self.assertIn('Created tag', result.output)
|
self.assertIn('Created tag', result.output)
|
||||||
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):
|
||||||
|
|
||||||
|
# noinspection PyShadowingNames
|
||||||
|
def setUp(self):
|
||||||
|
self.runner = CliRunner()
|
||||||
|
self.location = 'CHANGELOG.md'
|
||||||
|
|
||||||
|
self.log = yaclog.Changelog()
|
||||||
|
|
||||||
|
self.log.add_version(name='1.0.0').add_entry('- entry number 1')
|
||||||
|
self.log.add_version(name='Version 2.0.0').add_entry('- entry number 2', 'Added')
|
||||||
|
self.log.add_version(name='Three Point Oh').add_entry('entry number 3')
|
||||||
|
v = self.log.add_version(name='4.0.0 "Euclid"')
|
||||||
|
v.add_entry('- entry number 4')
|
||||||
|
v.add_entry('- entry number 5')
|
||||||
|
v.tags.append('TAGGED')
|
||||||
|
|
||||||
|
self.modes = {
|
||||||
|
'full': ([], lambda v, k: v.text(**k), '\n\n'),
|
||||||
|
'name': (['-n'], lambda v, k: v.name, '\n'),
|
||||||
|
'body': (['-b'], lambda v, k: v.body(**k), '\n\n'),
|
||||||
|
'header': (['-h'], lambda v, k: v.header(**k), '\n'),
|
||||||
|
}
|
||||||
|
|
||||||
|
def test_show_all(self):
|
||||||
|
"""Test showing all version information"""
|
||||||
|
|
||||||
|
with self.runner.isolated_filesystem():
|
||||||
|
self.log.write(self.location)
|
||||||
|
|
||||||
|
for mode, t in self.modes.items():
|
||||||
|
with self.subTest(mode, flags=t[0]):
|
||||||
|
check_result(self, result := self.runner.invoke(cli, ['show', '-a'] + t[0]))
|
||||||
|
self.assertEqual(t[2].join([t[1](v, {'md': False}) for v in self.log.versions]),
|
||||||
|
result.output.strip(), 'incorrect plaintext output')
|
||||||
|
|
||||||
|
check_result(self, result := self.runner.invoke(cli, ['show', '-am'] + t[0]))
|
||||||
|
self.assertEqual(t[2].join([t[1](v, {'md': True}) for v in self.log.versions]),
|
||||||
|
result.output.strip(), 'incorrect markdown output')
|
||||||
|
|
||||||
|
def test_show_version(self):
|
||||||
|
with self.runner.isolated_filesystem():
|
||||||
|
self.log.write(self.location)
|
||||||
|
|
||||||
|
for mode, t in self.modes.items():
|
||||||
|
with self.subTest(mode, flags=t[0]):
|
||||||
|
|
||||||
|
for version in self.log.versions:
|
||||||
|
check_result(self, result := self.runner.invoke(cli, ['show', version.name] + t[0]))
|
||||||
|
self.assertEqual(t[1](version, {'md': False}),
|
||||||
|
result.output.strip(), 'incorrect plaintext output')
|
||||||
|
|
||||||
|
check_result(self, result := self.runner.invoke(cli, ['show', version.name[-5:]] + t[0]))
|
||||||
|
self.assertEqual(t[1](version, {'md': False}),
|
||||||
|
result.output.strip(), 'incorrect plaintext output')
|
||||||
|
|
||||||
|
check_result(self, result := self.runner.invoke(cli, ['show', version.name, '-m'] + t[0]))
|
||||||
|
self.assertEqual(t[1](version, {'md': True}),
|
||||||
|
result.output.strip(), 'incorrect markdown output')
|
||||||
|
|
||||||
|
check_result(self, result := self.runner.invoke(cli, ['show', version.name[-5:], '-m'] + t[0]))
|
||||||
|
self.assertEqual(t[1](version, {'md': True}),
|
||||||
|
result.output.strip(), 'incorrect markdown output')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -223,7 +223,7 @@ class Changelog:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, path=None,
|
def __init__(self, path=None,
|
||||||
preamble: str = "Changelog\n\nAll notable changes to this project will be documented in this file"):
|
preamble: str = "# Changelog\n\nAll notable changes to this project will be documented in this file"):
|
||||||
"""
|
"""
|
||||||
Contents will be automatically read from disk if the file exists
|
Contents will be automatically read from disk if the file exists
|
||||||
|
|
||||||
@ -381,14 +381,15 @@ class Changelog:
|
|||||||
|
|
||||||
def get_version(self, name: Optional[str] = None) -> VersionEntry:
|
def get_version(self, name: Optional[str] = None) -> VersionEntry:
|
||||||
"""
|
"""
|
||||||
Get a version from the changelog by name
|
Get a version from the changelog by name.
|
||||||
|
|
||||||
:param name: The name of the version to get, or `None` to return the most recent
|
:param name: The name of the version to get, or `None` to return the most recent.
|
||||||
|
The first version with this value in its name is returned.
|
||||||
:return: The first version with the selected name
|
:return: The first version with the selected name
|
||||||
"""
|
"""
|
||||||
|
|
||||||
for version in self.versions:
|
for version in self.versions:
|
||||||
if version.name == name or name is None:
|
if name in version.name or name is None:
|
||||||
return version
|
return version
|
||||||
raise KeyError(f'Version {name} not found in changelog')
|
raise KeyError(f'Version {name} not found in changelog')
|
||||||
|
|
||||||
|
@ -18,14 +18,13 @@ 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
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
@click.option('--path', envvar='YACLOG_PATH', default='CHANGELOG.md', show_default=True,
|
@click.option('--path', envvar='YACLOG_PATH', metavar='FILE', default='CHANGELOG.md', show_default=True,
|
||||||
type=click.Path(dir_okay=False, writable=True, readable=True),
|
type=click.Path(dir_okay=False, writable=True, readable=True),
|
||||||
help='Location of the changelog file.')
|
help='Location of the changelog file.')
|
||||||
@click.version_option()
|
@click.version_option()
|
||||||
@ -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."""
|
||||||
@ -59,42 +58,74 @@ def reformat(obj: Changelog):
|
|||||||
click.echo(f'Reformatted changelog file at {obj.path}')
|
click.echo(f'Reformatted changelog file at {obj.path}')
|
||||||
|
|
||||||
|
|
||||||
|
# noinspection PyShadowingNames
|
||||||
@cli.command(short_help='Show changes from the changelog file')
|
@cli.command(short_help='Show changes from the changelog file')
|
||||||
@click.option('--all', '-a', 'all_versions', is_flag=True, help='Show the entire changelog.')
|
@click.option('--all', '-a', 'all_versions', is_flag=True, help='Show the entire changelog.')
|
||||||
@click.option('--markdown/--txt', '-m/-t', default=False, help='Display as markdown or plain text.')
|
@click.option('--markdown/--txt', '-m/-t', default=False, help='Display as markdown or plain text.')
|
||||||
@click.option('--full', '-f', 'str_func', flag_value=lambda v, k: v.text(**k), default=True,
|
@click.option('--full', '-f', 'mode', flag_value='full', default=True,
|
||||||
help='Show version header and body.')
|
help='Show version header and body.')
|
||||||
@click.option('--name', '-n', 'str_func', flag_value=lambda v, k: v.name, help='Show only the version name')
|
@click.option('--name', '-n', 'mode', flag_value='name',
|
||||||
@click.option('--body', '-b', 'str_func', flag_value=lambda v, k: v.body(**k), help='Show only the version body.')
|
help='Show only the version name')
|
||||||
@click.option('--header', '-h', 'str_func', flag_value=lambda v, k: v.preamble(**k),
|
@click.option('--body', '-b', 'mode', flag_value='body',
|
||||||
|
help='Show only the version body.')
|
||||||
|
@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, str_func, version_names):
|
def show(obj: Changelog, all_versions, markdown, mode, version_names, gh_actions):
|
||||||
"""
|
"""
|
||||||
Show the changes for VERSIONS.
|
Show the changes for VERSIONS.
|
||||||
|
|
||||||
VERSIONS is a list of versions to print. If not given, the most recent version is used.
|
VERSIONS is a list of versions to print. If not given, the most recent version is used.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
functions = {
|
||||||
|
'full': (lambda v, k: v.text(**k)),
|
||||||
|
'name': (lambda v, k: v.name),
|
||||||
|
'body': (lambda v, k: v.body(**k)),
|
||||||
|
'header': (lambda v, k: v.header(**k)),
|
||||||
|
'version': (lambda v, k: str(v.version))
|
||||||
|
}
|
||||||
|
|
||||||
|
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:
|
||||||
raise click.BadArgumentUsage(k)
|
raise click.BadArgumentUsage(str(k))
|
||||||
except ValueError as v:
|
except ValueError as v:
|
||||||
raise click.ClickException(v)
|
raise click.ClickException(str(v))
|
||||||
|
|
||||||
kwargs = {'md': markdown, 'color': True}
|
sep = '\n\n' if mode == 'body' or mode == 'full' else '\n'
|
||||||
|
|
||||||
for v in versions:
|
if gh_actions:
|
||||||
text = str_func(v, kwargs)
|
import tempfile
|
||||||
click.echo(text)
|
|
||||||
click.echo('\n')
|
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]))
|
||||||
|
|
||||||
|
|
||||||
@cli.command(short_help='Modify version tags')
|
@cli.command(short_help='Modify version tags')
|
||||||
@ -115,9 +146,9 @@ def tag(obj: Changelog, add, tag_name: str, version_name: str):
|
|||||||
else:
|
else:
|
||||||
version = obj.current_version()
|
version = obj.current_version()
|
||||||
except KeyError as k:
|
except KeyError as k:
|
||||||
raise click.BadArgumentUsage(k)
|
raise click.BadArgumentUsage(str(k))
|
||||||
except ValueError as v:
|
except ValueError as v:
|
||||||
raise click.ClickException(v)
|
raise click.ClickException(str(v))
|
||||||
|
|
||||||
if add:
|
if add:
|
||||||
version.tags.append(tag_name)
|
version.tags.append(tag_name)
|
||||||
@ -131,8 +162,8 @@ def tag(obj: Changelog, add, tag_name: str, version_name: str):
|
|||||||
|
|
||||||
|
|
||||||
@cli.command(short_help='Add entries to the changelog.')
|
@cli.command(short_help='Add entries to the changelog.')
|
||||||
@click.option('--bullet', '-b', 'bullets', metavar='text', multiple=True, type=str, help='Add a bullet point.')
|
@click.option('--bullet', '-b', 'bullets', metavar='TEXT', multiple=True, type=str, help='Add a bullet point.')
|
||||||
@click.option('--paragraph', '-p', 'paragraphs', metavar='text', multiple=True, type=str, help='Add a paragraph')
|
@click.option('--paragraph', '-p', 'paragraphs', metavar='TEXT', multiple=True, type=str, help='Add a paragraph')
|
||||||
@click.argument('section_name', metavar='SECTION', type=str, default='', required=False)
|
@click.argument('section_name', metavar='SECTION', type=str, default='', required=False)
|
||||||
@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
|
||||||
@ -153,7 +184,7 @@ def entry(obj: Changelog, bullets, paragraphs, section_name, version_name):
|
|||||||
else:
|
else:
|
||||||
version = obj.current_version(released=False, new_version=True)
|
version = obj.current_version(released=False, new_version=True)
|
||||||
except KeyError as k:
|
except KeyError as k:
|
||||||
raise click.BadArgumentUsage(k)
|
raise click.BadArgumentUsage(str(k))
|
||||||
|
|
||||||
for p in paragraphs:
|
for p in paragraphs:
|
||||||
version.add_entry(p, section_name)
|
version.add_entry(p, section_name)
|
||||||
@ -172,19 +203,34 @@ def entry(obj: Changelog, bullets, paragraphs, section_name, version_name):
|
|||||||
|
|
||||||
|
|
||||||
@cli.command(short_help='Release versions.')
|
@cli.command(short_help='Release versions.')
|
||||||
@click.option('-M', '--major', 'rel_seg', flag_value=0, default=None, help='Increment major version number.')
|
@click.option('-M', '--major', 'rel_seg', flag_value=0, type=int, default=None,
|
||||||
@click.option('-m', '--minor', 'rel_seg', flag_value=1, help='Increment minor version number.')
|
help='Increment major version number.')
|
||||||
@click.option('-p', '--patch', 'rel_seg', flag_value=2, help='Increment patch number.')
|
@click.option('-m', '--minor', 'rel_seg', flag_value=1, type=int,
|
||||||
@click.option('-a', '--alpha', 'pre_seg', flag_value='a', default=None, help='Increment alpha version number.')
|
help='Increment minor version number.')
|
||||||
@click.option('-b', '--beta', 'pre_seg', flag_value='b', help='Increment beta version number.')
|
@click.option('-p', '--patch', 'rel_seg', flag_value=2, type=int,
|
||||||
@click.option('-r', '--rc', 'pre_seg', flag_value='rc', help='Increment release candidate version number.')
|
help='Increment patch number.')
|
||||||
@click.option('-f', '--full', 'pre_seg', flag_value='', help='Clear the prerelease value creating a full release.')
|
@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,
|
||||||
|
help='Increment alpha version number.')
|
||||||
|
@click.option('-b', '--beta', 'pre_seg', flag_value='b', type=str,
|
||||||
|
help='Increment beta version number.')
|
||||||
|
@click.option('-r', '--rc', 'pre_seg', flag_value='rc', type=str,
|
||||||
|
help='Increment release candidate version number.')
|
||||||
|
@click.option('-f', '--full', 'pre_seg', flag_value='',
|
||||||
|
help='Clear the prerelease value creating a full release.')
|
||||||
@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.
|
||||||
|
|
||||||
@ -196,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:
|
||||||
@ -217,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()
|
||||||
@ -229,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:
|
||||||
@ -237,10 +296,13 @@ 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))
|
||||||
|
|
||||||
message = [['Commit and create tag', 'Create tag'][min(tracked, 1)], 'for']
|
message = [['Create tag', 'Commit and create tag'][min(tracked, 1)], 'for']
|
||||||
|
|
||||||
if not cur_version.released:
|
if not cur_version.released:
|
||||||
message.append('non-release')
|
message.append('non-release')
|
||||||
@ -252,15 +314,17 @@ 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'Version {cur_version.name}\n\n{cur_version.body()}')
|
commit = repo.index.commit(f'Release {cur_version.name}\n\n{cur_version.body()}')
|
||||||
click.echo(f"Created commit {click.style(repo.head.commit.hexsha[0:7], fg='green')}")
|
click.echo(f"Created commit {click.style(repo.head.commit.hexsha[0:7], fg='green')}")
|
||||||
else:
|
else:
|
||||||
commit = repo.head.commit
|
commit = repo.head.commit
|
||||||
|
|
||||||
repo_tag = repo.create_tag(cur_version.name, ref=commit, message=cur_version.body(False))
|
# noinspection PyTypeChecker
|
||||||
|
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