6

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,262,500
  • 529
  • 4,410
  • 5,250
Hadar
  • 61
  • 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.


Alternatively gh release list display releases, and since gh 2.18.0 (Nov. 2022), with column title:

$ gh release list
TITLE                   TYPE         TAG NAME      PUBLISHED
GitHub CLI 2.18.1       Latest       v2.18.1       about 12 days ago
GitHub CLI 2.18.0                    v2.18.0       about 14 days ago
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
2

CLI gh release list command can show the release date

Bill Chan
  • 3,199
  • 36
  • 32
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
  • 1,022
  • 10
  • 11