Skip to content

Commit 7efd106

Browse files
SaxenaAnushka102gbartolinileonardoce
authored
feat: add automated docs sync workflow and import script (#3)
This PR introduces the initial automation required for synchronising CloudNativePG documentation into this repository. Signed-off-by: Anushka Saxena <[email protected]> Signed-off-by: ANUSHKA SAXENA <[email protected]> Signed-off-by: Gabriele Bartolini <[email protected]> Signed-off-by: Leonardo Cecchi <[email protected]> Co-authored-by: Gabriele Bartolini <[email protected]> Co-authored-by: Leonardo Cecchi <[email protected]>
1 parent 2341797 commit 7efd106

File tree

3 files changed

+216
-3
lines changed

3 files changed

+216
-3
lines changed

.github/workflows/sync_docs.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Import CloudNativePG Docs
2+
3+
on:
4+
repository_dispatch:
5+
types: [cnpg-docs-release]
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
import:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
# -----------------------------
16+
# CHECKOUT CNPG DOCS REPO
17+
# -----------------------------
18+
- name: Checkout docs repo
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Setup Node.js
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: 20
27+
cache: 'yarn'
28+
29+
- name: Install dependencies
30+
run: yarn install --frozen-lockfile
31+
32+
# -----------------------------
33+
# RUN IMPORT SCRIPT
34+
# -----------------------------
35+
- name: Import docs
36+
env:
37+
VERSION: ${{ github.event.client_payload.version }}
38+
run: |
39+
echo "Importing CloudNativePG docs for version: $VERSION"
40+
./scripts/import_docs.sh "$VERSION"
41+
42+
# -----------------------------
43+
# COMMIT CHANGES
44+
# -----------------------------
45+
- name: Commit changes
46+
run: |
47+
git config user.name "github-actions"
48+
git config user.email "[email protected]"
49+
git add .
50+
git commit -m "docs: import CloudNativePG $VERSION" || echo "No changes to commit"
51+
52+
# -----------------------------
53+
# PUSH CHANGES
54+
# -----------------------------
55+
- name: Push changes
56+
run: git push

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,17 @@ yarn
4949
yarn start
5050
```
5151

52-
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.
52+
This command starts a local development server and opens up a browser window.
53+
Most changes are reflected live without having to restart the server.
5354

5455
## Build
5556

5657
```bash
5758
yarn build
5859
```
5960

60-
This command generates static content into the `build` directory and can be served using any static contents hosting service.
61+
This command generates static content into the `build` directory and can be
62+
served using any static contents hosting service.
6163

6264
## Deployment
6365

@@ -73,7 +75,15 @@ Not using SSH:
7375
GIT_USER=<Your GitHub username> yarn deploy
7476
```
7577

76-
If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
78+
If you are using GitHub pages for hosting, this command is a convenient way to
79+
build the website and push to the `gh-pages` branch.
80+
81+
---
82+
83+
## Workflow
84+
85+
The documentation is updated from the upstream CloudNativePG project by the
86+
[`sync_docs` workflow](.github/workflows/sync_docs.yml).
7787

7888
---
7989

scripts/import_docs.sh

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#!/usr/bin/env bash
2+
3+
##
4+
## Copyright © contributors to CloudNativePG, established as
5+
## CloudNativePG a Series of LF Projects, LLC.
6+
##
7+
## Licensed under the Apache License, Version 2.0 (the "License");
8+
## you may not use this file except in compliance with the License.
9+
## You may obtain a copy of the License at
10+
##
11+
## http://www.apache.org/licenses/LICENSE-2.0
12+
##
13+
## Unless required by applicable law or agreed to in writing, software
14+
## distributed under the License is distributed on an "AS IS" BASIS,
15+
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
## See the License for the specific language governing permissions and
17+
## limitations under the License.
18+
##
19+
## SPDX-License-Identifier: Apache-2.0
20+
##
21+
22+
set -euo pipefail
23+
24+
SOURCE_REPO="https://github.com/cloudnative-pg/cloudnative-pg.git"
25+
SOURCE_DOCS_PATH="docs/src"
26+
TMP_BASE="$(mktemp -d)"
27+
trap 'rm -rf "$TMP_BASE"' EXIT
28+
29+
VERSION_ARG="${1:-}"
30+
if [[ -z "$VERSION_ARG" ]]; then
31+
cat <<EOF
32+
Usage: $0 <tag|main> [branch name]
33+
34+
This script brings in the documentation from GitHub at
35+
github.com/cloudnative-pg/cloudnative-pg into the documentation repository.
36+
The first argument can either be "main" to import the most recent development
37+
snapshot or a specific version tag. The second argument is optional and allows
38+
you to import the documentation using a specified Git reference rather than
39+
the first argument.
40+
41+
### Examples:
42+
43+
To import the latest development snapshot:
44+
45+
./scripts/import_docs main
46+
47+
To import the documentation for a new release:
48+
49+
./scripts/import_docs v1.28.0
50+
51+
To update the existing documentation for the specified tag using the
52+
release branch:
53+
54+
./scripts/import_docs v1.28.0 release-1.28
55+
56+
EOF
57+
exit 1
58+
fi
59+
60+
GIT_REF="${2:-$1}"
61+
62+
# Normalize version label (strip leading 'v')
63+
VERSION_LABEL="$(echo "$VERSION_ARG" | sed 's/^v//')"
64+
65+
echo "=== Import job starting for: $VERSION_ARG (label: $VERSION_LABEL) ==="
66+
echo "Working temp: $TMP_BASE"
67+
68+
# Determine type
69+
IS_MAIN=false
70+
IS_RC=false
71+
72+
if [[ "$VERSION_ARG" == "main" ]]; then
73+
IS_MAIN=true
74+
elif [[ "$VERSION_LABEL" =~ ^[0-9]+\.[0-9]+\.[0-9]+-rc[0-9]+$ ]]; then
75+
IS_RC=true
76+
VERSION_DIR=$(echo "$VERSION_ARG" | sed -E 's/^v([0-9]+.[0-9]+).*/\1/')
77+
elif [[ "$VERSION_LABEL" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
78+
VERSION_DIR=$(echo "$VERSION_ARG" | sed -E 's/^v([0-9]+.[0-9]+).*/\1/')
79+
else
80+
echo "Invalid version argument: '$VERSION_ARG'"
81+
exit 1
82+
fi
83+
84+
# Clone the repo
85+
SRC_TMP="$TMP_BASE/source"
86+
echo "Cloning $SOURCE_REPO ($VERSION_ARG) -> $SRC_TMP"
87+
88+
if ! git clone --depth 1 --branch "${GIT_REF}" "$SOURCE_REPO" "$SRC_TMP" 2>/dev/null; then
89+
echo "ERROR: failed to clone branch/tag for ${GIT_REF}."
90+
exit 1
91+
else
92+
echo "Cloned using ref ${GIT_REF}"
93+
fi
94+
95+
SOURCE_PATH="$SRC_TMP/$SOURCE_DOCS_PATH"
96+
if [[ ! -d "$SOURCE_PATH" ]]; then
97+
echo "ERROR: expected docs folder at $SOURCE_PATH"
98+
exit 1
99+
fi
100+
101+
# Install node modules if missing
102+
if ! command -v yarn >/dev/null 2>&1; then
103+
echo "ERROR: yarn not found. Install Yarn."
104+
exit 1
105+
fi
106+
107+
if [[ ! -d "node_modules" ]]; then
108+
echo "node_modules missing: running yarn install"
109+
yarn install --silent
110+
fi
111+
112+
# ===== MAIN BRANCH =====
113+
if [[ "$IS_MAIN" == true ]]; then
114+
echo "Copying imported docs -> ./docs"
115+
mkdir -p ./docs
116+
rsync -av --delete "$SOURCE_PATH/" --exclude "css" ./docs/
117+
118+
echo "Updated ./docs from main — import completed."
119+
exit 0
120+
fi
121+
122+
# ===== VERSION TAG =====
123+
if grep -q "\"${VERSION_DIR}\"" versions.json 2>/dev/null; then
124+
# Import the new version in the correct folder
125+
TARGET_DIRECTORY="./versioned_docs/version-${VERSION_DIR}"
126+
echo "Copying imported docs -> ${TARGET_DIRECTORY}"
127+
rsync -av --delete "$SOURCE_PATH/" --exclude "css" "${TARGET_DIRECTORY}"
128+
else
129+
# Create Docusaurus version
130+
echo "Running: yarn docusaurus docs:version ${VERSION_DIR}"
131+
yarn docusaurus docs:version "${VERSION_DIR}"
132+
133+
# Import the new version in the correct folder
134+
TARGET_DIRECTORY="./versioned_docs/version-${VERSION_DIR}"
135+
echo "Copying imported docs -> ${TARGET_DIRECTORY}"
136+
rsync -av --delete "$SOURCE_PATH/" --exclude "css" "${TARGET_DIRECTORY}"
137+
138+
echo "=== Done: Docusaurus version ${VERSION_DIR} created ==="
139+
fi
140+
141+
# Mark RC as preview
142+
VDIR="versioned_docs/version-${VERSION_DIR}"
143+
if [[ "$IS_RC" == true ]]; then
144+
echo "Marking ${VDIR} as preview (rc)"
145+
echo "preview: true" > "${VDIR}/.preview"
146+
fi
147+

0 commit comments

Comments
 (0)