diff --git a/resources/scripts/bump-version.sh b/resources/scripts/bump-version.sh new file mode 100755 index 000000000..26343109b --- /dev/null +++ b/resources/scripts/bump-version.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# See usage() for usage + +source "$(dirname -- "$0";)/rel-common.sh" + +# Helpers +function usage() { + echo "Usage: ./bump-version.sh crate1 crate2 crateN bump" + echo " ./bump-version.sh read-fonts write-fonts patch" + echo " ./bump-version.sh {read,write}-fonts patch" + echo "bump is as defined by cargo release: major minor or patch" +} + +# What is it you want us to do? +if [ $# -eq 0 ]; then + die_with_usage "No arguments provided, must specify crate(s)" +fi + +# bump is the last argument, crate list is everythign else +bump="${@:$#}" +set -- "${@:1:$(($#-1))}" +crates=("$@") + +# Validate +[[ "$bump" =~ ^(major|minor|patch)$ ]] || die_with_usage "Invalid bump, must be major, minor, or patch" + +validate_crates "${crates[@]}" + +# Do the thing. We set errexit so step failure should break us out. +for crate in "${crates[@]}" +do + cargo release version "${bump}" -p "${crate}" -x +done + +echo "NEXT STEPS" +echo "Commit these changes to a new branch, get it approved and merged, and switch to the up-to-date main." \ No newline at end of file diff --git a/resources/scripts/check_no_println.sh b/resources/scripts/check_no_println.sh deleted file mode 100755 index ab79b79d5..000000000 --- a/resources/scripts/check_no_println.sh +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/env bash - -# Script to check for println! or eprintln! in Rust files, ignoring comments. -# -# When no args are provided, all the git-tracked *.rs files are searched. -# When run with two args, respectively --from-ref and --to-ref , -# only the added lines from the git diff between the two refs are searched. -# The latter is useful when running this as a pre-push git hook. - - -grep_rust_lines_with_prints() { - for file in $(git ls-files '*.rs'); do - # Strip all inline comments - sed -e 's://.*$::' "$file" | \ - # Prepend the file name and line number to each line, with colors - awk -v file="$file" '{ printf "\033[35m%s\033[0m:\033[32m%s\033[0m: %s\n", file, FNR, $0 }' | \ - # Grep for print statements - grep --color=always -E '\b(println!|eprintln!)' || true - done -} - -diff_rust_lines_with_prints() { - local from_ref="$1" - local to_ref="${2:-HEAD}" - # --diff-filter=A is to list only added files, excluding modified/deleted - git diff "$from_ref" "$to_ref" --name-only --diff-filter=A | \ - grep '\.rs$' | \ - while read -r file; do - # For each file, get a unified diff with no context (-U0) - git diff "$from_ref" "$to_ref" -U0 -- "$file" | \ - # Strip lines starting with '+++' containing the file name - grep -v -E '^\+\+\+' | \ - # Select only the added lines, i.e. starting with a plus sign - grep -E '^\+' | \ - # Strip the '+' prefix and the inline comments - sed -e 's/^\+//' -e 's://.*$::' | \ - # Prepend the file name and line number to each line, with colors - awk -v file="$file" '{ printf "\033[35m%s\033[0m:\033[32m%s\033[0m: %s\n", file, FNR, $0 }' | \ - # Grep for print statements - grep --color=always -E '\b(println!|eprintln!)' || true - done -} - - -opt_error() { - local message="$1" - echo "Error: $message" - echo "Usage: $0 [--from-ref ] [--to-ref ]" - exit 1 -} - - -if [ $# -eq 0 ]; then - # when no arguments are passed, search all git-tracked files - matches=$(grep_rust_lines_with_prints) -else - from_ref="" - to_ref="" - while [ $# -gt 0 ]; do - case "$1" in - --from-ref) - from_ref="$2" - shift 2 - ;; - --to-ref) - to_ref="${2:-HEAD}" - shift 2 - ;; - *) - opt_error "Unknown option: $1" - ;; - esac - done - - if [ -z "$from_ref" ] || [ -z "$to_ref" ]; then - opt_error "both --from-ref and --to-ref must be provided, or none at all." - fi - - matches=$(diff_rust_lines_with_prints "$from_ref" "$to_ref") -fi - -if [ ! -z "$matches" ]; then - echo "Error: The following Rust source files contain println! or eprintln! statements:" - echo "$matches" - echo "Please remove or comment out the println! and eprintln! statements before pushing." - exit 1 -fi -exit 0 diff --git a/resources/scripts/release.sh b/resources/scripts/release.sh new file mode 100755 index 000000000..79344df77 --- /dev/null +++ b/resources/scripts/release.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# See usage() for usage + +source "$(dirname -- "$0";)/rel-common.sh" + +# Helpers +function usage() { + echo "Usage:" + echo " # release everything changed" + echo " ./release.sh" + echo + echo " # release one crate" + echo " ./release.sh write-fonts" + echo + echo "Typically you should be running this after bump-version.sh" +} + +# What is it you want us to do? +if [ $# -gt 1 ]; then + die_with_usage "Specify 0 - meaning all - or 1 packages" +fi +crate_specifier="" +if [ $# -eq 1 ]; then + crates=("$@") + validate_crates "${crates[@]}" + crate_specifier="-p ${crates[0]}" +fi + +# Do the thing. We set errexit so step failure should break us out. + +echo "Dry run..." +cargo release publish ${crate_specifier} + +echo "Doing the thing; ${COLOR_RED}PRESS CTRL+C if anything looks suspicious${TEXT_RESET}" + +echo "Publish to crates.io" +cargo release publish -x ${crate_specifier} # this prompts y/N +echo "Generate tags" +cargo release tag -x ${crate_specifier} # this prompts y/N +echo "Pushing tag to github" +git push --tags + +echo "NEXT STEPS" +echo "You probably want to create a release on github"