#!/usr/bin/env zsh setopt ERR_EXIT vcsurl=$1 vcspath=$2 modname=$3 version=$4 dst=$modname/@v mkdir -p $dst cd $dst [[ ! -s $version.zip ]] || exit 0 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 touch -d $when $version.info $version.mod $version.zip $version.ziphash