-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathdeploy-lrug.cgi
62 lines (48 loc) · 1.61 KB
/
deploy-lrug.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env ruby
# This script should be installed at web webhook URL specified
# in .travis.yml
require "cgi"
require "json"
require 'fileutils'
cgi = CGI.new
params = JSON.parse(cgi.params['payload'].first) rescue nil
response = nil
if params.nil?
response = "Failed to parse payload:\n\n#{cgi.params.inspect}"
else
passed = params['state'] == 'success'
on_default_branch = params['branch'] == 'main'
if passed && on_default_branch
TAR_URL = "https://github.com/lrug/lrug.org/releases/download/travis-release/lrug.org.tar.bz2"
BASE_DIR = "/home/lrug/sites/lrug.org/www/lrug_middleman/"
TMP_FILE = "/tmp/lrug.org.tar.bz2"
NEW_RELEASE = File.join(BASE_DIR, "releases", Time.now.strftime('%Y%m%d%H%M%S'))
OLDEST_RELEASE = Dir[File.join(BASE_DIR, "releases", "*")].sort.first
CURRENT_SYMLINK = File.join(BASE_DIR, "current")
# Download the archive
`curl -L -o #{TMP_FILE} #{TAR_URL}`
# Create the new release directory
FileUtils.mkdir_p(NEW_RELEASE)
# Extract the archive to the new release directory
`tar xjvf #{TMP_FILE} -C #{NEW_RELEASE}`
if $? == 0
# Update the symlink
`ln -fsn #{NEW_RELEASE} #{CURRENT_SYMLINK}`
# Remove the oldest release
FileUtils.rm_rf(OLDEST_RELEASE)
response = "OK"
else
response = "Not deploying; tar exited with value #{$?}"
puts "HTTP-Version: HTTP/1.0 500 Failed"
puts
puts response
exit(0)
end
else
response = "Not deploying; passed = #{passed.inspect}, branch = #{params['branch'].inspect}"
end
end
puts "HTTP-Version: HTTP/1.0 200 OK"
puts
puts response
exit(0)