|
| 1 | +require File.expand_path(File.dirname(__FILE__) + '/util') |
| 2 | + |
| 3 | +SITE_DIR = "#{WORKSPACE_DIR}/target/doc" |
| 4 | + |
| 5 | +desc 'Publish the website' |
| 6 | +task 'site:publish' => 'doc' do |
| 7 | + origin_url = 'https://github.com/react4j/react4j.github.io.git' |
| 8 | + |
| 9 | + travis_build_number = ENV['TRAVIS_BUILD_NUMBER'] |
| 10 | + if travis_build_number |
| 11 | + origin_url = origin_url.gsub('https://github.com/', '[email protected]:') |
| 12 | + end |
| 13 | + |
| 14 | + component_name = Buildr.projects[0].name.gsub('react4j-', '') |
| 15 | + |
| 16 | + local_dir = "#{WORKSPACE_DIR}/target/remote_site" |
| 17 | + rm_rf local_dir |
| 18 | + |
| 19 | + sh "git clone -b master --depth 1 #{origin_url} #{local_dir}" |
| 20 | + |
| 21 | + # This is the list of directories controlled by other processes that should be left alone |
| 22 | + excludes = %w() |
| 23 | + |
| 24 | + in_dir(local_dir) do |
| 25 | + message = |
| 26 | + "Publishing docs for component #{component_name}#{travis_build_number.nil? ? '' : " - Travis build: #{travis_build_number}"}" |
| 27 | + |
| 28 | + rm_rf "#{local_dir}/#{component_name}" |
| 29 | + cp_r SITE_DIR, "#{local_dir}/#{component_name}" |
| 30 | + sh 'git add . -f' |
| 31 | + puts `git commit -m "#{message}"` |
| 32 | + if 0 == $?.exitstatus |
| 33 | + sh 'git push origin master' |
| 34 | + end |
| 35 | + end |
| 36 | +end |
| 37 | + |
| 38 | +desc 'Publish website iff current HEAD is a tag on blessed branch' |
| 39 | +task 'site:publish_if_tagged' do |
| 40 | + candidate_branches = %w(master) |
| 41 | + tag = get_head_tag_if_any |
| 42 | + if tag.nil? |
| 43 | + puts 'Current HEAD is not a tag. Skipping site:publish step.' |
| 44 | + else |
| 45 | + puts "Current HEAD is a tag: #{tag}" |
| 46 | + if is_tag_on_candidate_branches?(tag, candidate_branches) |
| 47 | + task('site:publish').invoke |
| 48 | + end |
| 49 | + end |
| 50 | +end |
| 51 | + |
| 52 | +def get_head_tag_if_any |
| 53 | + version = `git describe --exact-match --tags 2>&1` |
| 54 | + if 0 == $?.exitstatus && version =~ /^v[0-9]/ && (ENV['TRAVIS_BUILD_ID'].nil? || ENV['TRAVIS_TAG'].to_s != '') |
| 55 | + version.strip |
| 56 | + else |
| 57 | + nil |
| 58 | + end |
| 59 | +end |
| 60 | + |
| 61 | +def is_tag_on_branch?(tag, branch) |
| 62 | + output = `git tag --merged #{branch} 2>&1` |
| 63 | + tags = output.split |
| 64 | + tags.include?(tag) |
| 65 | +end |
| 66 | + |
| 67 | +def is_tag_on_candidate_branches?(tag, branches) |
| 68 | + sh 'git fetch origin' |
| 69 | + branches.each do |branch| |
| 70 | + if is_tag_on_branch?(tag, branch) |
| 71 | + puts "Tag #{tag} is on branch: #{branch}" |
| 72 | + return true |
| 73 | + elsif is_tag_on_branch?(tag, "origin/#{branch}") |
| 74 | + puts "Tag #{tag} is on branch: origin/#{branch}" |
| 75 | + return true |
| 76 | + else |
| 77 | + puts "Tag #{tag} is not on branches: #{branch} or origin/#{branch}" |
| 78 | + end |
| 79 | + end |
| 80 | + false |
| 81 | +end |
0 commit comments