Skip to content

Commit

Permalink
WIP: RDAPI-28682 enable Jenkins build and preview (#118)
Browse files Browse the repository at this point in the history
* RDAPI-28682
build.sh - updated to new version that for use Jenkins and remove netlify references
config.toml - cleanup existing hugo configuration
page-meta-links.html - cleanup the edit links menu
package.json  - update to reflect versions used in axway-open-docs

* RDAPI-28682 fix minor issue and enable previews on the branch

* RDAPI-28682 disable previews on the branch
  • Loading branch information
wlai-axway authored Jan 11, 2023
1 parent 641c627 commit a151301
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 91 deletions.
51 changes: 51 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Loads the Jenkins global pipeline library called "axway-dubl-libraries". This
// has to be added by your Jenkins admin.
@Library('axway-dubl-libraries')

// Previews will always be created by the opendocs.preview() function for pull
// requests and branches called "master" and "main". Add in the names of branches
// you want to generate previews for using the PREVIEW_FOR_BRANCHES variable e.g.
// String PREVIEW_FOR_BRANCHES = "developmay22 developaug22 developnov22"
// String PREVIEW_FOR_BRANCHES = "developmay22,developaug22,developnov22"
String PREVIEW_FOR_BRANCHES = ""

node('OpendocsBuilder') {
timestamps{ // enable timestamp in the console logs
ansiColor('xterm') { // using ansi colours
properties([
disableConcurrentBuilds(),
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '20', daysToKeepStr: '', numToKeepStr: '20'))
])

try {
// Checkout stage
stage('Checkout') {
checkout scm
}

// Potentially duplicating something already done using github workflows
// but it runs fast. Just delete this stage if you don't need it.
stage ('Markdown Lint') {
opendocs.markdownlint("content/en/**/*.md")
}

stage ('Build') {
// The build environment uses a default version of hugo. Invoke the opendocs.build
// using the following to override the default version:
// - opendocs.build(HUGO_VERSION, BUILD_COMMAND)
// - opendocs.build("0.103.1", "bash build.sh -m ci")
opendocs.build("bash build.sh -m ci")
}

stage ('Start Preview') {
opendocs.preview("${PREVIEW_FOR_BRANCHES}")
}
}
catch(Exception e) {
currentBuild.result = "FAILURE"
echo e
}
}
}
}

68 changes: 40 additions & 28 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,18 @@
# the build script
# - all other files like content/en/ content will be picked up by hugo automatically
# if they change
# -
#

set -e

DEBUG=${DEBUG:-false}
MODE=dev
while getopts ":np" opt; do

while getopts ":m:" opt; do
case ${opt} in
n ) MODE=nelify
;;
p ) MODE=nelify-preview
m ) MODE=$OPTARG
;;
* ) exit 1
* ) echo "[ERROR] Invalid option [${OPTARG}]!!";exit 1
;;
esac
done
Expand Down Expand Up @@ -64,13 +62,18 @@ function fCheckoutSubmodule() {
exit 1
fi
# the npm packages doesn't seem to be needed on the netify build server...this is just for developers
if [[ "${MODE}" == "dev" ]];then
#if [[ "${MODE}" == "dev" ]];then
echo "[INFO] Install npm packages required by docsy."
if [[ ! -d "node_modules" ]];then
npm install -D --save autoprefixer
npm install -D --save postcss-cli
if [[ -f "package.json" ]];then
npm install
else
npm install -D --save autoprefixer
npm install -D --save postcss
npm install -D --save postcss-cli
fi
fi
fi
#fi
}

# fMergeContent:
Expand All @@ -86,6 +89,7 @@ function fMergeContent() {
local _c_context
local _c_path
local _c_name
local _branch_name
local _ln_opt='-sf'
if [[ "$DEBUG" == "true" ]];then
_ln_opt='-vsf'
Expand Down Expand Up @@ -131,10 +135,21 @@ function fMergeContent() {
fi
done

# This soft link makes the git info available for hugo to populate the date with git hash in the footer.
# Note that common files coming from axway-open-docs-common will not have this information and the pages
# will use the "date" value at the top of the page.
ln ${_ln_opt} $(pwd)/.git ${BUILD_DIR}/.git
# Update the github_branch Param value in config.toml. This is used by the github edit link. If
# the BRANCH_NAME is not set then it's either a local build or a PR. We don't want to enable the
# github edit link when in this scenario.
_branch_name=${BRANCH_NAME} # the BRANCH_NAME variable comes from Jenkins
if [[ ! "${_branch_name}" =~ ^"PR-"* ]];then
unlink build/config.toml
cp -f config.toml build/config.toml
sed -i "s|# github_branch|github_branch|g" build/config.toml
sed -i "s|github_branch = .*|github_branch = \"${_branch_name}\"|g" build/config.toml
fi

# This soft link makes the git info available for hugo to populate the date with git hash in the footer.
# Note that common files coming from axway-open-docs-common will not have this information and the pages
# will use the "date" value at the top of the page.
ln ${_ln_opt} $(pwd)/.git ${BUILD_DIR}/.git

echo "[INFO] Following symlinks were created:"
for xxx in `find $(basename ${BUILD_DIR}) -type l`;do
Expand All @@ -148,23 +163,20 @@ function fRunHugo() {
cd ${BUILD_DIR}
mkdir public
case "${MODE}" in
"dev")
hugo server
;;
"nelify")
hugo
# Moving the "publish" directory to the ROOT of the workspace. Netlify can't publish a
# different directory even if the "Publish directory" is changed to specify a different directory.
mv -f ${BUILD_DIR}/public ${PROJECT_DIR}
;;
"nelify-preview")
hugo -b $DEPLOY_PRIME_URL
mv -f ${BUILD_DIR}/public ${PROJECT_DIR}
;;
"dev")
hugo server
;;
"ci")
hugo
;;
*)
echo "[ERROR] Build MODE [${MODE}] is invalid!!"
exit 1
;;
esac
}

fCheckoutSubmodule
fMergeContent
fRunHugo
echo "[INFO] Done"
echo "[INFO] Done."
11 changes: 7 additions & 4 deletions config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
baseURL = "https://platform-management.netlify.app/"
baseURL = "/"
title = "Platform-Management"

enableRobotsTXT = true
Expand Down Expand Up @@ -47,7 +47,7 @@ blog = "/:section/:year/:month/:day/:slug/"

[markup.goldmark]
[markup.goldmark.renderer]
unsafe = true #this overrides the default setting of false and allows goldmark to render HTML as Markdown
unsafe = true #this overrides the default setting of false and allows goldmark to render HTML as well as Markdown

# Image processing configuration.
[imaging]
Expand All @@ -64,8 +64,8 @@ id = "UA-56643615-3"

[languages]
[languages.en]
title = "Axway Documentation"
description = "Axway Documentation"
# title = ""
# description = ""
languageName ="English"
# Weight used for sorting.
weight = 1
Expand All @@ -85,6 +85,9 @@ github_repo = "https://github.com/Axway/platform-management-docs"
# An optional link to a related project repo. For example, the sibling repository where your product code lives.
# github_project_repo = "https://github.com/google/docsy"

# Github branch value for the edit on github link.
# github_branch = "master"

# Specify a value here if your content directory is not in your repo's root directory
# github_subdir = ""

Expand Down
49 changes: 17 additions & 32 deletions layouts/partials/page-meta-links.html
Original file line number Diff line number Diff line change
@@ -1,36 +1,21 @@
{{ if .Path }}
{{ if .File }}
{{ $pathFormatted := replace .File.Path "\\" "/" -}}
{{ $gh_repo := ($.Param "github_repo") }}
{{ $gh_subdir := ($.Param "github_subdir") }}
{{ $gh_project_repo := ($.Param "github_project_repo") }}
{{ if $gh_repo }}
{{ $gh_branch := ($.Param "github_branch") }}
<div class="td-page-meta ml-2 pb-1 pt-2 mb-0">
{{ $gh_branch := "master" }}
{{ if in (.Site.BaseURL | string) "develop" }}
{{ $gh_branch = "develop"}}
{{ end }} <!-- end of if develop -->
{{ $editURL := printf "%s/edit/%s/content/%s" $gh_repo $gh_branch .Path }}
{{ if and ($gh_subdir) (.Site.Language.Lang) }}
{{ $editURL = printf "%s/edit/%s/%s/content/%s/%s" $gh_repo $gh_branch $gh_subdir ($.Site.Language.Lang) $.Path }}
{{ else if .Site.Language.Lang }}
{{ $editURL = printf "%s/edit/%s/content/%s/%s" $gh_repo $gh_branch ($.Site.Language.Lang) .Path }}
{{ else if $gh_subdir }}
{{ $editURL = printf "%s/edit/%s/%s/content/%s" $gh_repo $gh_branch $gh_subdir $.Path }}
{{ end }} <!-- end of subdir lang conds -->
<a href="{{ $editURL }}" target="_blank"><i class="fa fa-edit fa-fw"></i> {{ T "post_edit_this" }}</a>
{{ $baseURL := strings.TrimSuffix "/" .Site.BaseURL }}
{{ $dir := (split .File.Dir "/") }}
{{ $cms_collection := index $dir 0 }}
{{ with (index $dir 1) }}
{{ $cms_collection = . }}
{{ end }}
{{ with (index $dir 2) }}
{{ $cms_collection = . }}
{{ end }}
{{ with (index $dir 3) }}
{{ $cms_collection = . }}
{{ end }} <!-- end of with -->
{{ $cmsURL := printf "%s/admin/#/edit/%s/%s" $baseURL $cms_collection .File.BaseFileName }}
<a href="{{ $cmsURL }}" target="_blank"><i class="fas fa-columns fa-fw"></i> {{ T "post_edit_cms" }}</a>
{{ if $gh_repo }}
{{ if $gh_branch }}
{{ $editURL := printf "%s/edit/%s/content/%s" $gh_repo $gh_branch $pathFormatted }}
{{ if and ($gh_subdir) (.Site.Language.Lang) }}
{{ $editURL = printf "%s/edit/%s/%s/content/%s/%s" $gh_repo $gh_branch $gh_subdir ($.Site.Language.Lang) $pathFormatted }}
{{ else if .Site.Language.Lang }}
{{ $editURL = printf "%s/edit/%s/content/%s/%s" $gh_repo $gh_branch ($.Site.Language.Lang) $pathFormatted }}
{{ else if $gh_subdir }}
{{ $editURL = printf "%s/edit/%s/%s/content/%s" $gh_repo $gh_branch $gh_subdir $pathFormatted }}
{{ end }} <!-- end of subdir lang conds -->
<a href="{{ $editURL }}" target="_blank"><i class="fa fa-edit fa-fw"></i> {{ T "post_edit_this" }}</a>
{{ end }} <!-- end of if gh_branch -->
{{ end }} <!-- end of if gh_repo -->
</div>
{{ end }} <!-- end of if repo -->
{{ end }} <!-- end if path -->
{{ end }} <!-- end if File -->
24 changes: 0 additions & 24 deletions netlify.toml

This file was deleted.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
},
"homepage": "https://github.com/bep/tech-doc-hugo#readme",
"devDependencies": {
"autoprefixer": "^9.8.6",
"autoprefixer": "^10.2.6",
"grunt": "^1.3.0",
"grunt-markdownlint": "^2.6.0",
"grunt-markdownlint": "^3.1.4",
"minimist": "^1.2.5",
"postcss-cli": "^7.1.2"
"postcss": "^8.2.10",
"postcss-cli": "^8.3.1"
}
}

0 comments on commit a151301

Please sign in to comment.