From d0b27211928f93f8455e1ee5a6a6485c6a21d382 Mon Sep 17 00:00:00 2001
From: Jack Wills <32690432+mrjackwills@users.noreply.github.com>
Date: Sat, 13 Jan 2024 13:31:53 +0000
Subject: [PATCH] chore: create_release check for unused lint
---
create_release.sh | 144 +++++++++++++++++++++++++---------------------
1 file changed, 77 insertions(+), 67 deletions(-)
diff --git a/create_release.sh b/create_release.sh
index a66b1c1..f3c90c2 100755
--- a/create_release.sh
+++ b/create_release.sh
@@ -1,7 +1,7 @@
#!/bin/bash
# rust create_release
-# v0.3.1
+# v0.4.1
STAR_LINE='****************************************'
CWD=$(pwd)
@@ -12,15 +12,14 @@ YELLOW='\033[0;33m'
PURPLE='\033[0;35m'
RESET='\033[0m'
-
# $1 string - error message
error_close() {
- echo -e "\n${RED}ERROR - EXITED: ${YELLOW}$1${RESET}\n";
+ echo -e "\n${RED}ERROR - EXITED: ${YELLOW}$1${RESET}\n"
exit 1
}
# $1 string - question to ask
-ask_yn () {
+ask_yn() {
printf "%b%s? [y/N]:%b " "${GREEN}" "$1" "${RESET}"
}
@@ -30,19 +29,19 @@ user_input() {
echo "$data"
}
-update_major () {
+update_major() {
local bumped_major
bumped_major=$((MAJOR + 1))
echo "${bumped_major}.0.0"
}
-update_minor () {
+update_minor() {
local bumped_minor
bumped_minor=$((MINOR + 1))
echo "${MAJOR}.${bumped_minor}.0"
}
-update_patch () {
+update_patch() {
local bumped_patch
bumped_patch=$((PATCH + 1))
echo "${MAJOR}.${MINOR}.${bumped_patch}"
@@ -56,8 +55,7 @@ get_git_remote_url() {
# Check that git status is clean
check_git_clean() {
GIT_CLEAN=$(git status --porcelain)
- if [[ -n $GIT_CLEAN ]]
- then
+ if [[ -n $GIT_CLEAN ]]; then
error_close "git dirty"
fi
}
@@ -66,8 +64,7 @@ check_git_clean() {
check_git() {
CURRENT_GIT_BRANCH=$(git branch --show-current)
check_git_clean
- if [[ ! "$CURRENT_GIT_BRANCH" =~ ^dev$ ]]
- then
+ if [[ ! "$CURRENT_GIT_BRANCH" =~ ^dev$ ]]; then
error_close "not on dev branch"
fi
}
@@ -79,8 +76,7 @@ ask_changelog_update() {
printf "%s" "$RELEASE_BODY_TEXT"
printf "\n%s\n" "${STAR_LINE}"
ask_yn "accept release body"
- if [[ "$(user_input)" =~ ^y$ ]]
- then
+ if [[ "$(user_input)" =~ ^y$ ]]; then
update_release_body_and_changelog "$RELEASE_BODY_TEXT"
else
exit
@@ -89,17 +85,17 @@ ask_changelog_update() {
# Edit the release-body to include new lines from changelog
# add commit urls to changelog
-# $1 RELEASE_BODY
-update_release_body_and_changelog () {
+# $1 RELEASE_BODY
+update_release_body_and_changelog() {
echo -e
DATE_SUBHEADING="### $(date +'%Y-%m-%d')\n\n"
RELEASE_BODY_ADDITION="${DATE_SUBHEADING}$1"
# Put new changelog entries into release-body, add link to changelog
- echo -e "${RELEASE_BODY_ADDITION}\n\nsee CHANGELOG.md for more details" > .github/release-body.md
+ echo -e "${RELEASE_BODY_ADDITION}\n\nsee CHANGELOG.md for more details" >.github/release-body.md
# Add subheading with release version and date of release
- echo -e "# ${NEW_TAG_WITH_V}\n${DATE_SUBHEADING}${CHANGELOG_ADDITION}$(cat CHANGELOG.md)" > CHANGELOG.md
+ echo -e "# ${NEW_TAG_WITH_V}\n${DATE_SUBHEADING}${CHANGELOG_ADDITION}$(cat CHANGELOG.md)" >CHANGELOG.md
# Update changelog to add links to commits [hex:8](url_with_full_commit)
# "[aaaaaaaaaabbbbbbbbbbccccccccccddddddddd]" -> "[aaaaaaaa](https:/www.../commit/aaaaaaaaaabbbbbbbbbbccccccccccddddddddd)"
@@ -111,20 +107,19 @@ update_release_body_and_changelog () {
}
# update version in cargo.toml, to match selected current version
-update_version_number_in_files () {
+update_version_number_in_files() {
sed -i "s|^version = .*|version = \"${MAJOR}.${MINOR}.${PATCH}\"|" Cargo.toml
}
# Work out the current version, based on git tags
# create new semver version based on user input
# Set MAJOR MINOR PATCH
-check_tag () {
+check_tag() {
LATEST_TAG=$(git describe --tags "$(git rev-list --tags --max-count=1)")
echo -e "\nCurrent tag: ${PURPLE}${LATEST_TAG}${RESET}\n"
echo -e "${YELLOW}Choose new tag version:${RESET}\n"
- if [[ $LATEST_TAG =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$ ]]
- then
- IFS="." read -r MAJOR MINOR PATCH <<< "${LATEST_TAG:1}"
+ if [[ $LATEST_TAG =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$ ]]; then
+ IFS="." read -r MAJOR MINOR PATCH <<<"${LATEST_TAG:1}"
else
MAJOR="0"
MINOR="0"
@@ -134,51 +129,53 @@ check_tag () {
OP_MINOR="minor___v$(update_minor)"
OP_PATCH="patch___v$(update_patch)"
OPTIONS=("$OP_MAJOR" "$OP_MINOR" "$OP_PATCH")
- select choice in "${OPTIONS[@]}"
- do
+ select choice in "${OPTIONS[@]}"; do
case $choice in
- "$OP_MAJOR" )
- MAJOR=$((MAJOR + 1))
- MINOR=0
- PATCH=0
- break;;
- "$OP_MINOR")
- MINOR=$((MINOR + 1))
- PATCH=0
- break;;
- "$OP_PATCH")
- PATCH=$((PATCH + 1))
- break;;
- *)
- error_close "invalid option $REPLY"
+ "$OP_MAJOR")
+ MAJOR=$((MAJOR + 1))
+ MINOR=0
+ PATCH=0
+ break
+ ;;
+ "$OP_MINOR")
+ MINOR=$((MINOR + 1))
+ PATCH=0
+ break
+ ;;
+ "$OP_PATCH")
+ PATCH=$((PATCH + 1))
+ break
+ ;;
+ *)
+ error_close "invalid option $REPLY"
+ ;;
esac
done
}
# ask continue, or quit
-ask_continue () {
+ask_continue() {
ask_yn "continue"
- if [[ ! "$(user_input)" =~ ^y$ ]]
- then
+ if [[ ! "$(user_input)" =~ ^y$ ]]; then
exit
fi
}
# run all tests
-cargo_test () {
+cargo_test() {
cargo test -- --test-threads=1
ask_continue
}
# Simulate publishing to crates.io
-cargo_publish () {
+cargo_publish() {
cargo publish --dry-run
ask_continue
}
# Build all releases that GitHub workflow would
# This will download GB's of docker images
-cargo_build () {
+cargo_build() {
cargo install cross
cargo_clean
echo -e "${YELLOW}cross build --target x86_64-unknown-linux-musl --release${RESET}"
@@ -199,9 +196,8 @@ cargo_build () {
cargo_clean
}
-
# $1 text to colourise
-release_continue () {
+release_continue() {
echo -e "\n${PURPLE}$1${RESET}"
ask_continue
}
@@ -212,14 +208,26 @@ cargo_clean() {
cargo clean
}
# Check repository for typos
-check_typos () {
+check_typos() {
echo -e "\n${PURPLE}check typos${RESET}"
typos
ask_continue
}
+# Make sure the unused lint isn't used
+check_allow_unsued() {
+ matches_any=$(find . -type d \( -name .git -o -name target \) -prune -o -type f -exec grep -lE '^#!\[allow\(unused\)\]$' {} +)
+ matches_cargo=$(grep "^unused = \"allow\"" ./Cargo.toml)
+ if [ -n "$matches_any" ]; then
+ error_close "\"#[allow(unused)]\" in ${matches_any}"
+ elif [ -n "$matches_cargo" ]; then
+ error_close "\"unsed = \"allow\"\" in Cargo.toml"
+ fi
+}
+
# Full flow to create a new release
release_flow() {
+ check_allow_unsued
check_typos
check_git
@@ -231,20 +239,20 @@ release_flow() {
cd "${CWD}" || error_close "Can't find ${CWD}"
check_tag
-
+
NEW_TAG_WITH_V="v${MAJOR}.${MINOR}.${PATCH}"
printf "\nnew tag chosen: %s\n\n" "${NEW_TAG_WITH_V}"
RELEASE_BRANCH=release-$NEW_TAG_WITH_V
echo -e
ask_changelog_update
-
+
release_continue "checkout ${RELEASE_BRANCH}"
git checkout -b "$RELEASE_BRANCH"
release_continue "update_version_number_in_files"
update_version_number_in_files
-
+
echo -e "\ncargo fmt"
cargo fmt
echo -e "\n${PURPLE}cargo check${RESET}\n"
@@ -283,7 +291,6 @@ release_flow() {
git branch -d "$RELEASE_BRANCH"
}
-
main() {
cmd=(dialog --backtitle "Choose option" --radiolist "choose" 14 80 16)
options=(
@@ -297,24 +304,27 @@ main() {
if [ $exitStatus -ne 0 ]; then
exit
fi
- for choice in $choices
- do
+ for choice in $choices; do
case $choice in
- 0)
- exit;;
- 1)
- cargo_test
- main
- break;;
- 2)
- release_flow
- break;;
- 3)
- cargo_build
- main
- break;;
+ 0)
+ exit
+ ;;
+ 1)
+ cargo_test
+ main
+ break
+ ;;
+ 2)
+ release_flow
+ break
+ ;;
+ 3)
+ cargo_build
+ main
+ break
+ ;;
esac
done
}
-main
\ No newline at end of file
+main