#!/usr/bin/env 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=bgtex 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 -n "$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" # Request a plot of the schematic sch_dir_name=schematic sch_dir=$tmp_dir/$sch_dir_name mkdir "$sch_dir" sch_basename=$prj_name.sch IFS= read -rd '' sch_instructions << __eof__ || true Opening $sch_basename with Eeschema... 1. From the 'File' menu, select 'Page Settings...' a. Set 'Issue Date' to '$(date +%Y.%m.%d)' b. Set 'Revision' to '$version' c. Press 'OK' 2. From the 'File' menu, select 'Plot...' a. Select 'PDF' for 'Output Format' b. Select 'Schematic size' for 'Page size' c. Enable 'Plot border and title block' d. Select 'Color' for 'Output mode' e. Set 'Default line width' to 6mils e. Set 'Output directory' to '../$sch_dir_name' f. Press 'Plot All Pages' g. Press 'Close' 3. From the 'Eeschema' menu, select 'Quit eeschema' a. Press 'Discard Changes' when prompted to save __eof__ echo -n "$sch_instructions" open -Wa eeschema "$git_dir/$sch_basename" cp "$sch_dir/$prj_name.pdf" "$archive_dir/$prj_name-schematic.pdf" echo "Plotted $sch_basename" # 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" tea releases create -l "$tea_login" -r "$repo" --tag "$tag" -d \ -t "Version $version" -a "$archive" echo "Drafted https://$gitea_domain/$repo/releases $tag"