]> Cypherpunks.ru repositories - prepro.git/blob - mk-mod
Separate .zip and .ziphash.sig steps for assurrance
[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
10 dst=$modname/@v
11 mkdir -p $dst
12 cd $dst
13 [[ ! -s $version.zip ]] || exit 0
14
15 root=$0:h:a
16 zipcreate=$root/zip-create
17 ziphash=$root/zip-hash
18 zmodload -F zsh/datetime b:strftime
19 git -C $vcspath cat-file -p $version | while read line ; do
20     [[ ! $line =~ ^object ]] || hsh=${${=line}[-1]}
21     [[ ! $line =~ ^tagger ]] || {
22         strftime -s sec -r "%s %z" "${${=line}[-2,-1]}"
23         break
24     }
25 done
26 [[ -n $hsh ]]
27 [[ -n $sec ]]
28 strftime -s when %Y-%m-%dT%H:%M:%SZ $sec
29
30 $zipcreate -vcs $vcspath -mod $modname -version $version > $version.zip
31 $ziphash $version.zip > $version.ziphash
32 unzip -p $version.zip ${modname}@${version}/go.mod > $version.mod
33 printf '{"Version":"%s","Time":"%s","Origin":{"VCS":"git","URL":"%s","Ref":"refs/tags/%s","Hash":"%s"}}' \
34     $version $when $vcsurl $version $hsh > $version.info
35 touch -d $when $version.info $version.mod $version.zip $version.ziphash