Skip to content

Instantly share code, notes, and snippets.

@lindenb
Created July 1, 2021 10:19
Show Gist options
  • Save lindenb/d8c78785840d65f79673d6fd779ffdbe to your computer and use it in GitHub Desktop.
Save lindenb/d8c78785840d65f79673d6fd779ffdbe to your computer and use it in GitHub Desktop.
#!/bin/bash
# https://git.521000.bestmunity/t/how-to-create-full-release-from-command-line-not-just-a-tag/916/2
if [ "$#" -ne 2 ]; then
echo "Expected: 'version' 'message'"
exit -1
fi
set -e
set -o pipefail
version=$1
text=$2
branch=$(git rev-parse --abbrev-ref HEAD)
repo_full_name=$(git config --get remote.origin.url)
url=${repo_full_name}
token=$(git config --global github.token)
test ! -z "${url}"
test ! -z "${branch}"
test ! -z "${token}"
re="^(https|git)(:\/\/|@)([^\/:]+)[\/:]([^\/:]+)\/(.+).git$"
if [[ ${url} =~ $re ]]; then
protocol=${BASH_REMATCH[1]}
separator=${BASH_REMATCH[2]}
hostname=${BASH_REMATCH[3]}
user=${BASH_REMATCH[4]}
repo=${BASH_REMATCH[5]}
fi
generate_post_data()
{
cat <<EOF
{
"tag_name": "$version",
"target_commitish": "$branch",
"name": "$version",
"body": "$text",
"draft": false,
"prerelease": false
}
EOF
}
echo "Create release $version for repo: $repo_full_name branch: $branch"
curl --data "$(generate_post_data)" "https://api.github.com/repos/$user/$repo/releases?access_token=$token"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment