5

I would like to use gitHub "releases" feature to tell my production server when should it update its code base from GitHub.
I do not want it to grab on each push, but just when a new release is being created.

My plan was to create a bash script that will check every 10-15 minutes if there is a new release and if it found a new release, it will do a pull request or download the latest release zip file, deploy the new code and restart the node service.

But I am stuck on the first step and that's how can I figure out if there is a new release.

Any help/pointer or direction will be greatly appreciated.

VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755
Hadar
  • 51
  • 1
  • 2

3 Answers3

4

As I mentioned in "GitHub latest release", you have an API dedicated to get the latest release.

GET /repos/:owner/:repo/releases/latest

You can use it (with the appropriate authentication and the right scope) for a private repo.

If you cache the latest release, you can trigger your process each time the new latest differs from the one you have cached.

Community
  • 1
  • 1
VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755
1

CLI gh release list command can show the release date

Bill Chan
  • 2,803
  • 32
  • 29
0

Using bash with the help of curl, you can use this long one-liner to get the latest release from a public repository:

git clone -b $(basename $(curl -Ls -o /dev/null -w %{url_effective} https://github.com/OWNER/PROJECT/releases/latest)) https://github.com/OWNER/PROJECT.git

A bash function like this:

gh-clone-latest() {
  local owner=$1 project=$2
  local output_directory=${3:-$owner-$project-release}
  local release_url=$(curl -Ls -o /dev/null -w %{url_effective} https://github.com/$owner/$project/releases/latest)
  local release_tag=$(basename $release_url)
  git clone -b $release_tag -- https://github.com/$owner/$project.git $output_directory
}

would reduce that to gh-clone-latest Owner Project.

For a private project, you'll need to authenticate and scope properly, as mentioned in the other answer.

Dennis Estenson
  • 912
  • 9
  • 11