|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +set -e |
| 4 | +set -x |
| 5 | + |
| 6 | +git add package.json history.md |
| 7 | +tag=v$(json -f package.json version) |
| 8 | +git commit -a -m "Release $tag" &> /dev/null |
| 9 | +rm -rf build |
| 10 | +webpack |
| 11 | +mkdir .release |
| 12 | +cp -r build autoload package.json plugin data Readme.md doc history.md .release |
| 13 | +git checkout release |
| 14 | +cp -r .release/* . |
| 15 | +git add . |
| 16 | +git commit -a -m "Release $tag" |
| 17 | +git tag -a "$tag" -m "Release $tag" |
| 18 | +git push |
| 19 | +git push --tags |
| 20 | +## upload assets |
| 21 | +cd ./build |
| 22 | +tar -zcf coc.tar.gz index.js |
| 23 | +zip coc.zip index.js |
| 24 | +declare -a files=("coc.zip" "coc.tar.gz") |
| 25 | +GH_API="https://api.github.com" |
| 26 | +GH_REPO="$GH_API/repos/neoclide/coc.nvim" |
| 27 | +GH_TAGS="$GH_REPO/releases/tags/$tag" |
| 28 | +AUTH="Authorization: token $GITHUB_API_TOKEN" |
| 29 | +# Validate token. |
| 30 | +curl -o /dev/null -sH "$AUTH" $GH_REPO || { echo "Error: Invalid repo, token or network issue!"; exit 1; } |
| 31 | +# Create release |
| 32 | +echo "Creating release for $tag" |
| 33 | +curl -X POST -H "Authorization: token $GITHUB_API_TOKEN" \ |
| 34 | + -H "Content-Type: application/json" \ |
| 35 | + --data "{\"tag_name\":\"$tag\"}" \ |
| 36 | + "$GH_REPO/releases" |
| 37 | +# Read asset tags. |
| 38 | +response=$(curl -sH "$AUTH" $GH_TAGS) |
| 39 | +# Get ID of the asset based on given filename. |
| 40 | +eval $(echo "$response" | grep -m 1 "id.:" | grep -w id | tr : = | tr -cd '[[:alnum:]]=') |
| 41 | +[ "$id" ] || { echo "Error: Failed to get release id for tag: $tag"; echo "$response" | awk 'length($0)<100' >&2; exit 1; } |
| 42 | +# Upload asset |
| 43 | +for filename in "${files[@]}" |
| 44 | +do |
| 45 | + GH_ASSET="https://uploads.github.com/repos/neoclide/coc.nvim/releases/$id/assets?name=$filename" |
| 46 | + echo "Uploading $filename" |
| 47 | + curl -X POST -H "Authorization: token $GITHUB_API_TOKEN" \ |
| 48 | + -H "Content-Type: application/octet-stream" \ |
| 49 | + --data-binary @"$filename" \ |
| 50 | + $GH_ASSET |
| 51 | +done |
| 52 | +rm coc.zip coc.tar.gz |
| 53 | +cd .. |
| 54 | +git checkout master |
| 55 | +rm -rf .release |
| 56 | +nvim -c 'helptags doc|q' |
0 commit comments