1
+ name : " Release"
2
+
3
+ on :
4
+ # can be used to re-release an existing tag
5
+ workflow_dispatch :
6
+
7
+ push :
8
+ tags :
9
+ - " v[0-9]+\\ .[0-9]+\\ .[0-9]+"
10
+ - " v[0-9]+\\ .[0-9]+\\ .[0-9]+-*"
11
+
12
+ jobs :
13
+ release :
14
+ env :
15
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
16
+ if : startsWith(github.ref, 'refs/tags/')
17
+ runs-on : ubuntu-latest
18
+ steps :
19
+ - name : Create release for ${{ github.ref_name }}
20
+ run : gh release create ${{ github.ref_name }} --prerelease --generate-notes --repo ${{ github.repository }}
21
+
22
+
23
+ artifacts :
24
+ if : startsWith(github.ref, 'refs/tags/')
25
+ needs : release
26
+ runs-on : ubuntu-latest
27
+ env :
28
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
29
+ strategy :
30
+ matrix :
31
+ build_type : ['build-release-arm64', 'build-release-amd64']
32
+ steps :
33
+ - name : Checkout
34
+ uses : actions/checkout@v3
35
+ - name : Set version tag
36
+ run : echo "VERSION=$(echo ${{ github.ref_name }} | sed 's/^v//')" >> $GITHUB_ENV
37
+ - name : Create build directory
38
+ run : mkdir -p build/release
39
+ - name : Build ${{ matrix.build_type }}
40
+ run : make ${{ matrix.build_type }}
41
+ - name : Upload the artifacts to release
42
+ run : gh release upload ${{ github.ref_name }} ./build/release/*
43
+
44
+ calculate-checksums :
45
+ needs : artifacts
46
+ env :
47
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
48
+ if : startsWith(github.ref, 'refs/tags/')
49
+ runs-on : ubuntu-latest
50
+ steps :
51
+ - name : Create build directory
52
+ run : mkdir -p build/release
53
+ - name : Download artifacts
54
+ run : gh release download ${{ github.ref_name }} --pattern '*.tar.gz' --dir build/release --repo ${{ github.repository }}
55
+ - name : Create checksums
56
+ run : |
57
+ cd build/release
58
+ sha256sum *.tar.gz > checksum.txt
59
+ - name : Display checksums
60
+ run : cat build/release/checksum.txt
61
+ - name : Upload the checksum to release
62
+ run : gh release upload ${{github.ref_name}} build/release/checksum.txt --repo ${{github.repository}}
63
+
64
+ generate-json :
65
+ needs : calculate-checksums
66
+ env :
67
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
68
+ if : startsWith(github.ref, 'refs/tags/')
69
+ runs-on : ubuntu-latest
70
+ steps :
71
+ - name : Install jq
72
+ run : sudo apt-get update && sudo apt-get install -y jq
73
+ - name : Create build directory
74
+ run : mkdir -p build/release
75
+ - name : Download artifacts
76
+ run : gh release download ${{github.ref_name}} --pattern '*.tar.gz' --dir build/release --repo ${{github.repository}}
77
+ - name : Generate JSON file
78
+ run : |
79
+ cd build/release
80
+ binaries=()
81
+ for file in *.tar.gz; do
82
+ checksum=$(sha256sum $file | awk '{print $1}')
83
+ url="https://github.com/${{github.repository}}/releases/download/${{github.ref_name}}/$file?checksum=sha256:$checksum"
84
+ declare -A TRANSLATION_MATRIX
85
+ TRANSLATION_MATRIX=( ["Linux_x86_64"]="linux/amd64" ["Linux_arm64"]="linux/arm64" ["Darwin_arm64"]="darwin/arm64" )
86
+ os_architecture_translated=""
87
+ for key in "${!TRANSLATION_MATRIX[@]}"; do
88
+ if [[ "$file" == *"$key"* ]]; then
89
+ os_architecture_translated="${TRANSLATION_MATRIX[$key]}"
90
+ break
91
+ fi
92
+ done
93
+ if [ -z "$os_architecture_translated" ]
94
+ then
95
+ echo "Could not translate OS and architecture information from binary name: $file"
96
+ exit 1
97
+ fi
98
+ binaries+=(" \"$os_architecture_translated\": \"$url\"")
99
+ done
100
+ binaries_json=$(IFS=$',\n'; echo "${binaries[*]}")
101
+ cat << EOF > binaries.json.raw
102
+ {
103
+ "binaries": {
104
+ $binaries_json
105
+ }
106
+ }
107
+ EOF
108
+
109
+ - name : Pretty-print JSON file using jq
110
+ run : |
111
+ cd build/release
112
+ jq . < binaries.json.raw > binaries.json && rm binaries.json.raw
113
+
114
+ - name : Display JSON file
115
+ run : cat build/release/binaries.json
116
+ - name : Upload the JSON file to release
117
+ run : gh release upload ${{ github.ref_name }} build/release/binaries.json --repo ${{ github.repository }}
0 commit comments