A script for updating quarks with automatic changelogs

Hello everyone

I recently wrote this neat little script that I now use to update my Quarks in a nice and consistent way. The script takes one argument which is the version number.

Running it will set a git tag, update the quark file with the new version, automatically generate a changelog and then commit these changes.

An example of the auto generated changelog can be seen here:

The auto generation of the changelog is done using a tool called git-cliff. This tool looks at all commits since the last tag, takes the ones that are written using the conventional commits style and then organizes and writes the changelog according to that. Pretty neat!

(config file here (which is basically just the vanilla config): madskjeldgaard/mk-synthlib: My SynthDef factory and library for SuperCollider - cliff.toml at main - mk-synthlib - Codeberg.org)

Ps. The script also depends on fd - you can exchange this for whatever in that line if you have a better way of finding the quark file in your project.

#!/usr/bin/bash
VERSION_NUMBER=$1
QUARK_FILE=$(fd .quark)

# Check input
if [[ -z $VERSION_NUMBER ]]; then echo "No version supplied" && exit 1; fi

# Changelog
function changelog(){
	if [[ -f "cliff.toml" ]]; then
		# git cliff --tag $VERSION_NUMBER
		git cliff --output CHANGELOG.md
	else
		echo "No git cliff config found. Generating cliff.toml now."
		git cliff --init
		# git cliff --tag $VERSION_NUMBER
		git cliff --output CHANGELOG.md
	fi
}

# Update quark file
function update_quark_file(){
	if [[ -f $QUARK_FILE ]]; then
		sed -i -e "s/version.*/version: \"$VERSION_NUMBER\",/g" "$QUARK_FILE"
	else
		echo "Cannot find quarks file: $QUARK_FILE" && exit 1
	fi
}

# Git tag
function update_tags(){
	echo "Updating git tag"
	git tag v$VERSION_NUMBER
}

# commit changes made by version system
function commit_version_changes(){
	echo "committing changes made by the version system"
	git commit $QUARK_FILE CHANGELOG.md -m "v$VERSION_NUMBER"
}

 update_quark_file && update_tags && changelog && commit_version_changes
3 Likes