Skip to content

Commit ccc5dae

Browse files
committed
Add new file for building binary json structure
1 parent df15035 commit ccc5dae

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

files/binary-json.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail
4+
5+
path=${1:-dist/}
6+
project=${2:-""}
7+
binary_name=${3:-""}
8+
9+
if [ -z "$path" ] || [ -z "$project" ] || [ -z "$binary_name" ]; then
10+
echo "Usage: $0 <path> <project> <binary_name>"
11+
exit 1
12+
fi
13+
14+
15+
json='[]'
16+
for bin in $(find "$path" -type f -name "$binary_name*"); do
17+
dir=$(basename "$(dirname $bin)")
18+
if [[ "$dir" =~ ${project}_([a-zA-Z0-9]+)_([a-zA-Z0-9]+) ]]; then
19+
os="${BASH_REMATCH[1]}"
20+
arch="${BASH_REMATCH[2]}"
21+
digest=$(sha256sum "$bin" | cut -d' ' -f1)
22+
json=$(echo "$json" | jq -c --arg path "$bin" --arg os "$os" --arg arch "$arch" --arg digest "$digest" '. += [{"path": $path, "os": $os, "arch": $arch, "digest": $digest}]')
23+
fi
24+
done
25+
echo "$json"

0 commit comments

Comments
 (0)