How to create full release from command line, not just a tag?

I’m working for a company that has a semi-automated system that creates release tags. Now we have started monitoring project for all releases in our organization and we want to use the Release event in the API for that. But since our “release tag” is not considered a full release, it does not create “Release” event. We can of course use “New tag event”, but we’d much prefer to be able to create full Release  with title, description, or assets from the command line. Is there any way to that?

Now, if I go to GitHub UI, find created tag, press “Edit tag”, change nothing and press “Publish release”  I’ll get what I want: full release and event. Is there any way to “Publish release” from a command line?

Thank you!

I’ve created a workaround. Please, advise if there’s a better way to do this:

  1. Create a personal access token through GitHub UI, we only need “Repo” access

  2. Place it in your config by " git config --global github .token YOUR_TOKEN"

  3. Use bash script to make CURL request **sh git-release.sh "1.5.0" "Test description"**

git-release.sh

#!/bin/bash

version=$1
text=$2
branch=$(git rev-parse --abbrev-ref HEAD)
repo_full_name=$(git config --get remote.origin.url | sed 's/.*:\/\/github.com\///;s/.git$//')
token=$(git config --global github.token)

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/$repo_full_name/releases?access_token=$token"
13 Likes

the code is excellent, but the link parse should be better with this: 

#works to ssh & http link

token="your_token"

repo_full_name=$(git config --get remote.origin.url)
url=$repo_full_name
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

echo "https://api.github.com/repos/$user/$repo/releases?access_token=$token"

your code helped me a lot

2 Likes

This scirpt is executing for me without any errors, but it is not creating the tags and I am ending with this " redirected</a>.</body></html>" did you face this issue? Will you please help me here. Thanks in advance.

Do you mind if I take that for creating an action?

1 Like