From a1513010202bbe28a884310d3983213c2681f02e Mon Sep 17 00:00:00 2001 From: Wing Hon Lai Date: Wed, 11 Jan 2023 19:04:35 +0000 Subject: [PATCH] WIP: RDAPI-28682 enable Jenkins build and preview (#118) * 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 --- Jenkinsfile | 51 ++++++++++++++++++++ build.sh | 68 ++++++++++++++++----------- config.toml | 11 +++-- layouts/partials/page-meta-links.html | 49 +++++++------------ netlify.toml | 24 ---------- package.json | 7 +-- 6 files changed, 119 insertions(+), 91 deletions(-) create mode 100644 Jenkinsfile delete mode 100644 netlify.toml diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..8adc7293 --- /dev/null +++ b/Jenkinsfile @@ -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 + } + } + } +} + diff --git a/build.sh b/build.sh index 415412a9..5e09cb12 100755 --- a/build.sh +++ b/build.sh @@ -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 @@ -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: @@ -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' @@ -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 @@ -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" \ No newline at end of file +echo "[INFO] Done." \ No newline at end of file diff --git a/config.toml b/config.toml index dd80ef7f..824c59f4 100644 --- a/config.toml +++ b/config.toml @@ -1,4 +1,4 @@ -baseURL = "https://platform-management.netlify.app/" +baseURL = "/" title = "Platform-Management" enableRobotsTXT = true @@ -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] @@ -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 @@ -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 = "" diff --git a/layouts/partials/page-meta-links.html b/layouts/partials/page-meta-links.html index 9c945f8d..2ecd75aa 100644 --- a/layouts/partials/page-meta-links.html +++ b/layouts/partials/page-meta-links.html @@ -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") }}
-{{ $gh_branch := "master" }} -{{ if in (.Site.BaseURL | string) "develop" }} -{{ $gh_branch = "develop"}} -{{ end }} -{{ $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 }} - {{ T "post_edit_this" }} -{{ $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 }} -{{ $cmsURL := printf "%s/admin/#/edit/%s/%s" $baseURL $cms_collection .File.BaseFileName }} - {{ T "post_edit_cms" }} +{{ 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 }} + {{ T "post_edit_this" }} + {{ end }} +{{ end }}
-{{ end }} -{{ end }} +{{ end }} diff --git a/netlify.toml b/netlify.toml deleted file mode 100644 index 33874117..00000000 --- a/netlify.toml +++ /dev/null @@ -1,24 +0,0 @@ -# Hugo build configuration for Netlify -# (https://gohugo.io/hosting-and-deployment/hosting-on-netlify/#configure-hugo-version-in-netlify) - -# Default build settings -[build] -publish = "public" -command = "bash build.sh -n" - -# "production" environment specific build settings -[build.environment] -HUGO_VERSION = "0.101.0" - -[context.production.environment] -HUGO_ENV = "production" - -[context.deploy-preview] -command = "bash build.sh -p" - -[context.develop] -command = "bash build.sh -p" - -[dev] - targetPort = 1313 - port = 1314 diff --git a/package.json b/package.json index a768b1e8..ef999505 100644 --- a/package.json +++ b/package.json @@ -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" } }