From: Sergey Matveev Date: Wed, 16 Aug 2023 06:52:40 +0000 (+0300) Subject: .ziphash X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5c3c85f9c5193436b7a69c346dfa6193378fd4126bed4323b3ea4fe51898dde1;p=prepro.git .ziphash --- diff --git a/build b/build new file mode 100755 index 0000000..63cf534 --- /dev/null +++ b/build @@ -0,0 +1,5 @@ +#!/bin/sh -e + +for cmd in zip-create zip-hash ; do + go build -C cmd/$cmd -o $PWD/$cmd -ldflags=-s +done diff --git a/main.go b/cmd/zip-create/main.go similarity index 100% rename from main.go rename to cmd/zip-create/main.go diff --git a/cmd/zip-hash/main.go b/cmd/zip-hash/main.go new file mode 100644 index 0000000..69c448f --- /dev/null +++ b/cmd/zip-hash/main.go @@ -0,0 +1,16 @@ +package main + +import ( + "log" + "os" + + "golang.org/x/mod/sumdb/dirhash" +) + +func main() { + hsh, err := dirhash.HashZip(os.Args[1], dirhash.DefaultHash) + if err != nil { + log.Fatal(err) + } + os.Stdout.WriteString(hsh + "\n") +} diff --git a/mk-mod b/mk-mod index ba13815..dc83c8b 100755 --- a/mk-mod +++ b/mk-mod @@ -12,7 +12,9 @@ mkdir -p $dst cd $dst [[ -s $version.zip ]] && exit -prepro=$0:h:a/prepro +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]} @@ -25,8 +27,9 @@ done [[ -n $sec ]] strftime -s when %Y-%m-%dT%H:%M:%SZ $sec -$prepro -vcs $vcspath -mod $modname -version $version > $version.zip +$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 +touch -d $when $version.info $version.mod $version.zip $version.ziphash