#!/bin/sh set -euo pipefail if [[ ! -z "${DRONE_NETRC_MACHINE}" ]]; then cat < ${HOME}/.netrc machine ${DRONE_NETRC_MACHINE} login ${DRONE_NETRC_USERNAME} password ${DRONE_NETRC_PASSWORD} EOF fi if [[ -z "${DRONE_COMMIT_AUTHOR_NAME}" ]]; then export DRONE_COMMIT_AUTHOR_NAME=drone fi if [[ -z "${DRONE_COMMIT_AUTHOR_EMAIL}" ]]; then export DRONE_COMMIT_AUTHOR_EMAIL=drone@localhost fi export GIT_AUTHOR_NAME=${DRONE_COMMIT_AUTHOR_NAME} export GIT_AUTHOR_EMAIL=${DRONE_COMMIT_AUTHOR_EMAIL} export GIT_COMMITTER_NAME=${DRONE_COMMIT_AUTHOR_NAME} export GIT_COMMITTER_EMAIL=${DRONE_COMMIT_AUTHOR_EMAIL} git fetch --tags CURRENTTAG=$(git tag --sort=-taggerdate | head -n 1) PREVIOUSTAG=$(git tag --sort=-taggerdate | head -n 2 | tail -n 1) echo "$PREVIOUSTAG..$CURRENTTAG" ALLCHANGES=$(npx -y @philippdormann/changelogen@0.7.6 --from $PREVIOUSTAG --to $CURRENTTAG --no-output | sed 's/"/\\"/g' | tail -n +6) if [ "${PLUGIN_GITEA_DOMAIN:+set}" = set ]; then if [ "${PLUGIN_GITEA_APIKEY:-null}" = null ]; then echo "No api key provided"; exit 1; fi if [ "${PLUGIN_REPO:-null}" = null ]; then echo "Falling back to drone repo name"; PLUGIN_REPO=$CI_REPO_NAME fi curl --request POST \ --url "https://$PLUGIN_GITEA_DOMAIN/api/v1/repos/$PLUGIN_REPO/releases" \ --header "Content-Type: application/json" \ --header "Authorization: token $PLUGIN_GITEA_APIKEY" \ --data "{ \"name\": \"$CURRENTTAG\", \"body\": \"$ALLCHANGES\", \"draft\": false, \"tag_name\": \"$CURRENTTAG\" }" echo "Release created"; fi if [ "${PLUGIN_MATRIX_SERVER:+set}" = set ]; then echo "Detected matrix server"; if [ "${PLUGIN_MATRIX_USER:-null}" = null ]; then echo "No matrix username provided"; exit 3; fi if [ "${PLUGIN_REPO:-null}" = null ]; then echo "No matrix password provided"; exit 4; fi if [ "${PLUGIN_MATRIX_ROOM:-null}" = null ]; then echo "No matrix room id provided"; exit 4; fi MATRIX_LOGIN=$(curl --request POST \ --url "https://$PLUGIN_MATRIX_SERVER/_matrix/client/r0/login" \ --header "Content-Type: application/json" \ --data "{ \"type\": \"m.login.password\", \"user\": \"$PLUGIN_MATRIX_USER\", \"password\": \"$PLUGIN_MATRIX_PASSWORD\" }") MATRIX_TOKEN=$(echo $MATRIX_LOGIN | jq .access_token | sed 's/"//g' ) if [ "${PLUGIN_VERSION_PREFIX:-null}" = null ]; then echo "Falling back to empty version prefix"; PLUGIN_VERSION_PREFIX="" fi FORMATTED_CHANGES=$(echo "# $PLUGIN_VERSION_PREFIX$CURRENTTAG \n $ALLCHANGES" | pandoc -f markdown -t html | sed 's/"/'"'"'/g' | xargs echo -n) curl --request POST \ --url "https://$PLUGIN_MATRIX_SERVER/_matrix/client/r0/rooms/$PLUGIN_MATRIX_ROOM/send/m.room.message?access_token=$MATRIX_TOKEN" \ --header "Content-Type: application/json" \ --data "{ \"msgtype\": \"m.text\", \"body\": \"$(echo "# $PLUGIN_VERSION_PREFIX$CURRENTTAG \n $ALLCHANGES" | xargs echo -n)\", \"format\": \"org.matrix.custom.html\", \"formatted_body\": \"$FORMATTED_CHANGES\" }" echo "Notification sent"; fi