-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathupload-documentation.sh
executable file
·100 lines (84 loc) · 4.61 KB
/
upload-documentation.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
#!/usr/bin/env -S bash -e
PROJECT=$1
RELEASE_VERSION=$2
VERSION_FAMILY=$3
WORKSPACE=${WORKSPACE:-'.'}
if [ -z "$PROJECT" ]; then
echo "ERROR: Project not supplied"
exit 1
fi
if [ -z "$RELEASE_VERSION" ]; then
echo "ERROR: Release version argument not supplied"
exit 1
fi
if [ -z "$VERSION_FAMILY" ]; then
echo "ERROR: Version family argument not supplied"
exit 1
fi
pushd ${WORKSPACE}
DIST=distribution/target/dist/hibernate-$PROJECT-$RELEASE_VERSION-dist.zip
if [ ! -f $DIST ]; then
# Legacy layout; see upload-distribution.sh
DIST=distribution/target/hibernate-$PROJECT-$RELEASE_VERSION-dist.zip
fi
unzip $DIST -d distribution/target/unpacked
DOCUMENTATION_DIRECTORY=distribution/target/unpacked/hibernate-${PROJECT}-${RELEASE_VERSION}/docs
# Add various metadata to the header
if [ "$PROJECT" == "validator" ]; then
META_DESCRIPTION="Hibernate Validator, Annotation based constraints for your domain model - Reference Documentation"
META_KEYWORDS="hibernate, validator, hibernate validator, validation, bean validation"
elif [ "$PROJECT" == "ogm" ]; then
META_DESCRIPTION="Hibernate OGM, JPA for NoSQL datastores - Reference Documentation"
META_KEYWORDS="hibernate, ogm, hibernate ogm, nosql, jpa, infinispan, mongodb, neo4j, cassandra, couchdb, ehcache, redis"
elif [ "$PROJECT" == "search" ]; then
META_DESCRIPTION="Hibernate Search, full text search for your entities - Reference Documentation"
META_KEYWORDS="hibernate, search, hibernate search, full text, lucene, elasticsearch"
else
META_DESCRIPTION=""
META_KEYWORDS=""
fi
for file in $(find ${DOCUMENTATION_DIRECTORY}/reference/ -name \*.html); do
# Only add the information if the file is generated by Docbook (the Asciidoctor output already has these information)
if grep -q '<meta name="generator" content="DocBook ' ${file}; then
# Add the metadata to the header
sed -i 's@</title><link rel="stylesheet"@</title><!-- HibernateDoc.Meta --><meta name="description" content="'"$META_DESCRIPTION"'" /><meta name="keywords" content="'"$META_KEYWORDS"'" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><link rel="canonical" href="https://docs.jboss.org/hibernate/stable/'"$PROJECT"'/reference/en-US/html_single/" /><!-- /HibernateDoc.Meta --><link rel="stylesheet"@' ${file}
# Add the outdated content Javascript at the bottom of the pages
sed -i 's@</body>@<!-- HibernateDoc.OutdatedContent --><script src="//code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script><script src="/hibernate/_outdated-content/outdated-content.js" type="text/javascript"></script><script type="text/javascript">var jQuery_3_1 = $.noConflict(true); jQuery_3_1(document).ready(function() { HibernateDoc.OutdatedContent.install("'"$PROJECT"'"); });</script><!-- /HibernateDoc.OutdatedContent --></body>@' ${file}
fi
done
# Push the documentation to the doc server
# Note we have to use filemgmt-prod-sync.jboss.org for rsync, not filemgmt.jboss.org or filemgmt-prod.jboss.org
rsync -rzh --progress --delete ${DOCUMENTATION_DIRECTORY}/ filemgmt-prod-sync.jboss.org:/docs_htdocs/hibernate/${PROJECT}/$VERSION_FAMILY
# If the release is the new stable one, we need to update the doc server (outdated content descriptor and /stable/ symlink)
function version_gt() {
test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1";
}
if [[ $RELEASE_VERSION =~ .*\.Final ]]; then
wget -q http://docs.jboss.org/hibernate/_outdated-content/${PROJECT}.json -O ${PROJECT}.json
if [ ! -s ${PROJECT}.json ]; then
echo "Error downloading the ${PROJECT}.json descriptor. Exiting."
exit 1
fi
CURRENT_STABLE_VERSION=$(cat ${PROJECT}.json | jq -r ".stable")
if [ "$CURRENT_STABLE_VERSION" != "$VERSION_FAMILY" ] && version_gt $VERSION_FAMILY $CURRENT_STABLE_VERSION; then
cat ${PROJECT}.json | jq ".stable = \"$VERSION_FAMILY\"" > ${PROJECT}-updated.json
if [ ! -s ${PROJECT}-updated.json ]; then
echo "Error updating the ${PROJECT}.json descriptor. Exiting."
exit 1
fi
# filemgmt-prod*.jboss.org don't allow scp, so we'll just rsync a single file...
# That's a bit overkill but at least it works.
# Note we have to use filemgmt-prod-sync.jboss.org for rsync, not filemgmt.jboss.org or filemgmt-prod.jboss.org
rsync -z --progress ${PROJECT}-updated.json filemgmt-prod-sync.jboss.org:/docs_htdocs/hibernate/_outdated-content/${PROJECT}.json
rm -f ${PROJECT}-updated.json
# update the symlink of stable to the latest release
# don't indent the EOF!
sftp filemgmt-prod.jboss.org -b <<EOF
cd docs_htdocs/hibernate/stable
rm ${PROJECT}
ln -s ../${PROJECT}/$VERSION_FAMILY ${PROJECT}
EOF
fi
rm -f ${PROJECT}.json
fi
popd