Skip to content

Commit 18198fd

Browse files
committed
site-dependencies.js foundation for partial build work
By exposing a map of component-version to origins, with latest SHA, and dependencies (e.g. origins referenced via include:: or image::) we lay foundations for partial build work. Output will look like "server@8.1": { "origins": { "https://github.com/couchbase/docs-server.git@release/8.1": "123456789", "https://github.com/couchbaselabs/docs-devex.git@release/8.1": "abcdefg", "https://github.com/couchbaselabs/cb-swagger.git@release/8.1:docs": "5e4776963c" }, "dependencies": [ "https://github.com/couchbase/docs-server.git@release/8.1", "https://github.com/couchbaselabs/docs-devex.git@release/8.1", "https://github.com/couchbaselabs/cb-swagger.git@release/8.1:docs" ] }, The SHA will note be present for local worktrees (e.g. if run locally, or for docs-site).
1 parent d12683a commit 18198fd

3 files changed

Lines changed: 90 additions & 6 deletions

File tree

antora-playbook-staging.diff.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ antora:
33
- ./lib/report-tree.js
44
- ./lib/site-stats-extension.js
55
- ./lib/component-stats.js
6+
- ./lib/site-dependencies.js
67

78
site:
89
title: Couchbase Docs Staging

antora-playbook-staging.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ urls:
1515
latest_version_segment: current
1616
ui:
1717
bundle:
18-
url: https://github.com/couchbase/docs-ui/releases/download/prod-230/ui-bundle.zip
18+
url: https://github.com/couchbase/docs-ui/releases/download/prod-229/ui-bundle.zip
1919
output:
2020
dir: ./public
2121
runtime:
@@ -29,6 +29,7 @@ antora:
2929
- ./lib/report-tree.js
3030
- ./lib/site-stats-extension.js
3131
- ./lib/component-stats.js
32+
- ./lib/site-dependencies.js
3233
site:
3334
title: Couchbase Docs Staging
3435
url: https://docs-staging.couchbase.com
@@ -201,7 +202,6 @@ content:
201202
- release/2.0
202203
- release/1.2
203204
- release/1.1
204-
- release/1.0
205205
- url: https://github.com/couchbase/docs-connectors-power-bi
206206
branches:
207207
- release/1.3
@@ -363,23 +363,25 @@ content:
363363
- release/2.8
364364
- url: https://github.com/couchbase/docs-couchbase-lite
365365
branches:
366+
- release/4.1
366367
- release/4.0
367-
- release/3.3
368-
- release/3.2
368+
- release/3.4
369369
- url: https://github.com/couchbaselabs/docs-couchbase-lite-js
370370
branches:
371371
- release/1.0
372372
- url: https://github.com/couchbase/docs-sync-gateway
373373
branches:
374+
- release/4.1
374375
- release/4.0
375376
- release/3.3
376-
- release/3.2
377377
- url: https://github.com/couchbaselabs/docs-couchbase-lite-edge-server
378378
branches:
379+
- release/1.1
379380
- release/1.0
380381
- url: https://github.com/couchbase/edge-server
381382
branches:
382-
- main
383+
- release/1.1
384+
- release/1.0
383385
start_path: docs
384386
- url: https://github.com/couchbaselabs/mobile-travel-sample
385387
branches:

lib/site-dependencies.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
'use strict'
2+
3+
const cvs = {}
4+
5+
module.exports.register = function () {
6+
// '8.0@docs-server' -> Set of '8.0@docs-devex'
7+
this.once('contentClassified', ({ contentCatalog }) => {
8+
this.updateVariables({ contentCatalog: trackingContentCatalog(contentCatalog, record) })
9+
})
10+
11+
this.once('beforePublish', ({ siteCatalog }) => {
12+
const depsFile = createDependenciesFile(cvs)
13+
siteCatalog.addFile(depsFile)
14+
})
15+
16+
this.once('contentAggregated', ({ contentAggregate }) => {
17+
18+
for (const cv of contentAggregate) {
19+
const cvKey = `${cv.name}@${cv.version}`
20+
const origins = Object.fromEntries(
21+
cv.origins.map(o => [repoKey(o), o.refhash || null]))
22+
23+
cvs[cvKey] = { origins, dependencies: new Set() }
24+
}
25+
26+
// compare repos[].sha against your persisted previous-build record
27+
})
28+
29+
}
30+
31+
function repoKey ({ url, refname, startPath }) {
32+
return `${url}@${refname}${startPath ? ':' + startPath : ''}`
33+
}
34+
35+
function record (from, to) {
36+
if (!to.origin) return // stub/synthetic files (e.g. Atlas-imported pages) carry no origin
37+
38+
const fromKey = `${from.component}@${from.version}`
39+
const toKey = repoKey(to.origin)
40+
41+
cvs[fromKey].dependencies.add(toKey)
42+
}
43+
44+
function trackingContentCatalog (contentCatalog, record) {
45+
return new Proxy(contentCatalog, {
46+
get (target, property) {
47+
if (property !== 'resolveResource') return target[property]
48+
return (spec, context, defaultFamily, permittedFamilies) => {
49+
const resolved = target.resolveResource(spec, context, defaultFamily, permittedFamilies)
50+
51+
// we explicitly don't want to handle 'page', as those are already
52+
// dealt with by Atlas
53+
if (resolved && resolved.src && resolved.src.family !== 'page') {
54+
record(context, resolved.src)
55+
}
56+
return resolved
57+
}
58+
},
59+
})
60+
}
61+
62+
const replacer = function (k, v) {
63+
if (v instanceof Set) {
64+
return Array.from(v)
65+
}
66+
else {
67+
return v
68+
}
69+
}
70+
71+
function createDependenciesFile (data) {
72+
const contents = JSON.stringify(data, replacer, 2) + '\n'
73+
return {
74+
contents: Buffer.from(contents),
75+
mediaType: 'application/json',
76+
out: { path: 'site-dependencies.json' },
77+
path: 'site-dependencies.json',
78+
pub: { url: '/site-dependencies.json', rootPath: '' },
79+
src: { stem: 'site-dependencies' },
80+
}
81+
}

0 commit comments

Comments
 (0)