#!/usr/bin/env zsh set -e vcsurl=$1 vcspath=$2 modname=$3 version=$4 signkey=$5 dst=$modname/@v mkdir -p $dst cd $dst [[ -s $version.zip ]] && exit root=$0:h:a zipcreate=$root/zip-create ziphash=$root/zip-hash zmodload -F zsh/datetime b:strftime git -C $vcspath cat-file -p $version | while read line ; do [[ $line =~ ^object ]] && hsh=${${=line}[-1]} [[ $line =~ ^tagger ]] && { strftime -s sec -r "%s %z" "${${=line}[-2,-1]}" break } done [[ -n $hsh ]] [[ -n $sec ]] strftime -s when %Y-%m-%dT%H:%M:%SZ $sec $zipcreate -vcs $vcspath -mod $modname -version $version > $version.zip $ziphash $version.zip > $version.ziphash unzip -p $version.zip ${modname}@${version}/go.mod > $version.mod printf '{"Version":"%s","Time":"%s","Origin":{"VCS":"git","URL":"%s","Ref":"refs/tags/%s","Hash":"%s"}}' \ $version $when $vcsurl $version $hsh > $version.info totouch=($version.info $version.mod $version.zip $version.ziphash) [[ -z $signkey ]] || { ssh-keygen -Y sign -f $signkey -n file $version.ziphash totouch=($totouch $version.ziphash.sig) } touch -d $when $totouch