Skip to content

Commit

Permalink
Keep ghc and go version aliases in git
Browse files Browse the repository at this point in the history
so that the docker containers builds do not need to generate files prior to
loading code.
  • Loading branch information
meatballhat committed Jul 3, 2017
1 parent 1dfe512 commit 8001f50
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 50 deletions.
81 changes: 47 additions & 34 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def version_for(version_str)
end
end

def semver_sort(a, b)
Gem::Version.new(a.to_s) <=> Gem::Version.new(b.to_s)
end

def fetch_githubusercontent_file(from, host: 'raw.githubusercontent.com',
to: nil, mode: 'a+rx')
conn = Faraday.new("https://#{host}") do |f|
Expand Down Expand Up @@ -68,7 +72,10 @@ def latest_release_for(repo)
if response.success?
json_data = JSON.parse(response.body)
fail "No releases found for #{repo}" if json_data.empty?
latest = json_data.sort { |a,b| version_for(a["tag_name"]) <=> version_for(b["tag_name"]) }.last["tag_name"]
json_data.sort! do |a, b|
semver_sort(a['tag_name'].sub(/^v/, ''), b['tag_name'].sub(/^v/, ''))
end
json_data.last['tag_name']
else
fail "Could not find releases for #{repo}"
end
Expand Down Expand Up @@ -124,6 +131,19 @@ def fetch_sc(platform)
chmod 'a+rx', dest
end

def expand_semver_aliases(full_version)
fullparts = full_version.split('.')
major = fullparts.first
{
full_version => full_version,
major => full_version,
"#{major}.x" => full_version,
"#{major}.x.x" => full_version,
"#{fullparts[0]}.#{fullparts[1]}" => full_version,
"#{fullparts[0]}.#{fullparts[1]}.x" => full_version,
}
end

task 'assets:precompile' => %i(
clean
update_sc
Expand All @@ -147,14 +167,14 @@ end

desc 'update gimme'
file 'public/files/gimme' => 'public/files' do
latest_release = latest_release_for 'travis-ci/gimme'
latest_release = latest_release_for('travis-ci/gimme')
logger.info "Latest gimme release is #{latest_release}"
fetch_githubusercontent_file "travis-ci/gimme/#{latest_release}/gimme"
end

desc "update godep for Darwin"
file 'public/files/godep_darwin_amd64' => 'public/files' do
latest_release = latest_release_for 'tools/godep'
latest_release = latest_release_for('tools/godep')
logger.info "Latest godep release is #{latest_release}"
fetch_githubusercontent_file(
"tools/godep/releases/download/#{latest_release}/godep_darwin_amd64",
Expand All @@ -164,7 +184,7 @@ end

desc "update godep for Linux"
file 'public/files/godep_linux_amd64' => 'public/files' do
latest_release = latest_release_for 'tools/godep'
latest_release = latest_release_for('tools/godep')
logger.info "Latest godep release is #{latest_release}"
fetch_githubusercontent_file(
"tools/godep/releases/download/#{latest_release}/godep_linux_amd64",
Expand All @@ -174,7 +194,7 @@ end

desc 'update nvm.sh'
file 'public/files/nvm.sh' => 'public/files' do
latest_release = latest_release_for 'creationix/nvm'
latest_release = latest_release_for('creationix/nvm')
logger.info "Latest nvm release is #{latest_release}"
fetch_githubusercontent_file "creationix/nvm/#{latest_release}/nvm.sh"
fetch_githubusercontent_file "creationix/nvm/#{latest_release}/nvm-exec"
Expand All @@ -187,7 +207,7 @@ end

desc 'update tmate'
file 'public/files/tmate-static-linux-amd64.tar.gz' => 'public/files' do
latest_release = latest_release_for 'tmate-io/tmate'
latest_release = latest_release_for('tmate-io/tmate')
logger.info "Latest tmate release is #{latest_release}"
fetch_githubusercontent_file(
File.join(
Expand All @@ -205,37 +225,24 @@ file 'public/files/rustup-init.sh' => 'public/files' do
end

desc 'update raw gimme versions'
file 'public/files/gimme-versions-binary-linux' => 'tmp' do
file 'tmp/gimme-versions-binary-linux' => 'tmp' do
fetch_githubusercontent_file(
'travis-ci/gimme/master/.testdata/sample-binary-linux',
to: 'gimme-versions-binary-linux',
to: File.expand_path('../tmp/gimme-versions-binary-linux', __FILE__),
mode: 0o644
)
end

desc 'update gimme versions'
file 'public/files/gimme-versions-binary-linux.json' => 'public/files/gimme-versions-binary-linux' do
raw = File.read('public/files/gimme-versions-binary-linux').split(/\n/).reject do |line|
file 'public/version-aliases/go.json' => 'tmp/gimme-versions-binary-linux' do
raw = File.read('tmp/gimme-versions-binary-linux').split(/\n/).reject do |line|
line.strip.empty? || line.strip.start_with?('#')
end

raw.sort! do |a, b|
a.split('.').map(&:to_i) <=> b.split('.').map(&:to_i)
end
raw.sort!(&method(:semver_sort))

out = {}
raw.each do |full_version|
fullparts = full_version.split('.')
major = fullparts.first
out.merge!(
full_version => full_version,
"#{major}" => full_version,
"#{major}.x" => full_version,
"#{major}.x.x" => full_version,
"#{fullparts[0]}.#{fullparts[1]}" => full_version,
"#{fullparts[0]}.#{fullparts[1]}.x" => full_version
)
end
raw.each { |full_version| out.merge!(expand_semver_aliases(full_version)) }

raise StandardError, 'no go versions parsed' if out.empty?

Expand All @@ -245,37 +252,39 @@ file 'public/files/gimme-versions-binary-linux.json' => 'public/files/gimme-vers
)

File.write(
'public/files/gimme-versions-binary-linux.json',
'public/version-aliases/go.json',
JSON.pretty_generate(out)
)
end

desc 'update raw ghc versions'
file 'public/files/ghc-versions.html' => 'tmp' do
file 'tmp/ghc-versions.html' => 'tmp' do
fetch_githubusercontent_file(
'~ghc',
host: 'downloads.haskell.org',
to: 'ghc-versions.html',
to: File.expand_path('../tmp/ghc-versions.html', __FILE__),
mode: 0o644
)
end

desc 'update ghc versions'
file 'public/files/ghc-versions.json' => 'public/files/ghc-versions.html' do
file 'public/version-aliases/ghc.json' => 'tmp/ghc-versions.html' do
out = {}
File.read('public/files/ghc-versions.html')
File.read('tmp/ghc-versions.html')
.scan(%r[<a href="[^"]+">(?<version>\d[^<>]+)/</a>]i)
.to_a
.flatten
.reject { |v| v =~ /-(rc|latest)/ }
.sort { |a, b| a.split('.').map(&:to_i) <=> b.split('.').map(&:to_i) }
.sort(&method(:semver_sort))
.each do |full_version|
fullparts = full_version.split('.')
major = fullparts.first
out.merge!(
full_version => full_version,
major => full_version,
"#{major}.x" => full_version,
"#{major}.x.x" => full_version,
"#{fullparts[0]}.#{fullparts[1]}" => full_version,
"#{fullparts[0]}.#{fullparts[1]}.x" => full_version,
)
end
Expand Down Expand Up @@ -315,6 +324,12 @@ multitask update_godep: Rake::FileList[
'public/files/godep_linux_amd64'
]

desc 'update version aliases'
multitask update_version_aliases: Rake::FileList[
'public/version-aliases/ghc.json',
'public/version-aliases/go.json'
]

desc 'update static files'
multitask update_static_files: Rake::FileList[
'lib/travis/build/addons/sauce_connect/sauce_connect.sh',
Expand All @@ -327,9 +342,7 @@ multitask update_static_files: Rake::FileList[
'public/files/sbt',
'public/files/sc-linux.tar.gz',
'public/files/sc-osx.zip',
'public/files/tmate-static-linux-amd64.tar.gz',
'public/files/gimme-versions-binary-linux.json',
'public/files/ghc-versions.json'
'public/files/tmate-static-linux-amd64.tar.gz'
]

desc "show contents in public/files"
Expand Down
31 changes: 15 additions & 16 deletions lib/travis/build/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,11 @@ class Config < Travis::Config
self.env_namespace = 'travis_build'

def go_version_aliases_hash
@go_version_aliases_hash ||= JSON.parse(
File.read(
File.expand_path(
'../../../../public/files/gimme-versions-binary-linux.json',
__FILE__
)
).untaint
)
@go_version_aliases_hash ||= version_aliases_hash('go')
end

def ghc_version_aliases_hash
@ghc_version_aliases_hash ||= JSON.parse(
File.read(
File.expand_path(
'../../../../public/files/ghc-versions.json',
__FILE__
)
).untaint
)
@ghc_version_aliases_hash ||= version_aliases_hash('ghc')
end

define(
Expand Down Expand Up @@ -88,6 +74,19 @@ def ghc_version_aliases_hash
default(
access: %i(key),
)

private

def version_aliases_hash(name)
JSON.parse(
File.read(
File.expand_path(
"../../../../public/version-aliases/#{name}.json",
__FILE__
)
).untaint
)
end
end
end
end
2 changes: 2 additions & 0 deletions public/version-aliases/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The files in this directory (other than this one) are *generated* and should not
be directly altered.
106 changes: 106 additions & 0 deletions public/version-aliases/ghc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"0.29": "0.29",
"0.x": "0.29",
"0.x.x": "0.29",
"0.29.x": "0.29",
"3.02": "3.02",
"3.x": "3.03",
"3.x.x": "3.03",
"3.02.x": "3.02",
"3.03": "3.03",
"3.03.x": "3.03",
"4.02": "4.02",
"4.x": "4.08.2",
"4.x.x": "4.08.2",
"4.02.x": "4.02",
"4.04": "4.04",
"4.04.x": "4.04",
"4.06": "4.06",
"4.06.x": "4.06",
"4.08": "4.08",
"4.08.x": "4.08.2",
"4.08.1": "4.08.1",
"4.08.2": "4.08.2",
"5.00": "5.00",
"5.x": "5.04.3",
"5.x.x": "5.04.3",
"5.00.x": "5.00.2",
"5.00.1": "5.00.1",
"5.00.2": "5.00.2",
"5.02": "5.02",
"5.02.x": "5.02.3",
"5.02.1": "5.02.1",
"5.02.2": "5.02.2",
"5.02.3": "5.02.3",
"5.03.20020204": "5.03.20020204",
"5.03.x": "5.03.20021303",
"5.03.20020208": "5.03.20020208",
"5.03.20020410": "5.03.20020410",
"5.03.20021303": "5.03.20021303",
"5.04": "5.04",
"5.04.x": "5.04.3",
"5.04.1": "5.04.1",
"5.04.2": "5.04.2",
"5.04.3": "5.04.3",
"6.0": "6.0",
"6.x": "6.12.3",
"6.x.x": "6.12.3",
"6.0.x": "6.0.1",
"6.0.1": "6.0.1",
"6.2": "6.2",
"6.2.x": "6.2.2",
"6.2.1": "6.2.1",
"6.2.2": "6.2.2",
"6.4": "6.4",
"6.4.x": "6.4.3",
"6.4.1": "6.4.1",
"6.4.2": "6.4.2",
"6.4.3": "6.4.3",
"6.6": "6.6",
"6.6.x": "6.6.1",
"6.6.1": "6.6.1",
"6.8.1": "6.8.1",
"6.8.x": "6.8.3",
"6.8.2": "6.8.2",
"6.8.3": "6.8.3",
"6.10.1": "6.10.1",
"6.10.x": "6.10.4",
"6.10.2": "6.10.2",
"6.10.3": "6.10.3",
"6.10.4": "6.10.4",
"6.12.1": "6.12.1",
"6.12.x": "6.12.3",
"6.12.2": "6.12.2",
"6.12.3": "6.12.3",
"7.0.1": "7.0.1",
"7.x": "7.10.3",
"7.x.x": "7.10.3",
"7.0.x": "7.0.4",
"7.0.2": "7.0.2",
"7.0.3": "7.0.3",
"7.0.4": "7.0.4",
"7.2.1": "7.2.1",
"7.2.x": "7.2.2",
"7.2.2": "7.2.2",
"7.4.1": "7.4.1",
"7.4.x": "7.4.2",
"7.4.2": "7.4.2",
"7.6.1": "7.6.1",
"7.6.x": "7.6.3",
"7.6.2": "7.6.2",
"7.6.3": "7.6.3",
"7.8.1": "7.8.1",
"7.8.x": "7.8.4",
"7.8.2": "7.8.2",
"7.8.3": "7.8.3",
"7.8.4": "7.8.4",
"7.10.1": "7.10.1",
"7.10.x": "7.10.3",
"7.10.2": "7.10.2",
"7.10.3": "7.10.3",
"8.0.1": "8.0.1",
"8.x": "8.0.2",
"8.x.x": "8.0.2",
"8.0.x": "8.0.2",
"8.0.2": "8.0.2"
}
27 changes: 27 additions & 0 deletions public/version-aliases/go.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"1.2.2": "1.2.2",
"1": "1.8.3",
"1.x": "1.8.3",
"1.x.x": "1.8.3",
"1.2": "1.2.2",
"1.2.x": "1.2.2",
"1.3.3": "1.3.3",
"1.3": "1.3.3",
"1.3.x": "1.3.3",
"1.4.3": "1.4.3",
"1.4": "1.4.3",
"1.4.x": "1.4.3",
"1.5.4": "1.5.4",
"1.5": "1.5.4",
"1.5.x": "1.5.4",
"1.6.4": "1.6.4",
"1.6": "1.6.4",
"1.6.x": "1.6.4",
"1.7.6": "1.7.6",
"1.7": "1.7.6",
"1.7.x": "1.7.6",
"1.8.3": "1.8.3",
"1.8": "1.8.3",
"1.8.x": "1.8.3",
"go1": "go1"
}

0 comments on commit 8001f50

Please sign in to comment.