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