From a2ff54dfa90cc59d860575cc5fac0d45b227cc71 Mon Sep 17 00:00:00 2001
From: s3krit <pugh@s3kr.it>
Date: Wed, 26 Feb 2020 14:36:02 +0100
Subject: [PATCH] Activate publishing of draft releases... (#5062)

* Activate publishing of draft releases...

... And fix the message sending (missing parameter).

* publish_draft_release.sh now checks latest...

... release on github rather than just a tag
---
 substrate/.maintain/gitlab/lib.sh                   | 8 ++++++++
 substrate/.maintain/gitlab/publish_draft_release.sh | 8 +++++---
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/substrate/.maintain/gitlab/lib.sh b/substrate/.maintain/gitlab/lib.sh
index bc0e06a6d46..c8b2d73e609 100755
--- a/substrate/.maintain/gitlab/lib.sh
+++ b/substrate/.maintain/gitlab/lib.sh
@@ -14,6 +14,14 @@ sanitised_git_logs(){
   sed 's/^/* /g'
 }
 
+# Returns the last published release on github
+# repo: 'organization/repo'
+# Usage: last_github_release "$repo"
+last_github_release(){
+  curl -H "Authorization: token $GITHUB_RELEASE_TOKEN" \
+    -s "$api_base/$1/releases/latest" | jq '.tag_name'
+}
+
 # Checks whether a tag on github has been verified
 # repo: 'organization/repo'
 # tagver: 'v1.2.3'
diff --git a/substrate/.maintain/gitlab/publish_draft_release.sh b/substrate/.maintain/gitlab/publish_draft_release.sh
index 8566827a099..4f73575f5bb 100755
--- a/substrate/.maintain/gitlab/publish_draft_release.sh
+++ b/substrate/.maintain/gitlab/publish_draft_release.sh
@@ -11,7 +11,9 @@ labels=(
 )
 
 version="$CI_COMMIT_TAG"
-last_version=$(git tag -l | sort -V | grep -B 1 -x "$version" | head -n 1)
+
+# Note that this is not the last *tagged* version, but the last *published* version
+last_version=$(last_github_release 'paritytech/substrate')
 echo "[+] Version: $version; Previous version: $last_version"
 
 all_changes="$(sanitised_git_logs "$last_version" "$version")"
@@ -39,7 +41,7 @@ $labelled_changes"
 
 echo "[+] Release text generated: "
 echo "$release_text"
-exit
+
 echo "[+] Pushing release to github"
 # Create release on github
 release_name="Substrate $version"
@@ -79,6 +81,6 @@ formatted_msg_body=$(cat <<EOF
 Draft release created: $html_url
 EOF
 )
-send_message "$(structure_message "$msg_body" "$formatted_msg_body")" "$MATRIX_ACCESS_TOKEN"
+send_message "$(structure_message "$msg_body" "$formatted_msg_body")" "$MATRIX_ROOM_ID" "$MATRIX_ACCESS_TOKEN"
 
 echo "[+] Done! Maybe the release worked..."
-- 
GitLab