mdcat 0.22.1

cat for markdown: Show markdown documents in terminals
Documentation
#!/bin/bash
# Copyright 2019-2020 Sebastian Wiesnser <sebastian@swsnr.de>

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

set -e

next_version="$1"
if [[ -z "${next_version}" ]]; then
    echo "Next version missing; aborting"
    exit 1
fi

changes="$(git status --porcelain)"
if [[ -n "${changes}" ]]; then
    git status
    echo "Working directory not clean; aborting"
    exit 1
fi

if [[ "$(git symbolic-ref --short HEAD)" != "main" ]]; then
    echo "Not on main branch; aborting"
    exit 1
fi

ci_status="$(hub ci-status HEAD || true)"
if [[ "${ci_status}" != "success" ]]; then
    echo "CI for HEAD pending or failed (${ci_status}); aborting"
    exit 1
fi

latest_version="$(git tag --sort '-v:refname' | grep '^mdcat-' | head -n1 | cut -d'-' -f2)"
release_date="$(date +%Y-%m-%d)"

# Substitute version in Cargo.toml
sed -i'' "1,/^version =/ s/^version = .*$/version = \"${next_version}\"/" Cargo.toml
# Make cargo update the version in the lockfile as well
cargo metadata --format-version 1 >/dev/null
# Add both files to Git
git add Cargo.toml Cargo.lock

# Substitute version and release date in manpage
sed -i'' "1,/^:revnumber:/ s/^:revnumber: .*$/:revnumber: ${next_version}/" mdcat.1.adoc
sed -i'' "1,/^:revdate:/ s/^:revdate: .*$/:revdate: ${release_date}/" mdcat.1.adoc
git add mdcat.1.adoc

# Update the changelog:
# 1. Append a headline for the current version right after [Unreleased] headline
# 2. Append link references for the new version and the new unreleased version
# 3. Delete the old link reference for the Unreleased header
sed -e "/^## \[Unreleased\]\$/ a\\
\\
## [${next_version}] – ${release_date}" \
    -e "\$a\\
[${next_version}]: https://github.com/lunaryorn/mdcat/compare/mdcat-${latest_version}...mdcat-${next_version}\\
[Unreleased]: https://github.com/lunaryorn/mdcat/compare/mdcat-${next_version}...HEAD" \
    -e '/^\[Unreleased\]:/ D' \
    -i'' CHANGELOG.md
git add CHANGELOG.md

git commit -m "Release ${next_version}"
git tag -m "mdcat ${next_version}" "mdcat-${next_version}"
cargo publish --no-verify
git push --follow-tags origin main