From 5b9959f04220a6eb57adb090bae0ec1cab0c9d3f Mon Sep 17 00:00:00 2001 From: Santiago Zarate Date: Fri, 23 Dec 2016 09:30:17 +0100 Subject: [PATCH] Add genapi.pl script to build asciidoc from pod --- script/genapi.pl | 28 +++++++++ script/generate-documentation | 110 +++++++++++++++++++++++----------- 2 files changed, 104 insertions(+), 34 deletions(-) create mode 100755 script/genapi.pl diff --git a/script/genapi.pl b/script/genapi.pl new file mode 100755 index 000000000000..ac1d22c7f61f --- /dev/null +++ b/script/genapi.pl @@ -0,0 +1,28 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use Pod::AsciiDoctor; + +my $adoc = Pod::AsciiDoctor->new(); + +my $data_dir = "./src/"; +opendir(DIR, $data_dir) or die("Cannot read directories: $data_dir"); +my @files = grep { /\.pm$/ } readdir DIR; + +foreach my $current_file (@files) { + + open(my $ifh, '<', $data_dir . $current_file) or die("Cannot open $current_file"); + $current_file =~ s/^(.*)\.pm$/$1.asciidoc/; + open(my $ofh, ">", $current_file) or die("Cannot open $current_file"); + + print "Transforming $current_file\n"; + $adoc->append("include::header.asciidoc[]"); + $adoc->append("\n"); + $adoc->parse_from_filehandle($ifh); + + print $ofh $adoc->adoc(); + close($ofh); + close($ifh); + +} diff --git a/script/generate-documentation b/script/generate-documentation index 958c1583d662..82f118646b40 100755 --- a/script/generate-documentation +++ b/script/generate-documentation @@ -15,6 +15,78 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +function update_docs { + + if [ "${TRAVIS_BRANCH}" == "master" ]; then + echo "Branch is master, generating documentation" + else + echo "Branch is: ${TRAVIS_BRANCH}, not generating any documentation" + exit 0 + fi + + cd .. + git clone $REPO out + cd out + git checkout $TARGET_BRANCH + git config user.name "Travis CI" + git config user.email "$COMMIT_AUTHOR_EMAIL" + mkdir docs + cp -r ${tmpwd}/output/* docs + cd docs + update_api + ln -f openqa-documentation-${verbose_doc_name}.html index.html + ln -f openqa-documentation-${verbose_doc_name}.pdf current.pdf + + cd .. + git add _includes/api.html + git add $( find docs -regex '.*\.\(html\|\pdf\)' ) + echo "Update documentation to commit ${shortref}" > last.commit + echo "" >> last.commit # somehow travis does not like \n + (cd .. && git log --pretty=fuller ${TRAVIS_COMMIT} -1 >> out/last.commit) + git commit -F last.commit + git push $SSH_REPO $TARGET_BRANCH + cd .. + rm -rf out + +} + +function update_api { + + cpanm --install Pod::AsciiDoctor + + mkdir -p api/src + curl -o api/src/testapi.pm https://raw.githubusercontent.com/os-autoinst/os-autoinst/master/testapi.pm + cd api + ${TRAVIS_BUILD_DIR}/script/genapi.pl + + for file in $(ls *.asciidoc | grep -v header ); do + ${asciidoctor_bin} $file + done; + + for file in $( find -regex '.*\.html' ); do + header_template $file > $file.tmp + cat $file >> $file.tmp + mv $file.tmp $file + done; + cd .. + +} + +function header_template { +filename=$( basename -s .html $1 ) +cat < out/last.commit) - git commit -F last.commit - git push $SSH_REPO $TARGET_BRANCH - rm -rf out +if [ ${GH_PUBLISH} ] && [ ${CONTINUOUS_INTEGRATION} ]; then + update_docs fi;