Skip to content

Commit 3899517

Browse files
committed
update release.yml to generate binaries.json
1 parent 88ea162 commit 3899517

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

.github/workflows/release.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,58 @@ jobs:
5454
run: cat build/release/checksum.txt
5555
- name: Upload the checksum to release
5656
run: gh release upload ${{github.ref_name}} build/release/checksum.txt --repo ${{github.repository}}
57+
58+
generate-json:
59+
needs: calculate-checksums
60+
env:
61+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
if: startsWith(github.ref, 'refs/tags/')
63+
runs-on: ubuntu-latest
64+
steps:
65+
- name: Install jq
66+
run: sudo apt-get update && sudo apt-get install -y jq
67+
- name: Create build directory
68+
run: mkdir -p build/release
69+
- name: Download artifacts
70+
run: gh release download ${{github.ref_name}} --pattern '*.tar.gz' --dir build/release --repo ${{github.repository}}
71+
- name: Generate JSON file
72+
run: |
73+
cd build/release
74+
binaries=()
75+
for file in *.tar.gz; do
76+
checksum=$(sha256sum $file | awk '{print $1}')
77+
url="https://github.com/${{github.repository}}/releases/download/${{github.ref_name}}/$file?checksum=sha256:$checksum"
78+
declare -A TRANSLATION_MATRIX
79+
TRANSLATION_MATRIX=( ["Linux_x86_64"]="linux/amd64" ["Linux_arm64"]="linux/arm64" ["Darwin_arm64"]="darwin/arm64" )
80+
os_architecture_translated=""
81+
for key in "${!TRANSLATION_MATRIX[@]}"; do
82+
if [[ "$file" == *"$key"* ]]; then
83+
os_architecture_translated="${TRANSLATION_MATRIX[$key]}"
84+
break
85+
fi
86+
done
87+
if [ -z "$os_architecture_translated" ]
88+
then
89+
echo "Could not translate OS and architecture information from binary name: $file"
90+
exit 1
91+
fi
92+
binaries+=(" \"$os_architecture_translated\": \"$url\"")
93+
done
94+
binaries_json=$(IFS=$',\n'; echo "${binaries[*]}")
95+
cat << EOF > binaries.json.raw
96+
{
97+
"binaries": {
98+
$binaries_json
99+
}
100+
}
101+
EOF
102+
103+
- name: Pretty-print JSON file using jq
104+
run: |
105+
cd build/release
106+
jq . < binaries.json.raw > binaries.json && rm binaries.json.raw
107+
108+
- name: Display JSON file
109+
run: cat build/release/binaries.json
110+
- name: Upload the JSON file to release
111+
run: gh release upload ${{github.ref_name}} build/release/binaries.json --repo ${{github.repository}}

0 commit comments

Comments
 (0)