|
| 1 | +#!/usr/bin/env ruby |
| 2 | + |
| 3 | +require "json" |
| 4 | + |
| 5 | +DOWNSTREAM_FORKS = ["swift", "swift-corelibs-foundation", "swift-corelibs-xctest"] |
| 6 | + |
| 7 | +def sync_checkout(options) |
| 8 | + config = JSON.parse(File.read(options[:config_path])) |
| 9 | + branch_schemes = config["branch-schemes"] |
| 10 | + upstream = branch_schemes[options[:upstream]] |
| 11 | + raise "No branch scheme for #{options[:upstream]}" unless upstream |
| 12 | + downstream = branch_schemes[options[:downstream]] |
| 13 | + raise "No branch scheme for #{options[:downstream]}" unless downstream |
| 14 | + |
| 15 | + upstream["repos"].each do |project, upstream_branch| |
| 16 | + next if DOWNSTREAM_FORKS.include?(project) |
| 17 | + downstream_branch = downstream["repos"][project] |
| 18 | + next if downstream_branch == upstream_branch |
| 19 | + |
| 20 | + puts "Please update #{project} to #{upstream_branch} (currently #{downstream_branch})" |
| 21 | + end |
| 22 | +end |
| 23 | + |
| 24 | +def main |
| 25 | + require "optparse" |
| 26 | + options = { |
| 27 | + config_path: File.expand_path(File.join(__dir__, "..", "update_checkout", "update-checkout-config.json")), |
| 28 | + upstream: "main", |
| 29 | + downstream: "wasm", |
| 30 | + } |
| 31 | + |
| 32 | + opts = OptionParser.new do |opts| |
| 33 | + opts.banner = "Usage: sync-update-checkout.rb [options]" |
| 34 | + |
| 35 | + opts.on("--config PATH", "Path to update-checkout-config.json") do |path| |
| 36 | + options[:config_path] = path |
| 37 | + end |
| 38 | + |
| 39 | + opts.on("--upstream BRANCH", "Name of upstream branch") do |branch| |
| 40 | + options[:upstream] = branch |
| 41 | + end |
| 42 | + |
| 43 | + opts.on("--downstream BRANCH", "Name of downstream branch") do |branch| |
| 44 | + options[:downstream] = branch |
| 45 | + end |
| 46 | + end |
| 47 | + opts.parse! |
| 48 | + |
| 49 | + sync_checkout(options) |
| 50 | +end |
| 51 | + |
| 52 | +main if $0 == __FILE__ |
0 commit comments