ci: add Jenkinsfile for building docs page (#410)

CI setup that builds the `master` branch and pushes it to `gh-pages`
branch in the repo which is published by GitHub pages.

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub 2022-01-24 11:53:45 +01:00 committed by GitHub
parent adcec18c3e
commit 671c757fa2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 95 additions and 94 deletions

View File

@ -1,91 +0,0 @@
name: Webchat Deploy GH Pages
on:
push:
branches:
- 'master'
jobs:
deploy_gh_pages:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set git author identity
run: |
git config user.name "GitHub Action On js-waku Repo"
git config user.email "franck+ghpages@status.im"
- name: Install NodeJS
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Cache npm cache
uses: actions/cache@v2
with:
path: ~/.npm
key: node-v2-${{ hashFiles('**/package-lock.json') }}
- name: "[js-waku] install using npm ci"
uses: bahmutov/npm-install@v1
- name: "[js-waku] build"
run: npm run build
- name: "[web-chat] install using npm i"
run: npm install
working-directory: examples/web-chat
- name: "[web-chat] build"
run: npm run build
working-directory: examples/web-chat
- name: "[web-chat] Deploy on gh pages to /"
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./examples/web-chat/build
- name: "[eth-pm] install using npm i"
run: npm install
working-directory: examples/eth-pm
- name: "[eth-pm] build"
run: npm run build
working-directory: examples/eth-pm
- name: "[eth-pm] Deploy on gh pages to /eth-pm"
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./examples/eth-pm/build
destination_dir: eth-pm
- name: "[eth-pm-wallet] install using npm i"
run: npm install
working-directory: examples/eth-pm-wallet-encryption
- name: "[eth-pm-wallet] build"
run: npm run build
working-directory: examples/eth-pm-wallet-encryption
- name: "[eth-pm-wallet] Deploy on gh pages to /eth-pm-wallet"
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./examples/eth-pm-wallet-encryption/build
destination_dir: eth-pm-wallet
- name: Generate docs
run: npm run doc:html
- name: Deploy documentation on gh pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
keep_files: true # Do not delete web chat app
publish_dir: ./build/docs
destination_dir: docs

40
ci/Jenkinsfile.gh-pages Normal file
View File

@ -0,0 +1,40 @@
pipeline {
agent { label 'linux' }
options {
disableConcurrentBuilds()
/* manage how many builds we keep */
buildDiscarder(logRotator(
numToKeepStr: '20',
daysToKeepStr: '30',
))
}
environment {
GIT_AUTHOR_NAME = 'status-im-auto'
GIT_AUTHOR_EMAIL = 'auto@status.im'
}
stages {
stage('Install Deps') {
steps {
sh 'yarn install'
}
}
stage('Build') {
steps {
sh 'yarn run doc'
}
}
stage('Publish Prod') {
when { expression { GIT_BRANCH.endsWith('docs-build') } }
steps { script {
sshagent(credentials: ['status-im-auto-ssh']) {
sh 'yarn run deploy'
}
} }
}
}
}

11
ci/README.md Normal file
View File

@ -0,0 +1,11 @@
# Description
Configuration of CI builds executed under a Jenkins instance at https://ci.status.im/.
# Website
The `Jenkinsfile.gh-pages` file builds the documentation site with this job:
https://ci.status.im/job/website/job/js-waku.wakuconnect.dev/
And deploys it via `gh-pages` branch and [GitHub Pages](https://pages.github.com/) to:
https://js-waku.wakuconnect.dev/

39
ci/deploy.js Executable file
View File

@ -0,0 +1,39 @@
const { promisify } = require('util')
const { publish } = require('gh-pages')
const ghpublish = promisify(publish)
/* fix for "Unhandled promise rejections" */
process.on('unhandledRejection', err => { throw err })
const Args = process.argv.slice(2)
const USE_HTTPS = Args[0] && Args[0].toUpperCase() === 'HTTPS'
const branch = 'gh-pages'
const org = 'status-im'
const repo = 'js-waku'
/* use SSH auth by default */
let repoUrl = USE_HTTPS
? `https://github.com/${org}/${repo}.git`
: `git@github.com:${org}/${repo}.git`
/* alternative auth using GitHub user and API token */
if (process.env.GH_USER != undefined) {
repoUrl = (
'https://' + process.env.GH_USER +
':' + process.env.GH_TOKEN +
'@' + `github.com/${org}/${repo}.git`
)
}
const main = async (url, branch)=> {
console.log(`Pushing to: ${url}`)
console.log(`On branch: ${branch}`)
await ghpublish('build/docs', {
repo: url,
branch: branch,
dotfiles: true,
silent: false
})
}
main(repoUrl, branch)

2
package-lock.json generated
View File

@ -57,7 +57,7 @@
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-prettier": "^4.0.0",
"fast-check": "^2.14.0",
"gh-pages": "^3.1.0",
"gh-pages": "^3.2.3",
"karma": "^6.3.4",
"karma-chrome-launcher": "^3.1.0",
"karma-mocha": "^2.0.1",

View File

@ -46,8 +46,10 @@
"proto:build": "buf generate",
"watch:build": "tsc -p tsconfig.json -w",
"watch:test": "nyc --silent mocha --watch",
"doc": "run-s doc:html && open-cli build/docs/index.html",
"doc": "run-s doc:*",
"doc:html": "typedoc --excludeInternal --listInvalidSymbolLinks --exclude **/*.spec.ts --out build/docs src/",
"doc:cname": "echo 'js-waku.wakuconnect.dev' > build/docs/CNAME",
"deploy": "node ci/deploy.js",
"reset-hard": "git clean -dfx && git reset --hard && npm i && npm run build && for d in examples/*; do (cd $d; npm i); done"
},
"engines": {
@ -102,7 +104,7 @@
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-prettier": "^4.0.0",
"fast-check": "^2.14.0",
"gh-pages": "^3.1.0",
"gh-pages": "^3.2.3",
"karma": "^6.3.4",
"karma-chrome-launcher": "^3.1.0",
"karma-mocha": "^2.0.1",