github.sh 3.16 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
#!/bin/bash

### Control that the script is run on `dev` branch
branch=`git rev-parse --abbrev-ref HEAD`
if [[ ! "$branch" = "master" ]];
then
  echo ">> This script must be run under \`master\` branch"
  exit
fi


### Releasing
current=`grep -P "version\": \"\d+.\d+.\d+(\w*)" package.json | grep -oP "\d+.\d+.\d+(\w*)"`
echo "Current version: $current"

case "$1" in
  del)
    if [[ $2 =~ ^[a-zA-Z0-9_]+:[a-zA-Z0-9_]+$ ]]; then
      result=`curl -i 'https://api.github.com/repos/duniter-gchange/gchange-client/releases/tags/v'"$current"''`
      release_url=`echo "$result" | grep -P "\"url\": \"[^\"]+"  | grep -oP "https://api.github.com/repos/duniter-gchange/gchange-client/releases/\d+"`
      if [[ $release_url != "" ]]; then
        echo "Deleting existing release..."
        curl -XDELETE $release_url -u $2
      fi
    else
      echo "Wrong argument"
      echo "Usage:"
      echo " > ./github.sh del user:password"
      exit
    fi
  ;;

  pre|rel)
    if [[ $2 =~ ^[a-zA-Z0-9_]+:[a-zA-Z0-9_]+$ && $3 != "" ]]; then

      if [[ $1 = "pre" ]]; then
        prerelease="true"
      else
        prerelease="false"
      fi

      result=`curl -i 'https://api.github.com/repos/duniter-gchange/gchange-client/releases/tags/v'"$current"''`
      release_url=`echo "$result" | grep -P "\"url\": \"[^\"]+"  | grep -oP "https://api.github.com/repos/duniter-gchange/gchange-client/releases/\d+"`
      if [[ $release_url != "" ]]; then
        echo "Deleting existing release..."
        curl -XDELETE $release_url -u $2
      fi

      echo "Creating new release..."
      result=`curl -i https://api.github.com/repos/duniter-gchange/gchange-client/releases -u $2 -d '{"tag_name": "v'"$current"'","target_commitish": "master","name": "'"$current"'","body": "'"$3"'","draft": false,"prerelease": '"$prerelease"'}'`
51
      upload_url=`echo "$result" | grep -P "\"upload_url\": \"[^\"]+"  | grep -oP "https://[a-z0-9/.-]+"`
52
      ###  Sending files
53
      echo "Uploading files to GitHub... to $upload_url"
54
      dirname=`pwd`
55
      curl -i -u $2 -H 'Content-Type: application/zip' -T $dirname/platforms/web/build/gchange-v$current-web.zip $upload_url?name=gchange-v$current-web.zip
56
      #curl -i -u $2 -H 'Content-Type: application/zip' -T $dirname/platforms/firefoxos/build/package.zip $upload_url?name=gchange-v$current-firefoxos.zip
57
      curl -i -u $2 -H 'Content-Type: application/vnd.android.package-archive' -T $dirname/platforms/android/build/outputs/apk/android-release.apk $upload_url?name=gchange-v$current-android.apk
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
      #curl -i -u $2 -H 'Content-Type: application/x-debian-package' -T $dirname/platforms/ubuntu/native/gchange_${current}_amd64.deb $upload_url?name=gchange-v${current}-ubuntu-amd64.deb

      echo "Successfully uploading files"
      release_url=`echo "$result" | grep -P "\"url\": \"[^\"]+"  | grep -oP "https://api.github.com/repos/[a-z0-9/.]+"`
      echo " -> Release url: $release_url"
    else
      echo "Wrong arguments"
      echo "Usage:"
      echo " > ./github.sh pre|rel user:password <release_description>"
      echo "With:"
      echo " - pre: use for pre-release"
      echo " - rel: for full release"
      exit
    fi
    ;;
  *)
    echo "No task given"
    ;;
esac