sc-items/lib

71 lines
2.1 KiB
Plaintext
Raw Normal View History

2023-07-21 20:19:29 +00:00
#!/bin/bash
function create-archive(){
mkdir release
envsubst < module.json.template > ./module.json
cp ./module.json ./src/module.json
zip -r -9 ./release/module.zip ./src/*
}
function create-release(){
2023-07-21 20:33:54 +00:00
if [[ -z "${TAG}" ]]; then
2023-07-21 20:28:21 +00:00
echo "TAG key is not set"
2023-07-21 20:33:54 +00:00
exit
2023-07-21 20:19:29 +00:00
fi
2023-07-21 22:52:38 +00:00
if [[ $1 == 'latest' ]]; then
echo "Deleting old latest release"
RELEASE_LIST=$(curl -X GET -Url https://gitea.kdiva.ru/api/v1/repos/modules/sc-items/releases)
2023-07-21 22:53:58 +00:00
LATEST_RELEASE_ID=$(jq -r '.[] | select(.tag_name=="latest") | .id' <<< $RELEASE_LIST)
2023-07-21 22:52:38 +00:00
delete-release $LATEST_RELEASE_ID
fi
2023-07-21 20:19:29 +00:00
RESPONSE=$(curl \
-X 'POST' \
-Url "https://gitea.kdiva.ru/api/v1/repos/${DRONE_REPO}/releases" \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer 10e4af53e553aacb905766512e36487492d61a66' \
-d '{
"draft": false,
2023-07-21 21:21:02 +00:00
"name": "'"$1"'",
2023-07-21 20:19:29 +00:00
"prerelease": false,
2023-07-21 21:21:02 +00:00
"tag_name": "'"$1"'"
2023-07-21 20:19:29 +00:00
}')
2023-07-21 22:18:37 +00:00
}
function upload-attachments(){
2023-07-21 20:19:29 +00:00
RELEASE_ID=$(jq -r '.id' <<< $RESPONSE)
2023-07-21 20:32:38 +00:00
echo "RELEASE_ID is ${RELEASE_ID}"
2023-07-21 20:19:29 +00:00
curl \
2023-07-21 22:09:13 +00:00
-vv \
2023-07-21 20:19:29 +00:00
-X 'POST' \
2023-07-21 20:29:00 +00:00
-Url "https://gitea.kdiva.ru/api/v1/repos/${DRONE_REPO}/releases/${RELEASE_ID}/assets" \
2023-07-21 20:19:29 +00:00
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-H 'Authorization: Bearer 10e4af53e553aacb905766512e36487492d61a66' \
2023-07-21 22:18:37 +00:00
-F "attachment=@$1"
2023-07-21 20:19:29 +00:00
}
2023-07-21 22:52:38 +00:00
function delete-release(){
curl \
-X 'DELETE' \
2023-07-21 22:55:48 +00:00
-Url "https://gitea.kdiva.ru/api/v1/repos/${DRONE_REPO}/releases/${1}" \
-H 'Authorization: Bearer 10e4af53e553aacb905766512e36487492d61a66'
2023-07-21 22:52:38 +00:00
}
2023-07-21 20:19:29 +00:00
function vars() {
echo "DRONE_SEMVER $DRONE_SEMVER"
echo "DRONE_REPO_LINK $DRONE_REPO_LINK"
echo "DRONE_TAG $DRONE_TAG"
echo "KEY $KEY"
echo "OTHER_KEY $OTHER_KEY"
RELEASES=$(curl -X GET -Url https://gitea.kdiva.ru/api/v1/repos/${DRONE_REPO}/releases)
RELEASES_IDS=$(jq -r '.[].id' <<< $RELEASES)
if [[ -z "${RELEASES_IDS}" ]]; then
echo "RELEASES_IDS id NULL"
else
echo "RELEASES_IDS id ${RELEASES_IDS}"
fi
}