#!/usr/bin/env -S bash -e # # Copyright 2020 ALT-TEKNIK LLC # Parse arguments gitea_domain=git.alt-tek.com unset version while [[ $# -gt 0 ]] do arg=$1 shift case $arg in -h|--help) IFS= read -rd '' usage << __eof__ || true Usage: release [-h] version Builds a release and uploads it to $gitea_domain as a draft Positional arguments: version The release version Optional arguments: -h, --help Show this help message and exit __eof__ echo -n "$usage" exit 0 ;; -*|--*) echo "Invalid argument '$arg'. Use -h for help." >&2 exit 1 ;; *) if [[ -v version ]] then echo "Invalid argument '$arg'. Use -h for help." >&2 exit 1 fi version=$arg esac done if [[ -z $version ]] then echo 'Missing version argument. Use -h for help.' >&2 exit 1 fi # Initialize globals used by handle-trap signals='INT TERM' unset tmp_dir prj_name=2x10-dip-adapter tea_login=$prj_name-release # Usage: handle-trap [exit_code] # # Deletes temporary files and logs out of Tea upon script exit or signal # # Positional arguments: # exit_code Optional exit code for which to trigger a script exit function handle-trap { trap - EXIT $signals rm -rf "$tmp_dir" tea logout "$tea_login" if [[ $1 ]] then exit "$1" fi } # Set the trap trap handle-trap EXIT trap 'handle-trap 1' $signals # Create a temporary build directory tmp_dir=$(mktemp -d) # Git a clean clone repo=alt-tek/$prj_name git_dir=$tmp_dir/git git clone "$gitea_domain:$repo" "$git_dir" cd "$git_dir" tag=v$version git checkout "tags/$tag" -b "tmp/$tag-build" # Create the archive directory archive_name=${prj_name}_$version archive_dir=$tmp_dir/$archive_name mkdir "$archive_dir" # Generate board plots plot_dir=$git_dir/plots rm -rf "$plot_dir" ./plot.py "$version" cp "$plot_dir"/* "$archive_dir" # Tar and Gzip the archive archive=$tmp_dir/$archive_name.tar.gz tar -czf "$archive" -C "$tmp_dir" "$archive_name" # Draft the release tea_token=$(<"$HOME/.config/$gitea_domain/api-token") tea login add -n "$tea_login" -u "https://$gitea_domain" -t "$tea_token" title="Version $version" tea releases create -l "$tea_login" -r "$repo" --tag "$tag" -d -t "$title" \ -a "$archive" echo "Drafted $title at https://$gitea_domain/$repo/releases"