github.com/ezbuy/gauge@v0.9.4-0.20171013092048-7ac5bd3931cd/build/brew_update.rb (about) 1 # Copyright 2015 ThoughtWorks, Inc. 2 3 # This file is part of Gauge. 4 5 # Gauge is free software: you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License as published by 7 # the Free Software Foundation, either version 3 of the License, or 8 # (at your option) any later version. 9 10 # Gauge is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 15 # You should have received a copy of the GNU General Public License 16 # along with Gauge. If not, see <http://www.gnu.org/licenses/>. 17 18 require 'parser/current' 19 require 'net/http' 20 require 'uri' 21 require 'json' 22 23 24 if ARGV.length < 2 25 puts 'Minimum two arguments required. 26 Usage: ruby brew_update.rb <version> <path to file>. 27 Example: ruby brew_update.rb 0.3.2 Library/Formula/gauge.rb. 28 ' 29 exit 1 30 end 31 32 Parser::Builders::Default.emit_lambda = true # opt-in to most recent AST format 33 code = File.read(ARGV[1]) 34 35 class Processor < AST::Processor 36 attr_accessor :old_sha256 37 38 def initialize() 39 @last_value = '' 40 end 41 42 def on_begin(node) 43 node.children.each { |c| process(c) } 44 end 45 46 def on_class(node) 47 node.children.each { |c| process(c) } 48 end 49 50 def on_block(node) 51 node.children.each { |c| process(c) } 52 end 53 54 def on_send(node) 55 if node.children[1].to_s == 'sha256' and node.children[2].children[0].instance_of? String 56 @old_sha256 = node.children[2].children[0] 57 end 58 end 59 end 60 61 ast = Processor.new 62 ast.process(Parser::CurrentRuby.parse(code)) 63 64 `curl -O -L https://github.com/getgauge/gauge/archive/v#{ARGV[0]}.tar.gz` 65 sha256 = `shasum -a 256 v#{ARGV[0]}.tar.gz`.split[0] 66 67 code = code.sub! ast.old_sha256, sha256 68 code = code.gsub(%r{(https://github.com/getgauge/gauge/archive/)v\d?.\d?.\d?.tar.gz}, "https://github.com/getgauge/gauge/archive/v#{ARGV[0]}.tar.gz") 69 70 File.write(ARGV[1], code) 71 72 puts 'Update done.'