Change release process to use towncrier and delay regenerating README

1. Use [towncrier][1] to generate release notes/CHANGELOG instead of
   auto-generating it from git commit messages.
2. Move release scripts into a Justfile.
3. Only regenerate the top-level README file when making a release,
   don't force it to be up to date in between releases.

Point 3 helps prevent documentation for unreleased changes from being
shown to users on GitHub, which may otherwise be confusing.

[1]: https://towncrier.readthedocs.io/en/stable/index.html#
This commit is contained in:
Nick Groenen 2024-08-04 12:36:11 +02:00
parent 564bee1d92
commit 72735cfff8
No known key found for this signature in database
GPG Key ID: 4F0AD019928AE098
14 changed files with 184 additions and 55 deletions

View File

@ -22,6 +22,19 @@
"packageNameTemplate": "rust-lang/rust",
"datasourceTemplate": "github-releases"
},
{
"customType": "regex",
"fileMatch": ["^Justfile$"],
"matchStrings": [
// https://regex101.com/r/vOmY6R/1
// Matching on word boundaries (\b) around start and end ensures we
// match variations like "towncrier==1.2.3" as well as "pipx run
// towncrier==1.2.3", adding some future proofness.
"\".*\\btowncrier==(?<currentValue>.+?)\\b\""
],
"depNameTemplate": "towncrier",
"datasourceTemplate": "pypi"
},
],
packageRules: [
{

View File

@ -15,5 +15,5 @@ jobs:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: dtolnay/rust-toolchain@stable
- uses: ./.github/actions/setup-ci
- run: cargo publish

View File

@ -30,8 +30,3 @@ repos:
language: system
files: \.rs$
pass_filenames: false
- id: README
name: Render README.md
entry: docs/generate.sh
language: script
files: ^(README\.md)|(docs/.*)

View File

@ -1,5 +1,7 @@
# Changelog
<!-- towncrier release notes start -->
## v23.12.0 (2023-12-03)
### New

View File

@ -74,4 +74,9 @@ If you don't feel comfortable writing user documentation, I will be happy to gui
> **⚠ Warning**
>
> If you update the README file, take note that you must edit the fragments in the [docs](docs/) directory as opposed to the README in the root of the repository, which is auto-generated.
> If you update the README file, take note that you must edit the fragments in the [docs](docs/) directory as opposed to the README in the root of the repository, which is auto-generated with every release.
## Release notes
[Towncrier](https://towncrier.readthedocs.io/en/stable/index.html) is used to generate release notes.
If you add a changelog fragment to the `changelog.d` directory with `just add-changelog` (requires [just](https://github.com/casey/just#installation)) it will automatically be picked up when a new release is made.

67
Justfile Normal file
View File

@ -0,0 +1,67 @@
towncrier_cmd := "pipx run towncrier==24.7.0"
_default:
@{{just_executable()}} --choose
# Add a new changelog entry using towncrier
add-changelog:
{{towncrier_cmd}} create --edit
git add changelog.d
# Create a new release
make-new-release:
#!/usr/bin/env bash
set -euo pipefail
get_next_version_number() {
DATEPART=$(date +%y.%-m)
ITERATION=0
while true; do
VERSION_STRING="${DATEPART}.${ITERATION}"
if git rev-list "v$VERSION_STRING" > /dev/null 2>&1; then
((ITERATION++))
else
echo "$VERSION_STRING"
return
fi
done
}
git add .
if ! git diff-index --quiet HEAD; then
printf "Working directory is not clean. Please commit or stash your changes.\n"
exit 1
fi
VERSION=$(get_next_version_number)
COMMITMSG=$(mktemp --tmpdir commitmsg.XXXXXXXXXX)
trap 'rm "$COMMITMSG"' EXIT
set -x
cargo set-version "${VERSION}"
# Construct a git commit message.
# This must be done before the next step so we can leverage the --draft
# flag here to get a list of changes being introduced by this release.
printf "Release v${VERSION}\n\n" > "$COMMITMSG"
{{towncrier_cmd}} build --draft --version "${VERSION}" >> "$COMMITMSG"
# Generate changelog and docs
{{towncrier_cmd}} build --version "${VERSION}"
docs/generate.sh
# Stage all the changes we've prepared
git add .
# There are likely trailing whitespace changes in the changelog, but a single
# run of pre-commit will fix these automatically.
pre-commit run || git add .
git commit --file "$COMMITMSG"
git tag "v${VERSION}"
set +x
printf "\n\nSuccessfully created release %s\n" "v${VERSION}"
printf "\nYou'll probably want to continue with:\n"
printf "\tgit push origin main\n"
printf "\tgit push origin %s\n" "v${VERSION}"

View File

@ -0,0 +1,4 @@
Bump to the minimum supported Rust version to 1.80.0
Obsidian-export now uses [std::sync::LazyLock](https://doc.rust-lang.org/std/sync/struct.LazyLock.html) instead of [lazy_static](https://crates.io/crates/lazy_static), which was only stabilized in Rust 1.80.0.
This change made it possible to drop the external dependency on lazy_static, though as a result of this, compiling with older versions will no longer be possible.

0
changelog.d/.gitignore vendored Normal file
View File

1
changelog.d/154.new.md Symbolic link
View File

@ -0,0 +1 @@
204.new.md

5
changelog.d/204.new.md Normal file
View File

@ -0,0 +1,5 @@
Optionally preserve modified time of exported files
Add a new argument `--preserve-mtime` to keep the original modified time attribute of notes being exported, instead of setting them to the current time.
Contribution made by [Davis Davalos-DeLosh](https://github.com/Programmerino).

50
changelog.d/template.md Normal file
View File

@ -0,0 +1,50 @@
{% if render_title %}
## v{{ versiondata.version }} ({{ versiondata.date }})
{% endif %}
{% for section, _ in sections.items() %}
{% if section %}
## {{section}}
{% endif %}
{% if sections[section] %}
{% for category, val in definitions.items() if category in sections[section] %}
### {{ definitions[category]['name'] }}
{% for text, values in sections[section][category].items() %}
- {{ text }}
{%- if values %}
{% if "\n - " in text or '\n * ' in text %}
(
{%- else %}
{% if text %} ({% endif %}
{%- endif -%}
{%- for issue in values %}
{{ issue.split(": ", 1)[0] }}{% if not loop.last %}, {% endif %}
{%- endfor %}
{% if text %}){% endif %}
{% else %}
{% endif %}
{% endfor %}
{% if issues_by_category[section][category] and "]: " in issues_by_category[section][category][0] %}
{% for issue in issues_by_category[section][category] %}
{{ issue }}
{% endfor %}
{% endif %}
{% if sections[section][category]|length == 0 %}
No significant changes.
{% else %}
{% endif %}
{% endfor %}
{% else %}
No significant changes.
{% endif %}
{% endfor +%}

View File

@ -1,5 +1,5 @@
# Release process
- [ ] Run `./make-new-release.sh`
- [ ] Run `just make-new-release`
- [ ] Push the created release commit/tag to GitHub
- [ ] Wait for builds to turn green (<https://github.com/zoni/obsidian-export/actions>) and confirm everything looks OK.

View File

@ -1,47 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
get_next_version_number() {
DATEPART=$(date +%y.%-m)
ITERATION=0
while true; do
VERSION_STRING="${DATEPART}.${ITERATION}"
if git rev-list "v$VERSION_STRING" > /dev/null 2>&1; then
((ITERATION++))
else
echo "$VERSION_STRING"
return
fi
done
}
git add .
if ! git diff-index --quiet HEAD; then
printf "Working directory is not clean. Please commit or stash your changes.\n"
exit 1
fi
VERSION=$(get_next_version_number)
git tag "v${VERSION}"
git cliff --latest --prepend CHANGELOG.md > /dev/null
${EDITOR:-vim} CHANGELOG.md
docs/generate.sh
sed -i -E "s/^version = \".+\"$/version = \"${VERSION}\"/" Cargo.toml
cargo check
git add .
# There are likely trailing whitespace changes in the changelog, but a single
# run of pre-commit will fix these automatically.
pre-commit run || git add .
git commit --message "Release v${VERSION}"
git tag "v${VERSION}" --force
printf "\n\nSuccessfully created release %s\n" "v${VERSION}"
printf "\nYou'll probably want to continue with:\n"
printf "\tgit push origin main\n"
printf "\tgit push origin %s\n" "v${VERSION}"

34
towncrier.toml Normal file
View File

@ -0,0 +1,34 @@
[tool.towncrier]
name = "obsidian-export"
directory = "changelog.d"
template = "changelog.d/template.md"
filename = "CHANGELOG.md"
start_string = "<!-- towncrier release notes start -->\n"
underlines = ["", "", ""]
title_format = ""
issue_format = "[#{issue}](https://github.com/zoni/obsidian-export/issues/{issue})"
[[tool.towncrier.type]]
directory = "new"
name = "New Features"
showcontent = true
[[tool.towncrier.type]]
directory = "change"
name = "Changes"
showcontent = true
[[tool.towncrier.type]]
directory = "fix"
name = "Fixes"
showcontent = true
[[tool.towncrier.type]]
directory = "breaking"
name = "Backwards-incompatible Changes"
showcontent = true
[[tool.towncrier.type]]
directory = "deprecation"
name = "Deprecations"
showcontent = true