Skip to content

Commit 44a8d2b

Browse files
committed
Prepare docs-build branch
0 parents  commit 44a8d2b

File tree

5 files changed

+228
-0
lines changed

5 files changed

+228
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Send Notification
2+
description: 'Sends a Google Chat message as a notification of the job''s outcome'
3+
inputs:
4+
build-scan-url:
5+
description: 'URL of the build scan to include in the notification'
6+
required: false
7+
run-name:
8+
description: 'Name of the run to include in the notification'
9+
required: false
10+
default: ${{ format('{0} {1}', github.ref_name, github.job) }}
11+
status:
12+
description: 'Status of the job'
13+
required: true
14+
webhook-url:
15+
description: 'Google Chat Webhook URL'
16+
required: true
17+
runs:
18+
using: composite
19+
steps:
20+
- name: Prepare Variables
21+
shell: bash
22+
run: |
23+
echo "BUILD_SCAN=${{ inputs.build-scan-url == '' && ' [build scan unavailable]' || format(' [<{0}|Build Scan>]', inputs.build-scan-url) }}" >> "$GITHUB_ENV"
24+
echo "RUN_URL=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> "$GITHUB_ENV"
25+
- name: Success Notification
26+
if: ${{ inputs.status == 'success' }}
27+
shell: bash
28+
run: |
29+
curl -X POST '${{ inputs.webhook-url }}' -H 'Content-Type: application/json' -d '{ text: "<${{ env.RUN_URL }}|${{ inputs.run-name }}> was successful ${{ env.BUILD_SCAN }}"}' || true
30+
- name: Failure Notification
31+
if: ${{ inputs.status == 'failure' }}
32+
shell: bash
33+
run: |
34+
curl -X POST '${{ inputs.webhook-url }}' -H 'Content-Type: application/json' -d '{ text: "<users/all> *<${{ env.RUN_URL }}|${{ inputs.run-name }}> failed* ${{ env.BUILD_SCAN }}"}' || true
35+
- name: Cancel Notification
36+
if: ${{ inputs.status == 'cancelled' }}
37+
shell: bash
38+
run: |
39+
curl -X POST '${{ inputs.webhook-url }}' -H 'Content-Type: application/json' -d '{ text: "<${{ env.RUN_URL }}|${{ inputs.run-name }}> was cancelled"}' || true

.github/workflows/deploy-docs.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Build and Deploy Documentation
2+
run-name: ${{ format('{0} ({1})', github.workflow, github.event.inputs.build-refname || 'all') }}
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
build-refname:
7+
description: Enter git refname to build (e.g., 1.0.x).
8+
required: false
9+
build-version:
10+
description: Enter the version being build (e.g. 1.0.3-SNAPSHOT)
11+
required: false
12+
push:
13+
branches: docs-build
14+
permissions: read-all
15+
jobs:
16+
build-and-deploy-docs:
17+
name: Build and Deploy Documentation
18+
if: github.repository_owner == 'spring-projects'
19+
runs-on: ${{ vars.UBUNTU_SMALL || 'ubuntu-latest' }}
20+
steps:
21+
- name: Check Out
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
- name: Fetch Main Branch
26+
run: git fetch origin ${{ github.event.repository.default_branch }}:main
27+
- name: Set Up Node
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: 20
31+
- name: Check Out 'package.json' From Main
32+
run: node run.js --only-checkout
33+
- name: Cache Files
34+
uses: actions/cache@v4
35+
with:
36+
key: antora-${{ hashFiles('package-lock.json', 'antora-playbook.yml') }}
37+
path: |
38+
~/.npm
39+
~/.cache/antora
40+
- name: Install and Run Antora
41+
env:
42+
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
43+
ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
44+
BUILD_REFNAME: ${{ github.event.inputs.build-refname }}
45+
BUILD_VERSION: ${{ github.event.inputs.build-version }}
46+
run: node run.js --no-checkout
47+
- name: Sync Documentation
48+
uses: spring-io/spring-doc-actions/[email protected]
49+
with:
50+
docs-username: ${{ secrets.DOCS_USERNAME }}
51+
docs-host: ${{ secrets.DOCS_HOST }}
52+
docs-ssh-key: ${{ secrets.DOCS_SSH_KEY }}
53+
docs-ssh-host-key: ${{ secrets.DOCS_SSH_HOST_KEY }}
54+
httpdocs-path: /spring-restdocs/antora/
55+
env:
56+
BUILD_REFNAME: ${{ github.event.inputs.build-refname }}
57+
BUILD_VERSION: ${{ github.event.inputs.build-version }}
58+
- name: Bust Cloudflare Cache
59+
uses: spring-io/spring-doc-actions/[email protected]
60+
with:
61+
context-root: spring-restdocs
62+
context-path: /
63+
cloudflare-zone-id: ${{ secrets.CLOUDFLARE_ZONE_ID }}
64+
cloudflare-cache-token: ${{ secrets.CLOUDFLARE_CACHE_TOKEN }}
65+
- name: Send Notification
66+
if: failure()
67+
uses: ./.github/actions/send-notification
68+
with:
69+
run-name: ${{ format('{0} | Build and Deploy Docs', github.ref_name) }}
70+
status: ${{ job.status }}
71+
webhook-url: ${{ secrets.GOOGLE_CHAT_WEBHOOK_URL }}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
.vscode
3+
build
4+
package.json
5+
package-lock.json

antora-playbook.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
antora:
2+
extensions:
3+
- require: '@antora/atlas-extension'
4+
- require: '@springio/antora-extensions/latest-version-extension'
5+
- require: '@springio/antora-extensions/override-navigation-builder-extension'
6+
- require: '@springio/antora-extensions/partial-build-extension'
7+
- require: '@springio/antora-extensions/publish-docsearch-config-extension'
8+
- require: '@springio/antora-extensions/set-algolia-env-extension'
9+
- require: '@springio/antora-extensions/static-page-extension'
10+
- require: '@springio/antora-xref-extension'
11+
- require: '@springio/antora-zip-contents-collector-extension'
12+
version_file: gradle.properties
13+
on_missing_snapshot_zip: drop_content
14+
username: '${env.ARTIFACTORY_USERNAME}'
15+
password: '${env.ARTIFACTORY_PASSWORD}'
16+
locations:
17+
- url: https://repo.spring.io/snapshot/org/springframework/restdocs/spring-restdocs-docs/${version}/spring-restdocs-docs-${version}-${name}-${classifier}.zip
18+
for-version-type: [snapshot]
19+
- url: https://repo.spring.io/milestone/org/springframework/restdocs/spring-restdocs-docs/${version}/spring-restdocs-docs-${version}-${name}-${classifier}.zip
20+
for-version-type: [milestone, rc]
21+
- url: https://repo.spring.io/release/org/springframework/restdocs/spring-restdocs-docs/${version}/spring-restdocs-docs-${version}-${name}-${classifier}.zip
22+
for-version-type: [release]
23+
# The root component extension must be last!
24+
- require: '@springio/antora-extensions/root-component-extension'
25+
root_component_name: restdocs
26+
site:
27+
title: Spring REST Docs
28+
url: https://docs.spring.io/spring-restdocs
29+
robots: allow
30+
content:
31+
sources:
32+
- url: .
33+
branches:
34+
- 'main'
35+
tags:
36+
- 'v4.0.0'
37+
start_paths:
38+
- spring-restdocs-docs/src/docs/antora
39+
version: unspecified
40+
asciidoc:
41+
sourcemap: true
42+
attributes:
43+
chomp: all
44+
hide-uri-scheme: '@'
45+
javadoc-location: xref:api:java/
46+
page-pagination: ''
47+
page-stackoverflow-url: https://stackoverflow.com/tags/spring-restdocs
48+
tabs-sync-option: '@'
49+
extensions:
50+
- '@asciidoctor/tabs'
51+
- '@springio/asciidoctor-extensions'
52+
- '@springio/asciidoctor-extensions/javadoc-extension'
53+
- '@springio/asciidoctor-extensions/section-ids-extension'
54+
urls:
55+
latest_version_segment: ''
56+
latest_version_segment_strategy: redirect:to
57+
redirect_facility: httpd
58+
runtime:
59+
log:
60+
failure_level: warn

run.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
;(function () {
2+
'use strict'
3+
4+
const childProcess = require('child_process')
5+
const fs = require('fs');
6+
7+
async function main() {
8+
try {
9+
checkout(process.argv.includes('--no-checkout'))
10+
if (!process.argv.includes('--only-checkout')) {
11+
install(process.argv.includes('--no-install'))
12+
run(process.argv.includes('--no-run'))
13+
}
14+
} catch (error) {
15+
console.log("Unexpected error")
16+
process.exitCode = (error.exitCode) ? error.exitCode : 1
17+
}
18+
}
19+
20+
function checkout(skip) {
21+
if (skip) return
22+
console.log('Checking out Antora package.json files from `main`')
23+
const packageJson = childProcess.execSync('git show main:antora/package.json', {env: process.env})
24+
const packageLockJson = childProcess.execSync('git show main:antora/package-lock.json', {env: process.env})
25+
fs.writeFileSync('package.json', packageJson)
26+
fs.writeFileSync('package-lock.json', packageLockJson)
27+
}
28+
29+
function install(skip) {
30+
if (skip) return
31+
console.log('Installing modules')
32+
childProcess.execSync('npm ci --silent --no-progress', {stdio: 'inherit', env: process.env})
33+
}
34+
35+
function run(skip) {
36+
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'))
37+
const uiBundleUrl = packageJson.config['ui-bundle-url'];
38+
const playbook = 'antora-playbook.yml'
39+
const command = `npx antora ${playbook} --stacktrace --ui-bundle-url ${uiBundleUrl}`
40+
if (uiBundleUrl.includes('/latest/')) {
41+
console.log('Refusing to run Antora with development build of UI')
42+
console.log(`$ ${command}`)
43+
process.exitCode = 1
44+
return
45+
}
46+
console.log((!skip) ? 'Running Antora' : 'Use the following command to run Antora')
47+
console.log(`$ ${command}`)
48+
if (!skip) childProcess.execSync(command, {stdio: 'inherit', env: process.env})
49+
}
50+
51+
main()
52+
53+
})()

0 commit comments

Comments
 (0)