2021-04-15 15:26:33 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
MODULE="pmd-doc"
|
|
|
|
SCRIPT_INCLUDES="log.bash"
|
|
|
|
# shellcheck source=inc/fetch_ci_scripts.bash
|
|
|
|
source "$(dirname "$0")/inc/fetch_ci_scripts.bash" && fetch_ci_scripts
|
2020-11-12 10:42:19 +01:00
|
|
|
|
|
|
|
# Used env vars:
|
|
|
|
# PMD_CI_JOB_URL
|
|
|
|
# PMD_CI_PUSH_COMMIT_COMPARE
|
|
|
|
|
|
|
|
|
2020-11-12 10:17:44 +01:00
|
|
|
#
|
|
|
|
# Executes jekyll and generates the documentation
|
|
|
|
# The documentation will be generated in the directory "docs/_site".
|
|
|
|
#
|
|
|
|
function pmd_doc_generate_jekyll_site() {
|
2021-04-15 16:44:17 +02:00
|
|
|
pushd docs || { echo "Directory 'docs' doesn't exist"; exit 1; }
|
2020-11-12 10:17:44 +01:00
|
|
|
|
|
|
|
echo -e "\n\n"
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_info "Building documentation using jekyll..."
|
2020-11-12 10:17:44 +01:00
|
|
|
bundle config set --local path vendor/bundle
|
|
|
|
bundle install
|
|
|
|
bundle exec jekyll build
|
|
|
|
|
2021-04-15 16:44:17 +02:00
|
|
|
popd || exit 1
|
2020-11-12 10:17:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Creates the pmd-doc.zip archive. It will be placed in "docs/".
|
|
|
|
#
|
|
|
|
function pmd_doc_create_archive() {
|
2021-04-15 16:44:17 +02:00
|
|
|
pushd docs || { echo "Directory 'docs' doesn't exist"; exit 1; }
|
2020-11-12 10:17:44 +01:00
|
|
|
|
|
|
|
echo -e "\n\n"
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_info "Creating pmd-doc archive..."
|
2021-04-15 16:44:17 +02:00
|
|
|
mv _site "pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}"
|
|
|
|
zip -qr "pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}.zip" "pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}/"
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_success "Successfully created pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}.zip"
|
2020-11-12 10:17:44 +01:00
|
|
|
|
2021-04-15 16:44:17 +02:00
|
|
|
popd || exit 1
|
2020-11-12 10:17:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
2021-04-15 15:26:33 +02:00
|
|
|
# Publishes the site to https://pmd.github.io/pmd-${PMD_CI_MAVEN_PROJECT_VERSION} and
|
2020-11-12 10:17:44 +01:00
|
|
|
# https://pmd.github.io/latest/
|
|
|
|
#
|
|
|
|
function publish_release_documentation_github() {
|
|
|
|
echo -e "\n\n"
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_info "Adding the new doc to pmd.github.io..."
|
2020-11-12 10:17:44 +01:00
|
|
|
# clone pmd.github.io. Note: This uses the ssh key setup earlier
|
|
|
|
# In order to speed things up, we use a sparse checkout - no need to checkout all directories here
|
|
|
|
mkdir pmd.github.io
|
|
|
|
(
|
2021-04-15 16:44:17 +02:00
|
|
|
cd pmd.github.io || { echo "Directory 'pmd.github.io' doesn't exist"; exit 1; }
|
2020-11-12 10:17:44 +01:00
|
|
|
git init
|
2020-11-12 10:42:19 +01:00
|
|
|
git config user.name "PMD CI (pmd-bot)"
|
2020-11-12 10:17:44 +01:00
|
|
|
git config user.email "andreas.dangel+pmd-bot@adangel.org"
|
|
|
|
git config core.sparsecheckout true
|
|
|
|
git remote add origin git@github.com:pmd/pmd.github.io.git
|
|
|
|
echo "/latest/" > .git/info/sparse-checkout
|
|
|
|
echo "/sitemap.xml" >> .git/info/sparse-checkout
|
|
|
|
git pull --depth=1 origin master
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_info "Copying documentation from ../docs/pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}/ to pmd-${PMD_CI_MAVEN_PROJECT_VERSION}/ ..."
|
2021-04-15 16:44:17 +02:00
|
|
|
rsync -ah --stats "../docs/pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}/" "pmd-${PMD_CI_MAVEN_PROJECT_VERSION}/"
|
2020-11-12 10:17:44 +01:00
|
|
|
git status
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_debug "Executing: git add pmd-${PMD_CI_MAVEN_PROJECT_VERSION}"
|
2021-04-15 16:44:17 +02:00
|
|
|
git add "pmd-${PMD_CI_MAVEN_PROJECT_VERSION}"
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_debug "Executing: git commit..."
|
|
|
|
git commit -q -m "Added pmd-${PMD_CI_MAVEN_PROJECT_VERSION}"
|
2020-11-12 10:17:44 +01:00
|
|
|
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_info "Copying pmd-${PMD_CI_MAVEN_PROJECT_VERSION} to latest ..."
|
2020-11-12 10:17:44 +01:00
|
|
|
git rm -qr latest
|
2021-04-15 16:44:17 +02:00
|
|
|
cp -a "pmd-${PMD_CI_MAVEN_PROJECT_VERSION}" latest
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_debug "Executing: git add latest"
|
2020-11-12 10:17:44 +01:00
|
|
|
git add latest
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_debug "Executing: git commit..."
|
|
|
|
git commit -q -m "Copying pmd-${PMD_CI_MAVEN_PROJECT_VERSION} to latest"
|
2020-11-12 10:17:44 +01:00
|
|
|
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_info "Generating sitemap.xml"
|
2020-11-13 20:34:37 +01:00
|
|
|
../docs/sitemap_generator.sh > sitemap.xml
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_debug "Executing: git add sitemap.xml"
|
2020-11-12 10:17:44 +01:00
|
|
|
git add sitemap.xml
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_debug "Executing: git commit..."
|
2020-11-12 10:17:44 +01:00
|
|
|
git commit -q -m "Generated sitemap.xml"
|
|
|
|
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_info "Executing: git push origin master"
|
2020-11-12 10:17:44 +01:00
|
|
|
git push origin master
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Updates github pages of the main repository,
|
|
|
|
# so that https://pmd.github.io/pmd/ has the latest (snapshot) content
|
|
|
|
#
|
|
|
|
function pmd_doc_publish_to_github_pages() {
|
|
|
|
echo -e "\n\n"
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_info "Pushing the new site to github pages..."
|
2020-11-12 10:17:44 +01:00
|
|
|
git clone --branch gh-pages --depth 1 git@github.com:pmd/pmd.git pmd-gh-pages
|
|
|
|
# clear the files first
|
|
|
|
rm -rf pmd-gh-pages/*
|
|
|
|
# copy the new site
|
2021-04-15 16:44:17 +02:00
|
|
|
cp -a "docs/pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}"/* pmd-gh-pages/
|
2020-11-12 10:17:44 +01:00
|
|
|
(
|
2021-04-15 16:44:17 +02:00
|
|
|
cd pmd-gh-pages || { echo "Directory 'pmd-gh-pages' doesn't exist"; exit 1; }
|
2020-11-12 10:42:19 +01:00
|
|
|
git config user.name "PMD CI (pmd-bot)"
|
2020-11-12 10:17:44 +01:00
|
|
|
git config user.email "andreas.dangel+pmd-bot@adangel.org"
|
|
|
|
git add -A
|
|
|
|
MSG="Update documentation
|
|
|
|
|
2020-11-12 10:42:19 +01:00
|
|
|
${PMD_CI_JOB_URL}
|
2020-11-12 11:42:50 +01:00
|
|
|
${PMD_CI_PUSH_COMMIT_COMPARE}"
|
2020-11-12 10:17:44 +01:00
|
|
|
git commit -q -m "$MSG"
|
|
|
|
git push git@github.com:pmd/pmd.git HEAD:gh-pages
|
2021-04-15 15:26:33 +02:00
|
|
|
pmd_ci_log_success "Successfully pushed site to https://pmd.github.io/pmd/"
|
2020-11-12 10:17:44 +01:00
|
|
|
)
|
|
|
|
}
|