forked from docToolchain/docToolchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.ci.sh
executable file
·167 lines (150 loc) · 6.15 KB
/
.ci.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/bash
set -o errtrace -o nounset -o pipefail -o errexit
# Enable build on Travis as well as on GH Actions
set +u
if test "${GITHUB_WORKFLOW}"; then
BRANCH=${GITHUB_REF##*/}
BUILD_DIR=${GITHUB_WORKSPACE}
BUILD_NUMBER="${GITHUB_WORKFLOW}-${GITHUB_RUN_ID}-${GITHUB_RUN_NUMBER}"
CI_SERVER="Github"
PULL_REQUEST=$(test "${GITHUB_HEAD_REF}" && echo "true" || echo "false")
# JDK_VERSION is set by GH Action
# RUNNER_OS is set by GH Action
TRAVIS_REPO_SLUG=${GITHUB_REPOSITORY}
elif test "${TRAVIS_BRANCH}"; then
BRANCH=${TRAVIS_BRANCH}
BUILD_NUMBER=${TRAVIS_BUILD_NUMBER}
BUILD_DIR=${TRAVIS_BUILD_DIR}
CI_SERVER="Travis"
PULL_REQUEST=${TRAVIS_PULL_REQUEST:-"false"}
JDK_VERSION=${TRAVIS_JDK_VERSION}
RUNNER_OS="ubuntu-latest"
else
echo "Cannot determine CI Server (Travis or Github)" >&2
exit 1
fi
GH_TOKEN=${GITHUB_TOKEN}
echo "${TRAVIS_REPO_SLUG}"
set -u
# Goto directory of this script
cd "$(dirname "${BASH_SOURCE[0]}")"
cleaning () {
echo "############################################"
echo "# #"
echo "# Cleaning #"
echo "# #"
echo "############################################"
./gradlew clean
}
dependency_info() {
echo "############################################"
echo "# #"
echo "# Check for dependency updates #"
echo "# #"
echo "############################################"
./gradlew -b init.gradle dependencyUpdates
./gradlew dependencyUpdates
}
unit_tests () {
echo "############################################"
echo "# #"
echo "# Unit testing #"
echo "# #"
echo "############################################"
if [ "${BRANCH}" == "ng" ] || [ "${BRANCH}" == "main-2.x" ] ; then
echo "skipping tests for now"
else
./gradlew test --info
fi
}
check_for_clean_worktree() {
echo "############################################"
echo "# #"
echo "# Check for clean worktree #"
echo "# #"
echo "############################################"
# To be executed as latest possible step, to ensures that there is no
# uncommitted code and there are no untracked files, which means .gitignore is
# complete and all code is part of a reviewable commit.
GIT_STATUS="$(git status --porcelain)"
if [[ ${GIT_STATUS} ]]; then
echo "Your worktree is not clean, there is either uncommitted code or there are untracked files:"
echo "${GIT_STATUS}"
exit 1
fi
}
create_doc () {
echo "############################################"
echo "# #"
echo "# Create documentation #"
echo "# #"
echo "############################################"
echo "TRAVIS_BRANCH=${BRANCH}"
if [ "${BRANCH}" == "ng" ] || [ "${BRANCH}" == "main-2.x" ] ; then
echo ">>> tasks"
./dtcw local tasks
echo ">>> exportMarkdown"
./dtcw local exportMarkdown
echo ">>> exportChangelog"
./dtcw local exportChangeLog
echo ">>> exportContributors"
./dtcw local exportContributors
echo ">>> generateSite"
./dtcw local generateSite --stacktrace
[ -d docs ] || mkdir docs
cp -r build/microsite/output/. docs/.
# [ -d docs/htmlchecks ] || mkdir docs/htmlchecks
# cp -r build/docs/report/htmlchecks/. docs/htmlchecks/.
else
echo ">>> exportMarkdown"
# ./gradlew exportMarkdown exportChangeLog exportContributors generateHTML htmlSanityCheck --stacktrace && ./copyDocs.sh
echo ">>> currently disabled"
fi
}
publish_doc () {
echo "publish_doc"
echo "${PULL_REQUEST} | ${JDK_VERSION} | ${BRANCH}"
# Take from and modified http://sleepycoders.blogspot.de/2013/03/sharing-travis-ci-generated-files.html
# ensure publishing doesn't run on pull requests, only when token is available and only on JDK11 matrix build and on master or a travisci test branch
if [ "${PULL_REQUEST}" == "false" ] && [ -n "${GH_TOKEN}" ] && { [ "${JDK_VERSION}" == "adopt-11" ] || [ "${JDK_VERSION}" == "openjdk11" ] || { [ "${JDK_VERSION}" == "11-adopt" ] && [ "${RUNNER_OS}" == "ubuntu-latest" ]; }; } && { [ "${BRANCH}" == "travisci" ] || [ "${BRANCH}" == "master" ] || [ "${BRANCH}" == "ng" ] || [ "${BRANCH}" == "main-1.x" ] || [ "${BRANCH}" == "main-2.x" ]; } ; then
echo "############################################"
echo "# #"
echo "# Publish documentation #"
echo "# #"
echo "############################################"
echo -e "Starting to update gh-pages\n"
#go to home and setup git
cd "${HOME}"
git config --global user.email "[email protected]"
git config --global user.name "Travis"
#using token clone gh-pages branch
git clone --quiet --branch=gh-pages "https://$GITHUB_ACTOR:[email protected]/${TRAVIS_REPO_SLUG}.git" gh-pages > /dev/null
if [ "${BRANCH}" == "master" ] || [ "${BRANCH}" == "main-1.x" ] ; then
#go into directory and copy data we're interested in to that directory
cd gh-pages
rm -rf v1.3.x/*
cp -Rf "${BUILD_DIR}"/docs/* v1.3.x/.
fi
if [ "${BRANCH}" == "ng" ] || [ "${BRANCH}" == "main-2.x" ] ; then
#go into directory and copy data we're interested in to that directory
cd gh-pages
rm -rf v2.0.x/*
cp -Rf "${BUILD_DIR}"/build/microsite/output/* v2.0.x/.
fi
#add, commit and push files
git add -f .
git commit -m "${CI_SERVER} build '${BUILD_NUMBER}' pushed to gh-pages"
echo "push"
git push -fq origin gh-pages > /dev/null
echo -e "Done publishing to gh-pages.\n"
fi
}
cleaning
dependency_info
#unit_tests
#check_for_clean_worktree fails because of a modified gradlew.bat
#but we work on a clean checkout, so how can this be?
#let's remove this check for now
#check_for_clean_worktree
create_doc
publish_doc