Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish checksums for every artifact #199

Merged
merged 2 commits into from
Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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