Skip to content

Commit

Permalink
Merge pull request #199 from lidel/checksums
Browse files Browse the repository at this point in the history
Publish checksums for every artifact
  • Loading branch information
dignifiedquire authored Nov 1, 2018
2 parents 7a4a482 + 4709b3f commit 53ef3f9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
25 changes: 19 additions & 6 deletions build-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ function pkgType() {
esac
}

function printDistInfo() {
function buildDistInfo() {
local bundle="$1"
local version="$2"
local dir="$2"

# print json output
jq -e ".platforms[\"$goos\"]" dist.json > /dev/null
Expand All @@ -57,9 +57,15 @@ function printDistInfo() {
jq ".platforms[\"$goos\"] = {\"name\":\"$goos Binary\",\"archs\":{}}" dist.json.temp > dist.json
fi

local linkname="$version/$bundle.`pkgType $goos`"
local linkname="$bundle.`pkgType $goos`"
# Calculate sha512 and write it to .sha512 file
shasum -a 512 $dir/$linkname | awk "{gsub(\"${dir}/\", \"\");print}" > $dir/$linkname.sha512
local linksha512=$(cat $dir/$linkname.sha512 | awk '{ print $1 }')
# Calculate CID and write it to .cid file
ipfs add --only-hash -Q $dir/$linkname > $dir/$linkname.cid
local linkcid=$(cat $dir/$linkname.cid)
cp dist.json dist.json.temp
jq ".platforms[\"$goos\"].archs[\"$goarch\"] = {\"link\":\"$linkname\"}" dist.json.temp > dist.json
jq ".platforms[\"$goos\"].archs[\"$goarch\"] = {\"link\":\"/$linkname\",\"cid\":\"$linkcid\",\"sha512\":\"$linksha512\"}" dist.json.temp > dist.json
rm dist.json.temp
}

Expand Down Expand Up @@ -103,7 +109,7 @@ function doBuild() {

# now package it all up
if bundleDist $dir/$binname $goos $build_dir_name; then
printDistInfo $binname
buildDistInfo $binname $dir
rm -rf $build_dir_name
else
warn " failed to zip up output"
Expand Down Expand Up @@ -233,8 +239,15 @@ function buildSource() {

cp "$reporoot/$target" "$output"

# Calculate sha512 and write it to .sha512 file
shasum -a 512 $output/$target | awk "{gsub(\"${output}/\", \"\");print}" > $output/$target.sha512
local linksha512=$(cat $output/$target.sha512 | awk '{ print $1 }')
# Calculate CID and write it to .cid file
ipfs add --only-hash -Q $output/$target > $output/$target.cid
local linkcid=$(cat $output/$target.cid)

cp dist.json dist.json.temp
jq ".source = {\"link\": \"/$target\"}" dist.json.temp > dist.json
jq ".source = {\"link\": \"/$target\",\"cid\":\"$linkcid\",\"sha512\":\"$linksha512\"}" dist.json.temp > dist.json
rm dist.json.temp
}

Expand Down
6 changes: 6 additions & 0 deletions deps-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ function fail() {
exit 1
}

(ipfs version > /dev/null 2>&1) || (fail "Missing ipfs, please install it :-)")
(awk --version > /dev/null 2>&1) || (fail "Missing awk, please install it")
(date | shasum -a 512 - > /dev/null 2>&1) || (fail "Missing shasum with sha512 support, please install it")

(hugo version > /dev/null 2>&1) || (fail "Missing hugo, please see https://gohugo.io/")

(node --version > /dev/null 2>&1) || (fail "Missing node.js, please see https://nodejs.org/")
Expand All @@ -13,4 +17,6 @@ function fail() {

(yarn --version > /dev/null 2>&1) || (fail "Missing yarn, please install with `npm i -g yarn`")

(jq --version > /dev/null 2>&1) || (fail "Missing jq, please see https://stedolan.github.io/jq/")

exec yarn

0 comments on commit 53ef3f9

Please sign in to comment.