Skip to content

Instantly share code, notes, and snippets.

@ryanfb
Created July 9, 2021 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanfb/675038152aeccbd2cdbe59b125acf65f to your computer and use it in GitHub Desktop.
Save ryanfb/675038152aeccbd2cdbe59b125acf65f to your computer and use it in GitHub Desktop.
Run from a Git repository with a properly configured Rapporteur (https://github.com/envylabs/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 https://example.com/status.json"
exit 1
end
live_commit = nil
last_commit = `git rev-parse HEAD`.chomp
unless $?.success?
$stderr.puts "Unable to fetch latest local git commit"
exit 1
end
$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
end
status = JSON.parse(json_body)
$stderr.puts "Revision at start: #{status['revision']}" if live_commit.nil?
live_commit = status['revision'].chomp
end
$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