From 3977b077e5c8552cdd89250c2ecf7abf424c7559 Mon Sep 17 00:00:00 2001
From: Xiao Gui <xgui3783@gmail.com>
Date: Tue, 18 Aug 2020 11:47:53 +0200
Subject: [PATCH] chore: auto tag releases

---
 .travis.yml             | 10 ++++++
 docs/releases/v2.2.6.md |  4 +++
 release.sh              | 70 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 84 insertions(+)
 create mode 100755 release.sh

diff --git a/.travis.yml b/.travis.yml
index e8aab9d64..6e5c0d5b2 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -77,6 +77,16 @@ jobs:
       - 'echo GREP_VERSION_NUM: $GREP_VERSION_NUM'
       - test -z "$GREP_VERSION_NUM" && exit 1 || exit 0
 
+    - stage: Create github release
+      if: |
+        type = push AND \
+        branch = master
+      before_script:
+      - chmod ugo+x ./release.sh
+      script: ./release.sh
+      env:
+      - secure: "mERkfztriSCECF/liheC4zFmq4h+MxausY8N0soTytOWUuTmz+NfxObsQ8w8Zl0h3XVe0BZdueJ15zeoipNBDisHZ2kbfLYnCJ8nsym+0O7mpYUSEiT5nDVE0Yj/9a+ZOAW0h0mvWNOwQZId0uTPr8rEst4IvCr+HkLZEUOM06lnftz1edYN3EsVih6MuTymXNLUaYkMBCErq2AFGvgOy6oP6Mq/D2QkBvM+RUNIxcJ2SrM9lMw4i5L/PeOnxbm0MBUndFhR/P0rJ7qz0j4kRP3DvgXfeW+hQsYcECGsnxMgC+Q59ULTBrRGuD03PnHI+7H8CrX+8maHYy+yf7S/iblaCcr0E5gZq/U0mUJbicymBhw4Ygu76X2Rj6E4jUeoC60MqDZovSisV6xuRXXFDqbfYxlBgFSsSS4Ozbl/RUA5MtLx/N4LwAKv5kafktFwZih/ZfQMAOZQfUDB60y4Mvh1Eg6XK4HhnRxdBE8GWP1tQLq/3n8NLr9KBIR4ceHUNEFXjWw3nPIAujnCqUoxSJotfDEnFUpV6KMgZxiC9vv/vq7IgnzzTXRGdvFfjzBbFmYv4+nqYzZhqKb7BI9y++0v+4Jdu9eHGdYVIpiYzzEKhqImK6I4CsUdcakXiPecdxlwA1zc/yET8qyBNGPGnXvYAw1hBt1VbtP8Rf3PKfo="
+
     # Temporarily disabling browserstack e2e tests. They seem to fail without any reason
 
     # - stage: browserstack e2e
diff --git a/docs/releases/v2.2.6.md b/docs/releases/v2.2.6.md
index 5319b9e90..dcf0d026c 100644
--- a/docs/releases/v2.2.6.md
+++ b/docs/releases/v2.2.6.md
@@ -4,3 +4,7 @@
 
 - Fixed matomo CSP issues
 - Updated kg dataset previewer URL
+
+# Under the hood
+
+- CI/CD: auto tag releases on github
diff --git a/release.sh b/release.sh
new file mode 100755
index 000000000..2eb23818a
--- /dev/null
+++ b/release.sh
@@ -0,0 +1,70 @@
+#! /bin/bash
+
+# This is an automated script for TravisCI
+# It is triggered on push to master
+# It will create a release and publish to the github repo
+
+OWNER=HumanBrainProject
+REPO=interactive-viewer
+USER=xgui3783
+EMAIL=xgui3783@gmail.com
+#GITHUB_TOKEN should be populated by CI
+
+test -z "$GITHUB_TOKEN" && exit 1
+
+TAG=$(jq '.version' < package.json)
+TAG=${TAG#\"}
+TAG=v${TAG%\"}
+OBJECT=$(git rev-parse HEAD)
+DATE=$(date --iso-8601=seconds)
+BODY='{
+  "tag": "'$TAG'",
+  "message": "Annotated release for '$TAG'",
+  "object": "'$OBJECT'",
+  "type": "commit",
+  "tagger": {
+    "name": "'$USER'",
+    "email": "'$EMAIL'",
+    "date": "'$DATE'"
+  }
+}'
+
+# Create annotated tag
+
+echo curl -XPOST \
+  -H "Accept: application/vnd.github.v3+json" \
+  -u "$USER:$GITHUB_TOKEN"\
+  -d "$BODY" \
+  https://api.github.com/repos/$OWNER/$REPO/git/tags
+
+# Push tag to remote
+
+CREATE_REF_BODY='{
+  "ref":"refs/tags/'$TAG'",
+  "sha":"'$OBJECT'"
+}'
+
+echo curl -XPOST\
+  -u "$USER:$GITHUB_TOKEN"\
+  -H "Accept: application/vnd.github.v3+json" \
+  -d "$CREATE_REF_BODY"\
+  https://api.github.com/repos/$OWNER/$REPO/git/refs
+
+# Create release
+
+RELEASE_NOTES=$(sed -e 's/$/\\n/' docs/releases/$TAG.md)
+
+RELEASE_BODY='{
+  "tag_name":"'$TAG'",
+  "name":"'$TAG'",
+  "body":"'$(echo $RELEASE_NOTES)'",
+  "target_commitish": "master",
+  "draft":false,
+  "prerelease":false
+}'
+
+echo curl -XPOST\
+  -u "$USER:$GITHUB_TOKEN"\
+  -H "Accept: application/vnd.github.v3+json" \
+  -d "$RELEASE_BODY" \
+  https://api.github.com/repos/$OWNER/$REPO/releases
-- 
GitLab