Skip to content

Commit

Permalink
FABN-1386: Publish docs to gh-pages branch
Browse files Browse the repository at this point in the history
Signed-off-by: Mark S. Lewis <[email protected]>
  • Loading branch information
bestbeforetoday committed Nov 21, 2019
1 parent 41d56ed commit 99c2227
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 58 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_style = space
indent_size = 2
36 changes: 20 additions & 16 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ trigger:
- master

pool:
vmImage: 'ubuntu-latest'
vmImage: 'ubuntu-18.04'

variables:
SOFTHSM2_CONF: './test/fixtures/hsm/softhsm2.conf'
SOFTHSM2_CONF: "$(Build.Repository.LocalPath)/test/fixtures/hsm/softhsm2.conf"

steps:
- task: NodeTool@0
inputs:
versionSpec: '8.x'
versionSpec: '10.x'
displayName: 'Install Node.js'

- script: |
sudo apt-get install softhsm2
softhsm2-util --init-token --slot 0 --label "My token 1" --pin 98765432 --so-pin 98765432
displayName: 'Install and configure SoftHSM'
displayName: 'Install SoftHSM'

- script: npm install
displayName: 'npm install'
Expand All @@ -35,15 +35,19 @@ steps:
- script: npx gulp run-test-all
displayName: 'Run tests'

# - script: scripts/ci_scripts/azurePublishNpmPackages.sh
# displayName: 'Publish npm packages'
# env:
# NPM_TOKEN: ${NPM_TOKEN}

# - script: scripts/ci_scripts/azurePublishApiDocs.sh
# displayName: 'Publish API documentation'
# env:
# GITHUB_USER: 'fabric-sdk-node'
# GITHUB_EMAIL: '[email protected]'
# GITHUB_PASSWORD: $(GITHUB_PASSWORD)
# PUBLISH_REPOSITORY: 'fabric-sdk-node/fabric-sdk-node'
#- script: scripts/ci_scripts/azurePublishNpmPackages.sh
# condition: and(succeeded(), eq(variables['Build.Reason'], 'IndividualCI'))
# displayName: 'Publish npm packages'
# env:
# NPM_TOKEN: $(NPM)
# PROJECT_DIR: "$(Build.Repository.LocalPath)"

- script: scripts/ci_scripts/azurePublishApiDocs.sh
condition: and(succeeded(), eq(variables['Build.Reason'], 'IndividualCI'))
displayName: 'Publish API documentation'
env:
GITHUB_USER: 'Hyperledger Bot'
GITHUB_EMAIL: '[email protected]'
PUBLISH_URL: "https://$(GITHUB-PAT)@github.com/hyperledger/fabric-sdk-node.git"
PROJECT_DIR: "$(Build.Repository.LocalPath)"
STAGING_DIR: "$(Build.StagingDirectory)/gh-pages"
2 changes: 1 addition & 1 deletion fabric-ca-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"url": "https://github.com/hyperledger/fabric-sdk-node"
},
"engines": {
"node": "^8.9.0 || ^10.15.3",
"node": "^8.9.0 || ^10.15.3 || ^12.13.1",
"npm": "^5.5.1 || ^6.4.1"
},
"types": "./types/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion fabric-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"url": "https://github.com/hyperledger/fabric-sdk-node"
},
"engines": {
"node": "^8.9.0 || ^10.15.3",
"node": "^8.9.0 || ^10.15.3 || ^12.13.1",
"npm": "^5.5.1 || ^6.4.1"
},
"types": "./types/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion fabric-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"test": "nyc mocha --exclude 'test/data/**/*.js' --recursive -t 10000"
},
"engines": {
"node": "^8.9.0 || ^10.15.3",
"node": "^8.9.0 || ^10.15.3 || ^12.13.1",
"npm": "^5.5.1 || ^6.4.1"
},
"types": "./types/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion fabric-network/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"test": "nyc mocha --recursive -t 10000"
},
"engines": {
"node": "^8.9.0 || ^10.15.3",
"node": "^8.9.0 || ^10.15.3 || ^12.13.1",
"npm": "^5.5.1 || ^6.4.1"
},
"types": "./types/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion fabric-protos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"url": "https://github.com/hyperledger/fabric-sdk-node"
},
"engines": {
"node": "^8.9.0 || ^10.15.3",
"node": "^8.9.0 || ^10.15.3 || ^12.13.1",
"npm": "^5.5.1 || ^6.4.1"
},
"keywords": [
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"retrieve-images": "./scripts/utility/fabric_images.sh amd64 2.0.0-stable"
},
"devDependencies": {
"@ampretia/x509": "0.4.0",
"@ampretia/x509": "0.4.7",
"@cloudant/cloudant": "^2.1.0",
"@types/chai": "^4.2.1",
"@types/chai-as-promised": "^7.1.2",
Expand All @@ -59,7 +59,6 @@
"fabric-protos": "file:./fabric-protos",
"gulp": "^3.9.1",
"gulp-add-src": "^1.0.0",
"gulp-debug": "^4.0.0",
"gulp-eslint": "^3.0.1",
"gulp-jsdoc3": "^2.0.0",
"gulp-mocha": "^6.0.0",
Expand Down Expand Up @@ -104,8 +103,7 @@
}
],
"dependencies": {
"fs-extra": "^6.0.1",
"x509": "^0.3.4"
"fs-extra": "^6.0.1"
},
"nyc": {
"exclude": [
Expand Down
69 changes: 37 additions & 32 deletions scripts/ci_scripts/azurePublishApiDocs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,61 +8,66 @@
# Input environment variables:
: "${GITHUB_USER:?}" # The GitHub user name for publishing
: "${GITHUB_EMAIL:?}" # Email address of the GitHub user
: "${GITHUB_PASSWORD:?}" # Password or token for GitHub user
: "${PUBLISH_REPOSITORY:?}" # Qualified GitHub publish repository name (i.e. "organization/repository")

readonly PROJECT_DIR=$(cd -P "$(dirname "$0")"/../.. >/dev/null 2>&1 && pwd)
: "${PUBLISH_URL:?}" # Git URL used to push published content
: "${PROJECT_DIR:?}" # Root directory for the Git project
: "${STAGING_DIR:?}" # Directory used to store content to publish to GitHub Pages

readonly COMMIT_HASH=$(git rev-parse HEAD)
readonly REPOSITORY_URL="https://github.com/${PUBLISH_REPOSITORY}.git"
readonly PUBLISH_URL="https://${GITHUB_USER}:${GITHUB_PASSWORD}@github.com/${PUBLISH_REPOSITORY}.git"
readonly BUILD_DIR="${PROJECT_DIR}/docs/gen"
readonly PUBLISH_DIR="${PROJECT_DIR}/$(basename "${PUBLISH_REPOSITORY}")"
readonly DOCS_BRANCH='gh-pages'

prepareStaging() {
echo "Preparing staging directory: ${STAGING_DIR}"
rm -rf "${STAGING_DIR}"
rsync -r --exclude-from=${PROJECT_DIR}/.gitignore "${PROJECT_DIR}/" "${STAGING_DIR}"
(cd "${STAGING_DIR}" && _stagingGitSetUp)
}

clonePublishRepository() {
rm -rf "${PUBLISH_DIR}"
git clone "${REPOSITORY_URL}" "${PUBLISH_DIR}"
_stagingGitSetUp() {
git config --local user.name "${GITHUB_USER}"
git config --local user.email "${GITHUB_EMAIL}"
git reset --hard
git clean -xdf
git fetch origin
git checkout -B "${DOCS_BRANCH}" "origin/${DOCS_BRANCH}"
git clean -xdf
}

buildDocs() {
echo 'Building documentation'
rm -rf "${BUILD_DIR}"
npx gulp docs
cleanPublishDirectory
cp -r "${BUILD_DIR}"/* "${PUBLISH_DIR}"
}

cleanPublishDirectory() {
# Root files should only be removed from the top-level publish directory if building the master branch
# removePublishRootFiles
removePublishDirectories
copyToStaging() {
echo "Copying built documentation from ${BUILD_DIR} to ${STAGING_DIR}"
cleanStaging
cp -r "${BUILD_DIR}"/* "${STAGING_DIR}"
}

removePublishRootFiles() {
find "${PUBLISH_DIR}" -type f -maxdepth 1 -depth 1 -print | while read -r file; do
echo "Removing ${file}"
rm -f "${file}"
done
}

removePublishDirectories() {
cleanStaging() {
local releaseDir targetDir
# Remove release sub-directories that have been re-built
find "${BUILD_DIR}" -type d -maxdepth 1 -depth 1 -print | while read -r subdir; do
local sourceDir=$(basename "${subdir}")
local targetDir="${PUBLISH_DIR}/${sourceDir}"
releaseDir=$(basename "${subdir}")
targetDir="${STAGING_DIR}/${releaseDir}"
echo "Removing ${targetDir}"
rm -rf "${targetDir}"
done
}

publishDocs() {
git config --local user.name "${GITHUB_USER}"
git config --local user.email "${GITHUB_EMAIL}"
echo 'Publishing documentation from staging'
(cd "${STAGING_DIR}" && _stagingPushDocs)
}

_stagingPushDocs() {
git add .
git commit -m "Commit ${COMMIT_HASH}"
git remote add publish "${PUBLISH_URL}"
# git push publish master
git push "${PUBLISH_URL}" "${DOCS_BRANCH}"
}

clonePublishRepository
prepareStaging
buildDocs
(cd "${PUBLISH_DIR}" && publishDocs)
copyToStaging
publishDocs
2 changes: 1 addition & 1 deletion scripts/ci_scripts/azurePublishNpmPackages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

# Input environment variables:
: "${NPM_TOKEN:?}" # The npm publishing auth token
: "${PROJECT_DIR:?}" # The project root directory

readonly PROJECT_DIR=$(cd -P "$(dirname "$0")"/../.. >/dev/null 2>&1 && pwd)
readonly NODE_MODULES="fabric-protos fabric-common fabric-ca-client fabric-client fabric-network"

npmPublish() {
Expand Down

0 comments on commit 99c2227

Please sign in to comment.