Skip to content
This repository was archived by the owner on Feb 28, 2019. It is now read-only.

Commit 8d2b406

Browse files
committed
Add site publishing on release
1 parent f1d94e7 commit 8d2b406

File tree

3 files changed

+83
-2
lines changed

3 files changed

+83
-2
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ sudo: false
55
rvm:
66
- 2.3.1
77
before_install:
8-
- openssl aes-256-cbc -K $encrypted_b94deb0a83fd_key -iv $encrypted_b94deb0a83fd_iv
8+
- openssl aes-256-cbc -K $encrypted_c67e65222272_key -iv $encrypted_c67e65222272_iv
99
-in etc/secrets -out ../secrets.tar -d
1010
- "(cd ../ && tar xvf secrets.tar)"
1111
- chmod 600 ../release.asc
@@ -14,7 +14,7 @@ install:
1414
- rvm use 2.3.1
1515
- gem install bundler
1616
- bundle install
17-
script: buildr package mcrt:publish_if_tagged
17+
script: buildr package mcrt:publish_if_tagged site:publish_if_tagged
1818
git:
1919
depth: false
2020
env:

etc/secrets

4 KB
Binary file not shown.

tasks/site.rake

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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

Comments
 (0)