Created
July 9, 2021 14:24
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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