github.com/getgauge/gauge@v1.6.9/build/brew/brew_update.rb (about) 1 # ---------------------------------------------------------------- 2 # Copyright (c) ThoughtWorks, Inc. 3 # Licensed under the Apache License, Version 2.0 4 # See LICENSE.txt in the project root for license information. 5 # ---------------------------------------------------------------- 6 7 require 'parser/current' 8 require 'net/http' 9 require 'uri' 10 require 'json' 11 12 13 if ARGV.length < 2 14 puts 'Minimum two arguments required. 15 Usage: ruby brew_update.rb <version> <path to file>. 16 Example: ruby brew_update.rb 0.3.2 Library/Formula/gauge.rb. 17 ' 18 exit 1 19 end 20 21 Parser::Builders::Default.emit_lambda = true # opt-in to most recent AST format 22 code = File.read(ARGV[1]) 23 24 class Processor < AST::Processor 25 attr_accessor :old_sha256 26 27 def initialize() 28 @last_value = '' 29 end 30 31 def on_begin(node) 32 node.children.each { |c| process(c) } 33 end 34 35 def on_class(node) 36 node.children.each { |c| process(c) } 37 end 38 39 def on_block(node) 40 node.children.each { |c| process(c) } 41 end 42 43 def on_send(node) 44 if node.children[1].to_s == 'sha256' and node.children[2].children[0].instance_of? String 45 @old_sha256 = node.children[2].children[0] 46 end 47 end 48 end 49 50 ast = Processor.new 51 ast.process(Parser::CurrentRuby.parse(code)) 52 53 `curl -O -L https://github.com/getgauge/gauge/archive/refs/tags/v#{ARGV[0]}.tar.gz` 54 sha256 = `shasum -a 256 v#{ARGV[0]}.tar.gz`.split[0] 55 56 code = code.sub! ast.old_sha256, sha256 57 code = code.gsub(%r{(https://github.com/getgauge/gauge/archive/refs/tags/)v\d?.\d?.\d?.tar.gz}, "https://github.com/getgauge/gauge/archive/refs/tags/v#{ARGV[0]}.tar.gz") 58 59 File.write(ARGV[1], code) 60 61 puts 'Update done.'