-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmaven-deploy-javadoc.sh
executable file
·131 lines (104 loc) · 4.15 KB
/
maven-deploy-javadoc.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/sh -e
# Copyright 2017 realglobe Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Maven プロジェクト生成した Javadoc を GitHub Pages にデプロイする。
# pom.xml のあるディレクトリで実行する。事前に以下の準備が必要。
# 1. デプロイ用の鍵ペアを用意する。
# 2. 公開鍵を Github の Javadoc 用プロジェクト(デプロイ先)の Deploy Keys に登録する。
# 3. 秘密鍵をデプロイ元プロジェクトディレクトリで travis encrypt-file して追加する。
# 4. Travis CI のデプロイ元プロジェクトの環境変数に ENCRYPTION_LABEL を追加する。
# 既に同一バージョンの Javadoc がデプロイされている場合はデプロイしない。
# ただし、環境変数 FORCE_DEPLOY が空でない場合は上書きデプロイする。
# target/site/apidocs か target/apidocs に Javadoc を生成しておくこと。
javadoc_repo=${JAVADOC_REPO:=https://github.com/realglobe-Inc/javadoc.git}
deploy_key=${DEPLOY_KEY:=javadoc-deploy-key.enc}
work_dir=${WORK_DIR:=.deploy-workspace}
deployer_name=${DEPLOYER_NAME:=rg-ci}
deployer_email=${DEPLOYER_EMAIL:[email protected]}
if ! [ -f pom.xml ]; then
echo 'no pom.xml' 1>&2
exit 1
elif ! [ -f ${deploy_key} ]; then
echo "no ${deploy_key}" 1>&2
exit 1
elif [ -z "${ENCRYPTION_LABEL}" ]; then
echo 'no environment variable ENCRYPTION_LABEL' 1>&2
exit 1
fi
apidocs_dir=target/site/apidocs
if ! [ -d ${apidocs_dir} ]; then
apidocs_dir=target/apidocs
if ! [ -d ${apidocs_dir} ]; then
echo "no javadoc direcotry" 1>&2
exit 1
fi
fi
group_id=$(xmllint --xpath '/*[local-name()="project"]/*[local-name()="groupId"]/text()' pom.xml)
artifact_id=$(xmllint --xpath '/*[local-name()="project"]/*[local-name()="artifactId"]/text()' pom.xml)
version=$(xmllint --xpath '/*[local-name()="project"]/*[local-name()="version"]/text()' pom.xml)
mkdir -p ${work_dir}
# デプロイ用の ssh 鍵を準備する
encrypted_key_var="encrypted_${ENCRYPTION_LABEL}_key"
encrypted_iv_var="encrypted_${ENCRYPTION_LABEL}_iv"
eval encrypted_key=\$${encrypted_key_var}
eval encrypted_iv=\$${encrypted_iv_var}
openssl aes-256-cbc -K ${encrypted_key} -iv ${encrypted_iv} -in ${deploy_key} -out ${work_dir}/deploy-key -d
chmod 600 ${work_dir}/deploy-key
eval "$(ssh-agent -s)"
ssh-add ${work_dir}/deploy-key
javadoc_root_dir=${work_dir}/javadoc
git clone ${javadoc_repo} ${javadoc_root_dir}
group_dir=$(echo ${group_id} | sed 's/\./\//g')
javadoc_dir=${javadoc_root_dir}/${group_dir}/${artifact_id}/${version}
if [ -e ${javadoc_dir} ]; then
if [ -n "${FORCE_DEPLOY}" ]; then
rm -rf ${javadoc_dir}
else
echo "already exists"
exit
fi
fi
mkdir -p $(dirname ${javadoc_dir})
cp -r ${apidocs_dir} ${javadoc_dir}
(
cd ${javadoc_root_dir}
# ディレクトリ列挙用 HTML をつくる
dir=${group_dir}/${artifact_id}
while true; do
(
cd ${dir}
echo '<html><body><ul>' > index.html
if [ ${dir} != . ]; then
echo '<li><a href="..">..</a></li>' >> index.html
fi
for i in $(find . -mindepth 1 -maxdepth 1 -name ".*" -prune -o -type d -printf '%f\n' | sort -V); do
echo '<li><a href="'${i}'">'${i}'</a></li>' >> index.html
done
echo '</html></body></ul>' >> index.html
)
if [ ${dir} = . ]; then
break
fi
dir=$(dirname ${dir})
done
git config user.name ${deployer_name}
git config user.email ${deployer_email}
git add -A
if ! git commit -m "Add javadoc (${group_id}:${artifact_id}:${version})"; then
echo 'no changes'
exit
fi
ssh_repo=$(echo ${javadoc_repo} | sed 's/https:\/\/github.com\//[email protected]:/')
git push ${ssh_repo} master
)