Skip to content

Commit 914c58e

Browse files
authored
Set up Antora site and GitHub Actions workflow (#1)
1 parent b90d31c commit 914c58e

12 files changed

Lines changed: 3002 additions & 0 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
workflow_dispatch:
8+
9+
permissions: {}
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
steps:
17+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
18+
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
19+
with:
20+
node-version-file: .tool-versions
21+
cache: npm
22+
- run: npm ci
23+
- name: Expose GitHub Actions runtime for the collector-cache Antora extension
24+
uses: crazy-max/ghaction-github-runtime@04d248b84655b509d8c44dc1d6f990c879747487 # v4.0.0
25+
- run: npm run build
26+
- if: github.event_name != 'pull_request'
27+
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
28+
with:
29+
path: build/site
30+
31+
deploy:
32+
if: github.event_name != 'pull_request'
33+
needs: build
34+
runs-on: ubuntu-latest
35+
concurrency:
36+
group: pages
37+
cancel-in-progress: false
38+
permissions:
39+
pages: write
40+
id-token: write
41+
environment:
42+
name: github-pages
43+
url: ${{ steps.deploy.outputs.page_url }}
44+
steps:
45+
- id: deploy
46+
uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1

‎.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/build/
2+
/node_modules/
3+
/.idea/
4+
/*.iml

‎.tool-versions‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodejs 26.13.1

‎README.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# AssertJ Documentation Site
2+
3+
This branch contains the Antora project for building AssertJ's documentation site.
4+
5+
## Prerequisites
6+
7+
It requires Node.js (for Antora) and Ruby (for asciidoctor.pdf).
8+
9+
A `.tool-versions` file can be used with `asdf` or `mise`:
10+
11+
```
12+
asdf install # or mise install
13+
npm install
14+
bundle install
15+
```
16+
17+
## Building
18+
19+
```
20+
npm run build
21+
```

‎antora-playbook.yml‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
antora:
2+
extensions:
3+
- require: './extensions/collector-cache.js'
4+
- '@antora/collector-extension'
5+
- require: '@antora/lunr-extension'
6+
index_by_heading: true
7+
- require: '@springio/antora-xref-extension'
8+
site:
9+
title: AssertJ Documentation
10+
url: https://docs.assertj.dev
11+
robots: allow
12+
content:
13+
sources:
14+
- url: .
15+
branches: HEAD
16+
start_path: home
17+
asciidoc:
18+
sourcemap: true
19+
extensions:
20+
- '@asciidoctor/tabs'
21+
attributes:
22+
page-pagination: ''
23+
idprefix: '@'
24+
idseparator: '-@'
25+
table-caption: false
26+
table-frame: 'none@'
27+
table-grid: 'rows@'
28+
table-stripes: 'odd@'
29+
figure-caption: false
30+
example-caption: false
31+
listing-caption: false
32+
hide-uri-scheme: '@'
33+
attribute-missing: warn
34+
tabs-sync-option: ''
35+
runtime:
36+
log:
37+
failure_level: warn
38+
urls:
39+
redirect_facility: static
40+
latest_version_segment: current
41+
latest_prerelease_version_segment: snapshot
42+
latest_version_segment_strategy: replace
43+
ui:
44+
bundle:
45+
url: https://github.com/assertj/antora-ui/releases/download/20261112-181749/ui-bundle.zip
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Modified version of https://github.com/spring-io/antora-extensions/blob/fee110d465480db87f029426bfab7da8068e282e/lib/cache-scandir/copy-recursive.js
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
'use strict'
5+
6+
const fs = require('fs')
7+
const path = require('path')
8+
9+
const copyRecursiveSync = function (src, dest) {
10+
const exists = fs.existsSync(src)
11+
const stats = exists && fs.statSync(src)
12+
const isDirectory = exists && stats.isDirectory()
13+
if (isDirectory) {
14+
if (!fs.existsSync(dest)) {
15+
fs.mkdirSync(dest, { recursive: true })
16+
}
17+
fs.readdirSync(src).forEach(function (childItemName) {
18+
copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName))
19+
})
20+
} else {
21+
fs.copyFileSync(src, dest)
22+
}
23+
}
24+
25+
function copyRecursive (scanDir, cacheDir) {
26+
copyRecursiveSync(scanDir, cacheDir)
27+
}
28+
29+
module.exports = copyRecursive

‎extensions/cache-scandir/index.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Modified version of https://github.com/spring-io/antora-extensions/blob/fee110d465480db87f029426bfab7da8068e282e/lib/cache-scandir/index.js
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
'use strict'
5+
6+
const copyRecursive = require('./copy-recursive')
7+
8+
const [, , ...args] = process.argv
9+
const [scanDir, cacheDir] = args
10+
11+
copyRecursive(scanDir, cacheDir)

‎extensions/collector-cache.js‎

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// Modified version of https://github.com/spring-io/antora-extensions/blob/fee110d465480db87f029426bfab7da8068e282e/lib/inject-collector-cache-config-extension.js
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
'use strict'
5+
6+
const expandPath = require('@antora/expand-path-helper')
7+
const ospath = require('path')
8+
const resolvedCopyRecursiveJs = require.resolve('./cache-scandir')
9+
const { createHash } = require('crypto')
10+
// @actions/cache is ESM-only, so load it via dynamic import from this CommonJS module.
11+
const cacheLib = import('@actions/cache')
12+
13+
module.exports.register = function ({ playbook, config = {} }) {
14+
const logger = this.getLogger('collector-cache')
15+
const excludes = config.excludes || []
16+
const getUserCacheDir = this.require('cache-directory')
17+
const fs = this.require('fs')
18+
19+
const cacheInfo = []
20+
this.once('contentAggregated', async ({ playbook, contentAggregate }) => {
21+
const cache = await cacheLib
22+
const cacheAvailable = cache.isFeatureAvailable()
23+
if (!cacheAvailable) {
24+
logger.info('GitHub Actions cache is not available; skipping restore/save operations')
25+
}
26+
const baseCacheDir = getBaseCacheDir(getUserCacheDir, playbook)
27+
for (const { origins } of contentAggregate) {
28+
for (const origin of origins) {
29+
const { url, gitdir, refhash, worktree, descriptor, refname } = origin
30+
const repositoryCacheDirName = generateWorktreeFolderName({ url, gitdir, worktree })
31+
const baseCollectorCacheCacheDir = ospath.join(baseCacheDir, 'collector-cache', repositoryCacheDirName)
32+
const collectorConfig = descriptor?.ext?.collector
33+
if (collectorConfig !== undefined && !excludes.includes(refname)) {
34+
const shortref = refhash.slice(0, 7)
35+
const cacheDirName = `${shortref}-${refname}`
36+
const cacheDir = ospath.join(baseCollectorCacheCacheDir, cacheDirName)
37+
const cacheKey = `collector-cache-${repositoryCacheDirName}-${cacheDirName}`
38+
if (!fs.existsSync(baseCollectorCacheCacheDir)) {
39+
fs.mkdirSync(baseCollectorCacheCacheDir, { recursive: true })
40+
}
41+
if (cacheAvailable && !fs.existsSync(cacheDir)) {
42+
// try and restore from the GitHub Actions cache
43+
const restoredKey = await cache.restoreCache([cacheDir], cacheKey).catch((err) => {
44+
logger.warn(`Failed to restore cache for key ${cacheKey}: ${err.message}`)
45+
return undefined
46+
})
47+
if (restoredKey) {
48+
logger.info(`Successfully restored cache for key ${cacheKey}`)
49+
} else {
50+
logger.info(`Unable to restore cache for key ${cacheKey}`)
51+
}
52+
}
53+
if (fs.existsSync(cacheDir)) {
54+
// use the cache
55+
origin.descriptor.ext.collector = {
56+
scan: {
57+
dir: cacheDir,
58+
},
59+
}
60+
logger.info(`Using the cache found at ${cacheDir}`)
61+
} else {
62+
const cachedConfig = []
63+
const normalizedCollectorConfig = Array.isArray(collectorConfig) ? collectorConfig : [collectorConfig]
64+
logger.info(`Configuring collector for caching (url: ${url} | ref: ${refname})`)
65+
origin.descriptor.ext.collector = cachedConfig
66+
normalizedCollectorConfig.forEach((collector) => {
67+
cachedConfig.push(collector)
68+
const { scan: scanConfig = [] } = collector
69+
const normalizedScanConfigs = Array.isArray(scanConfig) ? scanConfig : [scanConfig]
70+
normalizedScanConfigs.forEach((normalizedScanConfig) => {
71+
// cache the output of the build
72+
const cachedCollectorConfig = createCachedCollectorConfig(normalizedScanConfig.dir, cacheDir, normalizedScanConfig.into)
73+
cachedConfig.push.apply(cachedConfig, cachedCollectorConfig)
74+
})
75+
})
76+
if (cacheAvailable) {
77+
cacheInfo.push({ cacheDir, cacheKey })
78+
}
79+
}
80+
}
81+
}
82+
}
83+
})
84+
this.once('beforePublish', async () => {
85+
if (cacheInfo) {
86+
const cache = await cacheLib
87+
for (const {cacheDir, cacheKey} of cacheInfo) {
88+
await cache.saveCache([cacheDir], cacheKey)
89+
logger.info(`Saved cache for key ${cacheKey}`)
90+
}
91+
}
92+
})
93+
}
94+
95+
function getBaseCacheDir (getUserCacheDir, { dir: dot, runtime: { cacheDir: preferredDir } = {} }) {
96+
return preferredDir == null
97+
? getUserCacheDir(`antora${process.env.NODE_ENV === 'test' ? '-test' : ''}`) || ospath.join(dot, '.cache/antora')
98+
: expandPath(preferredDir, { dot })
99+
}
100+
101+
function generateWorktreeFolderName ({ url, gitdir, worktree }) {
102+
if (worktree === undefined) return ospath.basename(gitdir, '.git')
103+
return `${url.substr(url.lastIndexOf('/') + 1)}-${createHash('sha1').update(url).digest('hex')}`
104+
}
105+
106+
function createCachedCollectorConfig (scanDir, cacheDir, subDir) {
107+
return [
108+
{
109+
run: {
110+
command: `\${{env.NODE}} '${resolvedCopyRecursiveJs}' '.' '${cacheDir}${subDir ? `/${subDir}` : ''}'`,
111+
dir: scanDir,
112+
},
113+
},
114+
]
115+
}

‎home/antora.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: ROOT
2+
title: AssertJ
3+
version: ~

‎home/modules/ROOT/pages/index.adoc‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
= AssertJ Documentation
2+
3+
Welcome to the documentation of https://assertj.github.io/doc/[AssertJ], the fluent assertions library for Java.

0 commit comments

Comments
 (0)