]> Cypherpunks.ru repositories - prepro.git/blob - mk-mod
6fb58f6951c81a767bbd8677cf20f4ab4c5ba4950f0bc37998106b96dcf5ced3
[prepro.git] / mk-mod
1 #!/usr/bin/env zsh
2
3 setopt ERR_EXIT
4
5 vcsurl=$1
6 vcspath=$2
7 modname=$3
8 version=$4
9 signkey=$5
10
11 dst=$modname/@v
12 mkdir -p $dst
13 cd $dst
14 [[ ! -s $version.zip ]] || exit 0
15
16 root=$0:h:a
17 zipcreate=$root/zip-create
18 ziphash=$root/zip-hash
19 zmodload -F zsh/datetime b:strftime
20 git -C $vcspath cat-file -p $version | while read line ; do
21     [[ ! $line =~ ^object ]] || hsh=${${=line}[-1]}
22     [[ ! $line =~ ^tagger ]] || {
23         strftime -s sec -r "%s %z" "${${=line}[-2,-1]}"
24         break
25     }
26 done
27 [[ -n $hsh ]]
28 [[ -n $sec ]]
29 strftime -s when %Y-%m-%dT%H:%M:%SZ $sec
30
31 $zipcreate -vcs $vcspath -mod $modname -version $version > $version.zip
32 $ziphash $version.zip > $version.ziphash
33 unzip -p $version.zip ${modname}@${version}/go.mod > $version.mod
34 printf '{"Version":"%s","Time":"%s","Origin":{"VCS":"git","URL":"%s","Ref":"refs/tags/%s","Hash":"%s"}}' \
35     $version $when $vcsurl $version $hsh > $version.info
36 totouch=($version.info $version.mod $version.zip $version.ziphash)
37 [[ -z $signkey ]] || {
38     ssh-keygen -Y sign -f $signkey -n file $version.ziphash
39     totouch=($totouch $version.ziphash.sig)
40 }
41 touch -d $when $totouch