Skip to content

Commit 3f85d83

Browse files
authored
Merge pull request UiPath#37 from UiPath/feature/autodeploy_docs
Feature / publish docs automatically on master builds
2 parents 2258fe4 + 1e47b3a commit 3f85d83

File tree

7 files changed

+62
-24
lines changed

7 files changed

+62
-24
lines changed

.build/commitlint/index.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,13 @@ const Octokit = require('@octokit/rest')
55
const { lint, load } = require('@commitlint/core')
66
const path = require('path')
77

8-
const ACCESS_TOKEN = process.env['GH_STATUS_TOKEN']
9-
10-
if (!ACCESS_TOKEN) throw new Error('No access token found. env: GH_STATUS_TOKEN')
8+
const { variables } = require('../common')
9+
const { owner, repo, pull, token } = variables;
1110

1211
const github = new Octokit({
13-
auth: ACCESS_TOKEN,
12+
auth: token,
1413
})
1514

16-
const owner = process.env['GH_OWNER']
17-
const repo = process.env['GH_REPO']
18-
const pull = process.env['GH_PULL_ID']
19-
2015
const _handleUnexpectedError = (err) => {
2116
console.error(err)
2217
process.exit(1)

.build/common/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const extract = (token) => {
2+
const value = process.env[token]
3+
if (!value) throw new Error(`Could not read environment variable: ${token}`)
4+
5+
return value;
6+
}
7+
const owner = extract('GH_OWNER')
8+
const repo = extract('GH_REPO')
9+
const pull = extract('GH_PULL_ID')
10+
const token = extract('GH_TOKEN')
11+
12+
const variables = {
13+
owner,
14+
repo,
15+
pull,
16+
token,
17+
}
18+
19+
module.exports = {
20+
variables,
21+
}

.build/publish-gh-pages.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

.build/publish-gh-pages/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const ghpages = require('gh-pages')
2+
const { variables } = require('../common')
3+
const { owner, repo, token } = variables;
4+
5+
const PUBLISH_CONFIG = {
6+
repo: `https://${token}@github.com/${owner}/${repo}.git`,
7+
silent: true,
8+
}
9+
10+
console.log('Publishing docs to branch `gh-pages`...')
11+
12+
ghpages.publish(
13+
'documentation',
14+
PUBLISH_CONFIG,
15+
(err) => {
16+
if (err) {
17+
console.error(err)
18+
} else {
19+
console.log('Docs have been published succesfully...')
20+
}
21+
})

.ci/templates/steps/initialize-environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ steps:
33
echo '##vso[task.setvariable variable=CC_TEST_REPORTER_ID]$(system.ccToken)'
44
echo '##vso[task.setvariable variable=GIT_COMMIT_SHA]$(Build.SourceVersion)'
55
echo '##vso[task.setvariable variable=GIT_BRANCH]$(Build.SourceBranchName)'
6-
echo '##vso[task.setvariable variable=GH_STATUS_TOKEN]$(system.githubStatusToken)'
6+
echo '##vso[task.setvariable variable=GH_TOKEN]$(system.githubToken)'
77
echo '##vso[task.setvariable variable=GH_PULL_ID]$(System.PullRequest.PullRequestNumber)'
88
echo '##vso[task.setvariable variable=GH_OWNER]UiPath'
99
echo '##vso[task.setvariable variable=GH_REPO]angular-components'

azure-pipelines.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,19 @@ jobs:
4444
dependsOn:
4545
- CommitLint
4646
condition: succeeded('CommitLint')
47+
48+
- job: Documentation
49+
pool :
50+
vmImage: 'ubuntu-latest'
51+
steps:
52+
- template: .ci/templates/steps/initialize-environment.yml
53+
- template: .ci/templates/steps/install-dependencies.yml
54+
- script: |
55+
npm run docs
56+
displayName: 'Generating Docs'
57+
- script: |
58+
git config user.email [email protected]
59+
git config user.name "Azure Pipelines"
60+
node .build/publish-gh-pages
61+
displayName: 'Publishing Docs'
62+
condition: eq(variables['Build.SourceBranchName'], 'master')

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
"e2e": "ng e2e",
3939
"package": "npm-run-all build:prod",
4040
"docs": "compodoc",
41-
"predocs:publish": "npm run docs",
42-
"docs:publish": "node ./.build/publish-gh-pages.js",
4341
"commit": "git-cz"
4442
},
4543
"config": {

0 commit comments

Comments
 (0)