Skip to content

Instantly share code, notes, and snippets.

Created July 9, 2021 14:24
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Run from a Git repository with a properly configured Rapporteur ( status endpoint as the first argument, this script will wait until the live revision matches the latest local revision
#!/usr/bin/env ruby
require 'json'
require 'shellwords'
unless ARGV.length == 1
$stderr.puts "Usage: wait_for_deploy.rb"
exit 1
live_commit = nil
last_commit = `git rev-parse HEAD`.chomp
unless $?.success?
$stderr.puts "Unable to fetch latest local git commit"
exit 1
$stderr.puts "Latest commit: #{last_commit}"
until live_commit == last_commit do
sleep 1 unless live_commit.nil?
json_body = `curl -s --fail #{Shellwords.escape(ARGV[0])}`
unless $?.success?
$stderr.puts "Unable to fetch status JSON"
exit 1
status = JSON.parse(json_body)
$stderr.puts "Revision at start: #{status['revision']}" if live_commit.nil?
live_commit = status['revision'].chomp
$stderr.puts "Current revision matches: #{live_commit}"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment