-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpush_release.sh
More file actions
executable file
·49 lines (42 loc) · 1.76 KB
/
push_release.sh
File metadata and controls
executable file
·49 lines (42 loc) · 1.76 KB
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
#!/usr/bin/env bash
set -e
if [ "$#" -ne 2 ]; then
echo "Some parameters [GIT_TAG, GIT_REPO] were not provided"
exit
fi
GIT_TAG=$1
GIT_REPO=$2
CREATE_RELEASE_DATA='{
"tag_name": "'"${GIT_TAG}"'",
"target_commitish": "main",
"name": "'"${GIT_TAG}"'",
"body": "release-'"${GIT_TAG}"'",
"draft": false,
"prerelease": false
}'
echo "Creating a new release: $GIT_TAG branch: main"
RESPONSE=$(curl -s --data "${CREATE_RELEASE_DATA}" -H "Authorization: token ${GITHUB_TOKEN}" "https://api.github.com/repos/$GIT_REPO/releases")
ASSET_UPLOAD_URL=$(echo "$RESPONSE" | jq -r .upload_url | cut -d '{' -f1)
if [ -z "$ASSET_UPLOAD_URL" ]; then
echo ${RESPONSE}
exit 1
fi
# modify index.yaml, add created\digest field
if [ ! -f toCopy/index.yaml ]; then
echo "index.yaml does not exist"
exit 1
fi
timestamp=$(date "+%Y-%m-%d %H:%M:%S")
for FILE in `ls toCopy/*.tgz`; do
sha=$(sha256sum $FILE | awk '{ print $1 }') # FILE Example: toCopy/minio-2023.tgz
FILE=${FILE%%.tgz*} # remove ".tgz", Example: toCopy/minio-2023
addonVersion=${FILE##*toCopy/} # remove "path, Example: minio-2023
addon=${addonVersion%-*} # remove after "-" , Example: minio
version=${addonVersion##*-} # remove before "-", Example: 2023
a=$addon v=$version t=$timestamp yq -i '(.entries.[env(a)][] | select(.version == env(v)) | .created) = env(t)' toCopy/index.yaml
a=$addon v=$version s=$sha yq -i '(.entries.[env(a)][] | select(.version == env(v)) | .digest) = env(s)' toCopy/index.yaml
done
for FILE in toCopy/*; do
echo "Uploading asset: $FILE to url: $ASSET_UPLOAD_URL?name=${FILE}"
curl -s --data-binary @${FILE} -H "Content-Type: application/octet-stream" -H "Authorization: token ${GITHUB_TOKEN}" -X POST "$ASSET_UPLOAD_URL?name=$(basename ${FILE})"
done