diff --git a/lib b/lib new file mode 100644 index 0000000..13d29c5 --- /dev/null +++ b/lib @@ -0,0 +1,57 @@ +#!/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(){ + RED= '\033[0;31m' + + if [[-z "${TAG}"]]; then + echo "${RED}TAG key is not set" + break + fi + + 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, + "name": "release $1", + "prerelease": false, + "tag_name": "$1", + }') + + RELEASE_ID=$(jq -r '.id' <<< $RESPONSE) + + curl \ + -X 'POST' \ + -vv \ + -Url "https://gitea.kdiva.ru/api/v1/repos/${DRONE_REPO}/releases/$RELEASE_ID/assets" \ + -H 'accept: application/json' \ + -H 'Content-Type: multipart/form-data' \ + -H 'Authorization: Bearer 10e4af53e553aacb905766512e36487492d61a66' \ + -F 'attachment=@./release/module.zip;type=application/x-zip-compressed' \ + -F 'attachment=@./src/module.json;type=application/json' +} + +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 +}