Skip to content

Commit

Permalink
FABN-1386: Publish API documentation in Azure
Browse files Browse the repository at this point in the history
Signed-off-by: Mark S. Lewis <[email protected]>
Change-Id: Ib4bbfb2ba5c62263685726bdbfdf3b66ac9db82c
  • Loading branch information
bestbeforetoday committed Nov 6, 2019
1 parent 316a174 commit 9a38da6
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 8 deletions.
20 changes: 12 additions & 8 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,22 @@ steps:
softhsm2-util --init-token --slot 0 --label "My token 1" --pin 98765432 --so-pin 98765432
displayName: 'Install and configure SoftHSM'

- script: |
npm install
- script: npm install
displayName: 'npm install'

- script: |
npm run retrieve-images
- script: npm run retrieve-images
displayName: 'Pull Docker images'

- script: |
npx gulp install-and-generate-certs
- script: npx gulp install-and-generate-certs
displayName: 'Generate credentials'

- script: |
npx gulp run-test-all
- script: npx gulp run-test-all
displayName: 'Run tests'

# - 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'
68 changes: 68 additions & 0 deletions scripts/ci_scripts/azurePublishApiDocs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash -e
#
# Copyright IBM Corp All Rights Reserved
#
# SPDX-License-Identifier: Apache-2.0
#

clonePublishRepository() {
rm -rf "${PUBLISH_DIR}"
git clone "${REPOSITORY_URL}"
}

buildDocs() {
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
}

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

removePublishDirectories() {
find "${BUILD_DIR}" -type d -maxdepth 1 -depth 1 -print | while read -r subdir; do
sourceDir=$(basename "${subdir}")
targetDir="${PUBLISH_DIR}/${sourceDir}"
echo "Removing ${targetDir}"
rm -rf "${targetDir}"
done
}

publishDocs() {
git config --local user.name "${GITHUB_USER}"
git config --local user.email "${GITHUB_EMAIL}"

git add .
git commit -m "Commit ${COMMIT_HASH}"
git remote add publish "${PUBLISH_URL}"
git push publish master
}

# Must be run from the repository root directory.

# 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")

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

clonePublishRepository
buildDocs
(cd "${PUBLISH_DIR}" && publishDocs)

0 comments on commit 9a38da6

Please sign in to comment.