@@ -3,8 +3,8 @@ name: Release
33on :
44 push :
55 tags :
6- - ' v[0-9]+.[0-9]+.[0-9]+' # Push events to matching v*, i.e. v1.0, v20.15.10
7- - ' v[0-9]+.[0-9]+.[0-9]+-rc*' # Push events to matching v*, i.e. v1.0-rc1, v20.15.10-rc5
6+ - " v[0-9]+.[0-9]+.[0-9]+" # Push events to matching v*, i.e. v1.0, v20.15.10
7+ - " v[0-9]+.[0-9]+.[0-9]+-rc*" # Push events to matching v*, i.e. v1.0-rc1, v20.15.10-rc5
88
99jobs :
1010 release :
2424 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
2525 strategy :
2626 matrix :
27- build_type : [' build-release-arm64', ' build-release-amd64' ]
27+ build_type : [" build-release-arm64", " build-release-amd64" ]
2828 steps :
2929 - name : Checkout
3030 uses : actions/checkout@v3
5353 - name : Display checksums
5454 run : cat build/release/checksum.txt
5555 - name : Upload the checksum to release
56- run : gh release upload ${{github.ref_name}} build/release/checksum.txt --repo ${{github.repository}}
56+ 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