github-pages-health-check 0.6.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +6 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +3 -0
- data/README.md +83 -0
- data/github-pages-health-check.gemspec +28 -0
- data/lib/github-pages-health-check.rb +18 -245
- data/lib/github-pages-health-check/checkable.rb +62 -0
- data/lib/github-pages-health-check/cloudflare.rb +11 -7
- data/lib/github-pages-health-check/domain.rb +260 -0
- data/lib/github-pages-health-check/error.rb +7 -6
- data/lib/github-pages-health-check/errors.rb +13 -0
- data/lib/github-pages-health-check/errors/build_error.rb +8 -0
- data/lib/github-pages-health-check/errors/deprecated_ip_error.rb +11 -0
- data/lib/github-pages-health-check/errors/invalid_a_record_error.rb +11 -0
- data/lib/github-pages-health-check/errors/invalid_cname_error.rb +11 -0
- data/lib/github-pages-health-check/errors/invalid_dns_error.rb +11 -0
- data/lib/github-pages-health-check/errors/invalid_domain_error.rb +11 -0
- data/lib/github-pages-health-check/errors/invalid_repository_error.rb +11 -0
- data/lib/github-pages-health-check/errors/missing_access_token_error.rb +11 -0
- data/lib/github-pages-health-check/errors/not_served_by_pages_error.rb +11 -0
- data/lib/github-pages-health-check/printer.rb +71 -0
- data/lib/github-pages-health-check/repository.rb +74 -0
- data/lib/github-pages-health-check/site.rb +32 -0
- data/lib/github-pages-health-check/version.rb +3 -3
- data/script/bootstrap +5 -0
- data/script/check +11 -0
- data/script/check-cloudflare-ips +17 -0
- data/script/cibuild +9 -0
- data/script/console +5 -0
- data/script/release +42 -0
- data/script/test +2 -0
- data/script/update-cloudflare-ips +14 -0
- metadata +60 -7
- data/lib/github-pages-health-check/errors/deprecated_ip.rb +0 -9
- data/lib/github-pages-health-check/errors/invalid_a_record.rb +0 -9
- data/lib/github-pages-health-check/errors/invalid_cname.rb +0 -9
- data/lib/github-pages-health-check/errors/invalid_dns.rb +0 -9
- data/lib/github-pages-health-check/errors/not_served_by_pages.rb +0 -9
@@ -0,0 +1,71 @@
|
|
1
|
+
module GitHubPages
|
2
|
+
module HealthCheck
|
3
|
+
class Printer
|
4
|
+
PRETTY_LEFT_WIDTH = 11
|
5
|
+
PRETTY_JOINER = " | "
|
6
|
+
|
7
|
+
attr_reader :health_check
|
8
|
+
|
9
|
+
def initialize(health_check)
|
10
|
+
@health_check = health_check
|
11
|
+
end
|
12
|
+
|
13
|
+
def simple_string
|
14
|
+
require 'yaml'
|
15
|
+
health_check.to_hash.to_yaml.sub(/\A---\n/, "").gsub(/^:/, "")
|
16
|
+
end
|
17
|
+
|
18
|
+
def pretty_print
|
19
|
+
values = health_check.to_hash
|
20
|
+
output = StringIO.new
|
21
|
+
|
22
|
+
# Header
|
23
|
+
output.puts new_line "Domain", "#{values[:uri]}"
|
24
|
+
output.puts ("-" * (PRETTY_LEFT_WIDTH + 1)) + "|" + "-" * 50
|
25
|
+
|
26
|
+
output.puts new_line "DNS", "does not resolve" if not values[:dns_resolves?]
|
27
|
+
|
28
|
+
# Valid?
|
29
|
+
output.write new_line "State", "#{values[:valid?] ? "valid" : "invalid"}"
|
30
|
+
output.puts " - is #{"NOT " if not values[:served_by_pages?]}served by Pages"
|
31
|
+
|
32
|
+
# What's wrong?
|
33
|
+
output.puts new_line "Reason", "#{values[:reason]}" if not values[:valid?]
|
34
|
+
output.puts new_line nil, "pointed to user domain" if values[:pointed_to_github_user_domain?]
|
35
|
+
output.puts new_line nil, "pointed to pages IP" if values[:pointed_to_github_pages_ip?]
|
36
|
+
|
37
|
+
# DNS Record info
|
38
|
+
output.write new_line "Record Type", "#{values[:a_record?] ? "A" : values[:cname_record?] ? "CNAME" : "other"}"
|
39
|
+
output.puts values[:should_be_a_record?] ? ", should be A record" : ", should be CNAME"
|
40
|
+
|
41
|
+
ip_problems = []
|
42
|
+
ip_problems << "not apex domain" if not values[:apex_domain?]
|
43
|
+
ip_problems << "invalid domain" if not values[:valid_domain?]
|
44
|
+
ip_problems << "old ip address used" if values[:old_ip_address?]
|
45
|
+
output.puts new_line "IP Problems", "#{ip_problems.size > 0 ? ip_problems.join(", ") : "none"} "
|
46
|
+
|
47
|
+
if values[:proxied?]
|
48
|
+
output.puts new_line "Proxied", "yes, through #{values[:cloudflare_ip?] ? "CloudFlare" : "unknown"}"
|
49
|
+
end
|
50
|
+
|
51
|
+
output.puts new_line "Domain", "*.github.com/io domain" if values[:pages_domain?]
|
52
|
+
|
53
|
+
output.string
|
54
|
+
end
|
55
|
+
|
56
|
+
def new_line(left = nil, right = nil)
|
57
|
+
if left and right
|
58
|
+
ljust(left) + PRETTY_JOINER + right
|
59
|
+
elsif left
|
60
|
+
ljust(left)
|
61
|
+
elsif right
|
62
|
+
" " * (PRETTY_LEFT_WIDTH + PRETTY_JOINER.size) + right
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def ljust(line)
|
67
|
+
line.ljust(PRETTY_LEFT_WIDTH)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module GitHubPages
|
2
|
+
module HealthCheck
|
3
|
+
class Repository < Checkable
|
4
|
+
|
5
|
+
attr_reader :name, :owner
|
6
|
+
|
7
|
+
REPO_REGEX = %r{\A[a-z0-9_\-]+/[a-z0-9_\-\.]+\z}i
|
8
|
+
|
9
|
+
HASH_METHODS = [
|
10
|
+
:name_with_owner, :built?, :last_built, :build_duration, :build_error
|
11
|
+
].freeze
|
12
|
+
|
13
|
+
def initialize(name_with_owner, access_token: nil)
|
14
|
+
unless name_with_owner =~ REPO_REGEX
|
15
|
+
raise Errors::InvalidRepositoryError
|
16
|
+
end
|
17
|
+
parts = name_with_owner.split("/")
|
18
|
+
@owner = parts.first
|
19
|
+
@name = parts.last
|
20
|
+
@access_token = access_token || ENV["OCTOKIT_ACCESS_TOKEN"]
|
21
|
+
end
|
22
|
+
|
23
|
+
def name_with_owner
|
24
|
+
@name_with_owner ||= [owner,name].join("/")
|
25
|
+
end
|
26
|
+
alias_method :nwo, :name_with_owner
|
27
|
+
|
28
|
+
def check!
|
29
|
+
raise Errors::BuildError, build_error unless built?
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
def last_build
|
34
|
+
@last_build ||= client.latest_pages_build(name_with_owner)
|
35
|
+
end
|
36
|
+
|
37
|
+
def built?
|
38
|
+
last_build && last_build.status == "built"
|
39
|
+
end
|
40
|
+
|
41
|
+
def build_error
|
42
|
+
last_build.error.message unless built?
|
43
|
+
end
|
44
|
+
alias_method :reason, :build_error
|
45
|
+
|
46
|
+
def build_duration
|
47
|
+
last_build.duration unless last_build.nil?
|
48
|
+
end
|
49
|
+
|
50
|
+
def last_built
|
51
|
+
last_build.updated_at unless last_build.nil?
|
52
|
+
end
|
53
|
+
|
54
|
+
def domain
|
55
|
+
@domain ||= GitHubPages::HealthCheck::Domain.new(cname)
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def client
|
61
|
+
raise Errors::MissingAccessTokenError if @access_token.nil?
|
62
|
+
@client ||= Octokit::Client.new(access_token: @access_token)
|
63
|
+
end
|
64
|
+
|
65
|
+
def pages_info
|
66
|
+
@pages_info ||= client.pages(name_with_owner)
|
67
|
+
end
|
68
|
+
|
69
|
+
def cname
|
70
|
+
pages_info.cname
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module GitHubPages
|
2
|
+
module HealthCheck
|
3
|
+
class Site < Checkable
|
4
|
+
|
5
|
+
attr_reader :repository, :domain
|
6
|
+
|
7
|
+
def initialize(repository_or_domain, access_token: nil)
|
8
|
+
@repository = Repository.new(repository_or_domain, access_token: access_token)
|
9
|
+
@domain = @repository.domain
|
10
|
+
rescue GitHubPages::HealthCheck::Errors::InvalidRepositoryError
|
11
|
+
@repository = nil
|
12
|
+
@domain = Domain.new(repository_or_domain)
|
13
|
+
end
|
14
|
+
|
15
|
+
def check!
|
16
|
+
domain.check!
|
17
|
+
repository.check! unless repository.nil?
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_hash
|
22
|
+
hash = domain.to_hash.dup
|
23
|
+
hash = hash.merge(repository.to_hash) unless repository.nil?
|
24
|
+
hash[:valid?] = valid?
|
25
|
+
hash[:reason] = reason
|
26
|
+
hash
|
27
|
+
end
|
28
|
+
alias_method :to_h, :to_hash
|
29
|
+
alias_method :as_json, :to_hash
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/script/check
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/bin/bash -e
|
2
|
+
|
3
|
+
script/update-cloudflare-ips >/dev/null 2>&1
|
4
|
+
|
5
|
+
# `git diff --quiet` suppresses output and sets a return code
|
6
|
+
# 0 - no changes
|
7
|
+
# 1 - changes
|
8
|
+
if git diff -w --quiet --cached config/cloudflare-ips.txt
|
9
|
+
then
|
10
|
+
echo CloudFlare IP list is up-to-date.
|
11
|
+
exit 0
|
12
|
+
else
|
13
|
+
echo git reset config/cloudflare-ips.txt
|
14
|
+
git reset --quiet config/cloudflare-ips.txt
|
15
|
+
echo '*** CloudFlare IP list is out of date! Run script/update-cloudflare-ips!'
|
16
|
+
exit 1
|
17
|
+
fi
|
data/script/cibuild
ADDED
data/script/console
ADDED
data/script/release
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
# Tag and push a release.
|
3
|
+
|
4
|
+
set -e
|
5
|
+
|
6
|
+
# Make sure we're in the project root.
|
7
|
+
|
8
|
+
cd $(dirname "$0")/..
|
9
|
+
|
10
|
+
# Make sure the darn thing works
|
11
|
+
|
12
|
+
bundle update
|
13
|
+
|
14
|
+
# Build a new gem archive.
|
15
|
+
|
16
|
+
rm -rf github-pages-health-check-*.gem
|
17
|
+
gem build -q github-pages-health-check.gemspec
|
18
|
+
|
19
|
+
# Make sure we're on the master branch.
|
20
|
+
|
21
|
+
(git branch | grep -q '* master') || {
|
22
|
+
echo "Only release from the master branch."
|
23
|
+
exit 1
|
24
|
+
}
|
25
|
+
|
26
|
+
# Figure out what version we're releasing.
|
27
|
+
|
28
|
+
tag=v`ls github-pages-health-check-*.gem | sed 's/^github-pages-health-check-\(.*\)\.gem$/\1/'`
|
29
|
+
|
30
|
+
# Make sure we haven't released this version before.
|
31
|
+
|
32
|
+
git fetch -t origin
|
33
|
+
|
34
|
+
(git tag -l | grep -q "$tag") && {
|
35
|
+
echo "Whoops, there's already a '${tag}' tag."
|
36
|
+
exit 1
|
37
|
+
}
|
38
|
+
|
39
|
+
# Tag it and bag it.
|
40
|
+
|
41
|
+
gem push github-pages-health-check-*.gem && git tag "$tag" &&
|
42
|
+
git push origin master && git push origin "$tag"
|
data/script/test
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/bin/bash -e
|
2
|
+
#/ Usage script/update-cloudflare-ips
|
3
|
+
#/ updates config/cloudflare-ips.txt
|
4
|
+
|
5
|
+
source=https://www.cloudflare.com/ips-v4
|
6
|
+
dest=config/cloudflare-ips.txt
|
7
|
+
|
8
|
+
echo '====>' Downloading $source
|
9
|
+
curl --silent --fail $source | tee $dest
|
10
|
+
echo # cover for a missing newline
|
11
|
+
|
12
|
+
echo '====>' git add $dest
|
13
|
+
git diff -w $dest
|
14
|
+
git add --verbose $dest
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github-pages-health-check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitHub, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-dns
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '2.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: octokit
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '4.0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rspec
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,23 +136,62 @@ dependencies:
|
|
122
136
|
- - "~>"
|
123
137
|
- !ruby/object:Gem::Version
|
124
138
|
version: '1.21'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: dotenv
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '1.0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '1.0'
|
125
153
|
description: Checks your GitHub Pages site for commons DNS configuration issues.
|
126
154
|
email: support@github.com
|
127
155
|
executables: []
|
128
156
|
extensions: []
|
129
157
|
extra_rdoc_files: []
|
130
158
|
files:
|
159
|
+
- ".gitignore"
|
160
|
+
- ".rspec"
|
161
|
+
- ".ruby-version"
|
162
|
+
- ".travis.yml"
|
163
|
+
- Gemfile
|
131
164
|
- LICENSE.md
|
165
|
+
- README.md
|
132
166
|
- config/cloudflare-ips.txt
|
167
|
+
- github-pages-health-check.gemspec
|
133
168
|
- lib/github-pages-health-check.rb
|
169
|
+
- lib/github-pages-health-check/checkable.rb
|
134
170
|
- lib/github-pages-health-check/cloudflare.rb
|
171
|
+
- lib/github-pages-health-check/domain.rb
|
135
172
|
- lib/github-pages-health-check/error.rb
|
136
|
-
- lib/github-pages-health-check/errors
|
137
|
-
- lib/github-pages-health-check/errors/
|
138
|
-
- lib/github-pages-health-check/errors/
|
139
|
-
- lib/github-pages-health-check/errors/
|
140
|
-
- lib/github-pages-health-check/errors/
|
173
|
+
- lib/github-pages-health-check/errors.rb
|
174
|
+
- lib/github-pages-health-check/errors/build_error.rb
|
175
|
+
- lib/github-pages-health-check/errors/deprecated_ip_error.rb
|
176
|
+
- lib/github-pages-health-check/errors/invalid_a_record_error.rb
|
177
|
+
- lib/github-pages-health-check/errors/invalid_cname_error.rb
|
178
|
+
- lib/github-pages-health-check/errors/invalid_dns_error.rb
|
179
|
+
- lib/github-pages-health-check/errors/invalid_domain_error.rb
|
180
|
+
- lib/github-pages-health-check/errors/invalid_repository_error.rb
|
181
|
+
- lib/github-pages-health-check/errors/missing_access_token_error.rb
|
182
|
+
- lib/github-pages-health-check/errors/not_served_by_pages_error.rb
|
183
|
+
- lib/github-pages-health-check/printer.rb
|
184
|
+
- lib/github-pages-health-check/repository.rb
|
185
|
+
- lib/github-pages-health-check/site.rb
|
141
186
|
- lib/github-pages-health-check/version.rb
|
187
|
+
- script/bootstrap
|
188
|
+
- script/check
|
189
|
+
- script/check-cloudflare-ips
|
190
|
+
- script/cibuild
|
191
|
+
- script/console
|
192
|
+
- script/release
|
193
|
+
- script/test
|
194
|
+
- script/update-cloudflare-ips
|
142
195
|
homepage: https://github.com/github/github-pages-health-check
|
143
196
|
licenses:
|
144
197
|
- MIT
|