-
Notifications
You must be signed in to change notification settings - Fork 6
/
generate-docs.yaml
177 lines (154 loc) · 7.74 KB
/
generate-docs.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
trigger:
branches:
include:
- master
pr:
drafts: false
branches:
include:
- master
paths:
include:
- Domains/
- System/
- tools/
- docs/
- package.json
- package-lock.json
resources:
repositories:
- repository: itwinjs-core
type: github
endpoint: iModelJs
name: iTwin/itwinjs-core
ref: refs/heads/master
stages:
- stage: Generate_Docs
jobs:
- job:
displayName: Generate Docs
workspace:
clean: all
pool:
vmImage: windows-latest
steps:
- script: npm install @bentley/ecjson2md@latest
displayName: Install ECJson2md
workingDirectory: $(Build.BinariesDirectory)
- task: CopyFiles@2
displayName: 'Copy all schemas to staging directory'
inputs:
SourceFolder: '$(System.DefaultWorkingDirectory)'
Contents: '**/*.ecschema.xml'
TargetFolder: '$(Build.StagingDirectory)\xml\'
- task: PythonScript@0
displayName: Run Schema Json Serializer
inputs:
scriptSource: inline
script: |
import os, sys, shutil, subprocess
#from sets import Set
defaultWorkingDir = os.path.realpath(sys.argv[1])
schemasToSkip = ["ECDbFileInfo", "ECDbSystem", "ECv3ConversionAttributes", "PresentationRules", "SchemaLocalizationCustomAttributes"]
# folders that contain a schema but aren't a released folder as reference directories.
refDir = set()
# all released schemas found by looking in 'Released' directories and pulling the highest schema version
releasedSchemas = {}
# files found in 'media' directories that do not end with .cmap
schemaMediaFiles = set()
for root, dirs, files in os.walk(defaultWorkingDir):
files.sort(reverse=True)
for fileName in files:
# reference schema directories
if "Released" not in root and fileName.endswith(".ecschema.xml"):
refDir.add(root)
print ("Added directory " + root + " as a reference path.")
# Relesed schema Files
if "Released" in root and fileName.endswith(".ecschema.xml"):
schemaName = fileName[:fileName.index(".")]
if schemaName not in releasedSchemas and schemaName not in schemasToSkip:
releasedSchemas[schemaName] = os.path.join(root, fileName)
print ("Added released schema " + fileName + " from directory " + root)
# media files
if "media" in root and "docs" not in root and not fileName.endswith(".cmap"):
schemaMediaFiles.add(os.path.join(root, fileName))
print ("Added media for schema " + fileName + " from directory " + root)
# add the released versions of the ECDb schemas because the real versions are not copied over
refDir.add(os.path.join(defaultWorkingDir, "System", "ECDb", "Released"))
rDir = ' '.join(refDir)
outputDir = os.path.join(os.path.realpath(sys.argv[2]), "json")
if not os.path.exists(outputDir):
os.makedirs(outputDir)
print ("Using the output directory, '" + outputDir + "'.")
mdOutputDir = os.path.join(os.path.realpath(sys.argv[2]), "markdown")
if not os.path.exists(mdOutputDir):
os.makedirs(mdOutputDir)
for schemaName, fullXmlSchemaPath in releasedSchemas.items():
# Copy all markdown files that also have a schema.
fullMdSchemaPath = os.path.join(fullXmlSchemaPath[:fullXmlSchemaPath.find("Released")], schemaName) + ".remarks.md"
if os.path.exists(fullMdSchemaPath):
print ("Copying schema markdown file " + fullMdSchemaPath)
shutil.copy(fullMdSchemaPath, mdOutputDir)
mdMediaOutputDir = os.path.join(mdOutputDir, "media")
for mediaFile in schemaMediaFiles:
targetFilePath = os.path.join(mdMediaOutputDir, mediaFile.split('media\\')[-1])
if not os.path.exists(os.path.dirname(targetFilePath)):
os.makedirs(os.path.dirname(targetFilePath))
if os.path.exists(targetFilePath):
print ("ERROR - Cannot copy " + mediaFile + " because a file with the same name already exists in the media output directory.")
exit(-1)
print ("Copying media file " + mediaFile)
shutil.copy(mediaFile, targetFilePath)
arguments: '$(System.DefaultWorkingDirectory) $(Build.StagingDirectory)'
- task: Npm@1
displayName: 'npm install'
inputs:
workingDir: '$(Build.Repository.LocalPath)'
verbose: false
- task: Npm@1
displayName: 'Generate Json Schemas'
inputs:
command: custom
workingDir: '$(Build.Repository.LocalPath)'
verbose: false
customCommand: 'run generateJsonSchemas -- --latestReleasedVersionsForMarkdown --OutDir $(Build.StagingDirectory)/json/'
- script: |
mkdir $(Build.StagingDirectory)\markdown\
cmd | for %%a in ($(Build.StagingDirectory)\json\*.json) do (
$(Build.BinariesDirectory)/node_modules/.bin/ecjson2md -i %%a -r $(Build.StagingDirectory)\json\ -o $(Build.StagingDirectory)\markdown\
)
displayName: 'Generate Markdown'
- task: CopyFiles@2
displayName: 'Copy Logo to Media Directory'
inputs:
SourceFolder: '$(Build.BinariesDirectory)/node_modules/@bentley/ecjson2md/lib/media/'
Contents: imodel-schema-editor-icon.png
TargetFolder: '$(Build.StagingDirectory)/markdown/media'
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: Bis Docs'
inputs:
PathtoPublish: '$(Build.StagingDirectory)\markdown\'
ArtifactName: 'Bis Docs'
- task: PowerShell@2
condition: and(succeeded(), not(canceled()), startsWith(variables['Build.SourceBranchName'], 'refs/tags/imodeljs/'))
name: RetainTagBuildsOnSuccess
displayName: Retain Tag Builds on Success
inputs:
failOnStderr: true
targetType: 'inline'
script: |
$contentType = "application/json";
$headers = @{ Authorization = 'Bearer $(System.AccessToken)' };
$rawRequest = @{ daysValid = 365 * 1; definitionId = $(System.DefinitionId); ownerId = 'User:$(Build.RequestedForId)'; protectPipeline = $false; runId = $(Build.BuildId) };
$request = ConvertTo-Json @($rawRequest);
$uri = "$(System.CollectionUri)$(System.TeamProject)/_apis/build/retention/leases?api-version=6.0-preview.1";
Invoke-RestMethod -uri $uri -method POST -Headers $headers -ContentType $contentType -Body $request;
- stage: Validate_Docs
dependsOn: Generate_Docs
condition: and(succeeded(), in(variables['Build.Reason'], 'IndividualCI', 'PullRequest', 'Manual'))
jobs:
- template: common/config/azure-pipelines/jobs/docs-build.yaml@itwinjs-core
parameters:
checkout: itwinjs-core
ignoreAudit: true
useCurrentBisDocsArtifact: true