CI: Add wiki doc publish to periodics
authorGeorge Joseph <gjoseph@digium.com>
Thu, 19 Jul 2018 15:34:51 +0000 (09:34 -0600)
committerGeorge Joseph <gjoseph@digium.com>
Fri, 20 Jul 2018 12:56:27 +0000 (06:56 -0600)
Change-Id: I29ba26134e5083bc6788ede235f1a5d4383c148a

tests/CI/periodics-daily.jenkinsfile
tests/CI/publishAsteriskDocs.sh [new file with mode: 0755]

index 8f53658..335edd9 100644 (file)
@@ -14,7 +14,7 @@ pipeline {
        triggers {
                cron 'H H(0-4) * * *'
        }
-       
+
        agent {
                /* All of the stages need to be performed on a docker host */
                label "swdev-docker"
@@ -26,7 +26,7 @@ pipeline {
                                /* Here's where we switch to scripted pipeline */
                                script {
                                        stage ("Checkout") {
-                                               sh "sudo chown -R jenkins:users ."  
+                                               sh "sudo chown -R jenkins:users ."
                                                sh "printenv | sort"
                                                sh "sudo tests/CI/setupJenkinsEnvironment.sh"
                                        }
@@ -43,8 +43,8 @@ pipeline {
                                        def img = docker.image(randomImage)
                                        img.pull()
 
-                                       stage ("Build") {
-                                               img.inside(dockerOptions + " --name ${bt}-build") {
+                                       img.inside(dockerOptions + " --name ${bt}-build") {
+                                               stage ("Build") {
                                                        echo 'Building..'
                                                        env.CCACHE_DIR = "/srv/cache/ccache"
                                                        sh "./tests/CI/buildAsterisk.sh --output-dir=${outputdir} --cache-dir=/srv/cache"
@@ -52,6 +52,27 @@ pipeline {
                                                        archiveArtifacts allowEmptyArchive: true, defaultExcludes: false, fingerprint: false,
                                                                artifacts: "${outputdir}/*"
                                                }
+                                               stage ("Docs") {
+
+                                                       sh 'sudo ./tests/CI/installAsterisk.sh  --user-group=jenkins:users'
+
+                                                       def docUrl = env.GIT_URL.replaceAll(/\/[^\/]+$/, "/publish-docs")
+                                                       checkout scm: [$class: 'GitSCM',
+                                                               branches: [[name: "master"]],
+                                                                       extensions: [
+                                                                               [$class: 'RelativeTargetDirectory', relativeTargetDir: "tests/CI/output/publish-docs"],
+                                                                               [$class: 'CloneOption',
+                                                                                       noTags: true,
+                                                                                       depth: 10,
+                                                                                       honorRefspec: true,
+                                                                                       shallow: true
+                                                                               ],
+                                                                       ],
+                                                                       userRemoteConfigs: [[url: docUrl]]
+                                                               ]
+
+                                                       sh "./tests/CI/publishAsteriskDocs.sh --branch-name=${BRANCH_NAME} --wiki-doc-branch-regex=\"${WIKI_DOC_BRANCH_REGEX}\""
+                                               }
                                        }
 
                                        def testGroups = readJSON file: "tests/CI/periodic-dailyTestGroups.json"
@@ -78,7 +99,7 @@ pipeline {
                                                                        }
 
                                                                        sh "sudo rm -rf ${groupDir} || : "
-                                                                       
+
                                                                        checkout scm: [$class: 'GitSCM',
                                                                                branches: [[name: "${BRANCH_NAME}"]],
                                                                                        extensions: [
diff --git a/tests/CI/publishAsteriskDocs.sh b/tests/CI/publishAsteriskDocs.sh
new file mode 100755 (executable)
index 0000000..d5c857a
--- /dev/null
@@ -0,0 +1,144 @@
+#
+# Publish Asterisk documentation to the wiki
+#
+#!/usr/bin/env bash
+CIDIR=$(dirname $(readlink -fn $0))
+source $CIDIR/ci.functions
+ASTETCDIR=$DESTDIR/etc/asterisk
+
+ASTERISK="$DESTDIR/usr/sbin/asterisk"
+CONFFILE=$ASTETCDIR/asterisk.conf
+OUTPUTDIR=${OUTPUT_DIR:-tests/CI/output/publish-docs}
+
+[ ! -d ${OUTPUTDIR} ] && mkdir -p $OUTPUTDIR
+[ x"$USER_GROUP" != x ] && sudo chown -R $USER_GROUP $OUTPUTDIR
+
+rm -rf $ASTETCDIR/extensions.{ael,lua} || :
+
+if test -f ~/.asterisk-wiki.conf; then
+   . ~/.asterisk-wiki.conf
+fi
+
+: ${AWK:=awk}
+: ${GREP:=grep}
+: ${MAKE:=make}
+: ${GIT:=git}
+
+function fail()
+{
+    echo "${PROGNAME}: " "$@" >&2
+    exit 1
+}
+
+function usage()
+{
+    echo "usage: ${PROGNAME} --branch-name=<branch> [ --user-group=<user>:<group> ] [ --output-dir=<output_dir> ]"
+}
+
+#
+# Check settings from config file
+#
+if ! test ${CONFLUENCE_URL}; then
+    fail "CONFLUENCE_URL not set in ~/.asterisk-wiki.conf"
+fi
+
+if ! test ${CONFLUENCE_USER}; then
+    fail "CONFLUENCE_USER not set in ~/.asterisk-wiki.conf"
+fi
+
+if ! test ${CONFLUENCE_PASSWORD}; then
+    fail "CONFLUENCE_PASSWORD not set in ~/.asterisk-wiki.conf"
+fi
+# needed by publishing scripts. pass via the environment so it doesn't show
+# up in the logs.
+export CONFLUENCE_PASSWORD
+
+# default space to AST
+: ${CONFLUENCE_SPACE:=AST}
+
+#
+# Check repository
+#
+if ! test -f main/asterisk.c; then
+    fail "Must run from an Asterisk checkout"
+fi
+
+#
+# Check current working copy
+#
+CHANGES=$(${GIT} status | grep 'modified:' | wc -l)
+if test ${CHANGES} -ne 0; then
+    fail "Asterisk checkout must be clean"
+fi
+
+# Verbose, and exit on any command failure
+set -ex
+
+AST_VER=$(export GREP; export AWK; ./build_tools/make_version .)
+
+# Generate latest ARI documentation
+make ari-stubs
+
+# Ensure docs are consistent with the implementation
+CHANGES=$(${GIT} status | grep 'modified:' | wc -l)
+if test ${CHANGES} -ne 0; then
+    fail "Asterisk code out of date compared to the model"
+fi
+
+# make ari-stubs may modify the $Revision$ tags in a file; revert the
+# changes
+${GIT} reset --hard
+
+#
+# Don't publish docs for non-main-release branches. We still want the above
+# validation to ensure that REST API docs are kept up to date though.
+#
+if [ -n "$WIKI_DOC_BRANCH_REGEX" ] ; then
+       if [[ ! ${BRANCH_NAME} =~ $WIKI_DOC_BRANCH_REGEX ]] ; then
+       exit 0;
+       fi
+fi
+
+#
+# Publish the REST API.
+#
+
+${OUTPUTDIR}/publish-rest-api.py --username="${CONFLUENCE_USER}" \
+        --verbose \
+        --ast-version="${AST_VER}" \
+        ${CONFLUENCE_URL} \
+        ${CONFLUENCE_SPACE} \
+        "Asterisk ${BRANCH_NAME}"
+
+rm -f ${OUTPUTDIR}/full-en_US.xml
+
+sudo $ASTERISK ${USER_GROUP:+-U ${USER_GROUP%%:*} -G ${USER_GROUP##*:}} -gn -C $CONFFILE
+for n in `seq 1 5` ; do
+       sleep 3
+       $ASTERISK -rx "core waitfullybooted" -C $CONFFILE && break
+done
+sleep 1
+$ASTERISK -rx "xmldoc dump ${OUTPUTDIR}/asterisk-docs.xml" -C $CONFFILE
+$ASTERISK -rx "core stop now" -C $CONFFILE
+
+#
+# Set the prefix argument for publishing docs
+#
+PREFIX="Asterisk ${BRANCH_NAME}"
+
+#
+# Publish XML documentation.
+#
+
+# Script assumes that it's running from TOPDIR
+pushd ${OUTPUTDIR}
+
+./astxml2wiki.py --username="${CONFLUENCE_USER}" \
+    --server=${CONFLUENCE_URL} \
+    --prefix="${PREFIX}" \
+    --space="${CONFLUENCE_SPACE}" \
+    --file=asterisk-docs.xml \
+    --ast-version="${AST_VER}" \
+    -v
+
+popd
\ No newline at end of file