From beb1fd23a42d44ac3a1f66fcf778461efccac771 Mon Sep 17 00:00:00 2001 From: Marvin Vogt Date: Sun, 3 Nov 2024 13:49:07 +0100 Subject: [PATCH] Add just recipes to update changelog and release version (#152) --- .github/CONTRIBUTING.md | 24 +++++++++++++++++++++++ justfile | 43 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 2cc7bac..3a2c760 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -50,3 +50,27 @@ $ just test To ensure that the parser stays performant, benchmarks are run on every PR. To execute them locally, run `cargo bench`. [`just`]: https://github.com/casey/just + +## Releasing a new version + +To release a new version of `rpsl-rs`, perform the following steps. + +- Ensure the unreleased section of the [CHANGELOG](../CHANGELOG.md) contains all relevant changes. + +- Checkout a new branch. + + ```sh + $ git switch -c bump-version-1-0-0 + ``` + +- Use the just recipe to bump the version. This will create the necessary commits as well as a pull request using the GitHub CLI. + + ```sh + $ just bump-version 1.0.0 + ``` + +- Once the branch is merged, a GitHub release for the new version containing the recent changes can be created automatically. + + ```sh + $ just release-latest-version 1.0.0 + ``` diff --git a/justfile b/justfile index 763dacc..c462306 100644 --- a/justfile +++ b/justfile @@ -1,6 +1,8 @@ import "docs/benchmark/benchmark.just" export CI := env("CI", "false") +CHANGELOG_FILE := "CHANGELOG.md" +REPO_URL := "https://github.com/SRv6d/rpsl-rs" default: lint test @@ -19,21 +21,40 @@ test $COV=CI: (_install_llvm_cov COV) {{ if COV == "true" { "cargo llvm-cov --all-features" + " " + cov_output } else { "cargo test --all-features" } }} # Bump our version -bump-version $VERSION: (_validate_semver VERSION) +bump-version $VERSION: _check_clean_working (_validate_semver VERSION) && (_changelog_add_version VERSION) (_bump_version_pr VERSION) #!/usr/bin/env bash set -euxo pipefail - test -z "$(git status --porcelain)" || (echo "The working directory is not clean"; exit 1) - sed -i 's/^version = .*/version = "'$VERSION'"/g' Cargo.toml git add Cargo.toml git commit -m "Bump version to v{{ VERSION }}" +# Create a GitHub release containing the latest changes +release-latest-version version: + #!/usr/bin/env bash + set -euxo pipefail + PREVIOUS_RELEASE=$(gh release list --json name,isLatest --jq '.[] | select(.isLatest)|.name') + CURRENT_RELEASE="v{{ version }}" + CHANGES=$(sed -n "/^## \[{{ version }}]/,/^## \[[0-9].*\]/ {//!p}" {{ CHANGELOG_FILE }}) + RELEASE_NOTES=" + ## What's Changed + + $CHANGES + + **Full Changelog**: {{ REPO_URL }}/compare/$PREVIOUS_RELEASE...$CURRENT_RELEASE + " + + gh release create $CURRENT_RELEASE --latest --title $CURRENT_RELEASE --notes-file - <<< "$RELEASE_NOTES" + # Publish the crate publish: _validate_version_tag cargo publish --no-verify +# Check that Git has a clean working directory +_check_clean_working: + test -z "$(git status --porcelain)" || (echo "The working directory is not clean"; exit 1) + # Validate that the crate version matches that of the git tag _validate_version_tag: #!/usr/bin/env bash @@ -62,3 +83,19 @@ _install_llvm_cov $run: if [ $run == true ] && [ $CI = false ]; then cargo install cargo-llvm-cov --locked fi + +# Update the changelog with a new version +_changelog_add_version version filename=CHANGELOG_FILE: + #!/usr/bin/env bash + set -euxo pipefail + PREV_VERSION=$(sed -n "/^\[unreleased\]:/ { n; s/^\[\([^]]*\)\].*/\1/p }" {{ filename }}) + + sed -i "/^## \[Unreleased\]$/ { N; s/\n/\n\n## [{{ version }}] - {{ datetime('%Y-%m-%d') }}\n/ }" {{ filename }} + sed -i "/^\[unreleased\]:/ s/v[0-9.]\+\b/v{{ version }}.../; /^\[unreleased\]:/ a\ + [{{ version }}]: {{ REPO_URL }}/compare/v$PREV_VERSION...v{{ version }}" {{ filename }} + + git add {{ filename }} + git commit -m "Update {{ filename }}" + +_bump_version_pr version: + gh pr create --title "Bump version to v{{ version }}" --body ""