Skip to content

docs: add versioned docs build with tag-based snapshots#980

Open
efiacor wants to merge 2 commits into
kptdev:mainfrom
Nordix:docs_versioning
Open

docs: add versioned docs build with tag-based snapshots#980
efiacor wants to merge 2 commits into
kptdev:mainfrom
Nordix:docs_versioning

Conversation

@efiacor
Copy link
Copy Markdown
Collaborator

@efiacor efiacor commented May 12, 2026

Description

  • What changed: Added a multi-version docs build system using git tags
  • Why it's needed: Serve versioned docs (e.g. /v1.5/) alongside latest, preparing for porch.kpt.dev
  • How it works: scripts/build-versioned-docs.sh reads docs/versions.json, builds main to / and each tagged version to its subdirectory (e.g. /v1.5/). Docsy's built-in version-banner and navbar-version-selector handle the UI.

Type of Change

  • Documentation
  • New feature

Checklist

  • Code follows project style guidelines
  • Self-reviewed changes
  • Tests added/updated
  • Documentation added/updated
  • All tests and gating checks pass

Testing Instructions

  1. Netlify deploy preview should show the version dropdown in the navbar
  2. Navigate to /v1.5/ in the preview — should show archived docs with banner
  3. Run locally: ./scripts/build-versioned-docs.sh and check docs/public/ and docs/public/v1.5/

Additional Notes

  • Only standard tools used: awk, git, hugo, npm (no jq/python dependency)
  • v1.5.9 tag must exist for the versioned build to include it (gracefully skipped if missing)
  • Prepares for domain move to porch.kpt.dev (all URLs are relative)
  • Old versioned docs are frozen at tag time — fix forward on main

AI Disclosure

[x] I have used AI in the creation of this PR.

  • Kiro to design the versioning strategy and implement the build script
  • The author has fully verified all code

@efiacor efiacor added the documentation Improvements or additions to documentation label May 12, 2026
@efiacor efiacor self-assigned this May 12, 2026
@efiacor efiacor added the documentation Improvements or additions to documentation label May 12, 2026
@netlify
Copy link
Copy Markdown

netlify Bot commented May 12, 2026

Deploy Preview for porch ready!

Name Link
🔨 Latest commit 53b36bc
🔍 Latest deploy log https://app.netlify.com/projects/porch/deploys/6a0346fa379f1f000870132d
😎 Deploy Preview https://deploy-preview-980--porch.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

- Add versions.json manifest to define which versions to build
- Add build-versioned-docs.sh script that builds main (latest) and
  tagged versions into subdirectories (e.g. /v1.5/)
- Update netlify.toml to use the versioned build script
- Update config.toml: relative URLs, version dropdown entries, latestTag
- Docsy's built-in version-banner and navbar-version-selector handle
  the archived banner and version switcher dropdown

The script uses only standard tools (awk, git, hugo, npm) with no
additional dependencies. Tagged versions are built with an archived
overlay config so Docsy renders the 'no longer maintained' banner.

Signed-off-by: Fiachra Corcoran <fiachra.corcoran@est.tech>
@efiacor efiacor force-pushed the docs_versioning branch from 48a02f2 to 53b36bc Compare May 12, 2026 15:27
@sonarqubecloud
Copy link
Copy Markdown

Copilot AI review requested due to automatic review settings May 13, 2026 15:42
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a tag-based, multi-version Hugo docs build so the site can serve “latest” plus archived snapshots under versioned prefixes (e.g. /v1.5/) for Netlify deployment.

Changes:

  • Added scripts/build-versioned-docs.sh to build current docs plus archived versions from git tags described in docs/versions.json.
  • Switched Netlify docs build to use the new script instead of a single Hugo invocation.
  • Updated docs config for the version selector and refreshed the latest release tag metadata.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
scripts/build-versioned-docs.sh New multi-version docs build script: builds latest + per-tag archived sites into one publish directory.
docs/versions.json Declares which versions/tags/paths should be built as archived snapshots.
docs/netlify.toml Uses the new versioned build script for Netlify builds.
docs/config.toml Updates latest tag metadata and version selector entries; makes latest-docs link relative.
Comments suppressed due to low confidence (4)

scripts/build-versioned-docs.sh:63

  • rm -rf "${OUTPUT_DIR}" can be destructive if the script is invoked with an unexpected/empty argument (e.g. /). Add a safety check/guardrail (reject empty, /, and possibly paths outside the repo/docs tree) before deleting.
# Clean output directory
rm -rf "${OUTPUT_DIR}"
mkdir -p "${OUTPUT_DIR}"

scripts/build-versioned-docs.sh:73

  • npm install --quiet 2>/dev/null || true hides install failures and allows the build to proceed with missing PostCSS tooling, potentially producing incomplete/broken assets without surfacing the root cause. Consider failing the build on npm errors (and/or using a more deterministic install like npm ci if a lockfile is available).
  # Install npm dependencies (needed for PostCSS/autoprefixer)
  if [[ -f "package.json" ]]; then
    npm install --quiet 2>/dev/null || true
  fi

scripts/build-versioned-docs.sh:107

  • Temp dirs are only removed on the success path; if git archive, sed, or hugo fails, the script exits (due to set -e) and leaves ${TEMP_DIR} behind. Use a trap to ensure cleanup on EXIT/ERR for each created temp dir.
  # Create a temporary directory for the tagged docs
  TEMP_DIR=$(mktemp -d)

  # Extract the docs directory from the tag
  git -C "${REPO_ROOT}" archive "${TAG}" -- docs/ | tar -x -C "${TEMP_DIR}"

scripts/build-versioned-docs.sh:144

  • Same issue as the latest build: npm install --quiet ... || true suppresses errors in the tagged builds, which can yield silently broken CSS/JS for archived versions. Prefer surfacing npm failures and using a deterministic install approach.
    # Install npm dependencies if package.json exists (needed for PostCSS/autoprefixer)
    if [[ -f "package.json" ]]; then
      npm install --quiet 2>/dev/null || true
    fi

Comment on lines +36 to +42
# Ensure required tools are available
for cmd in hugo git npm; do
if ! command -v "${cmd}" &> /dev/null; then
echo "ERROR: ${cmd} is required but not installed." >&2
exit 1
fi
done
Comment thread docs/versions.json
Comment on lines +1 to +11
[
{
"version": "latest",
"tag": null,
"path": "/"
},
{
"version": "v1.5",
"tag": "v1.5.9",
"path": "/v1.5/"
}
Comment thread docs/config.toml
# point people to the main doc site.

url_latest_version = "https://docs.porch.nephio.org/docs/"
url_latest_version = "/docs/"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a few comments

Comment on lines +156 to +157
# Clean up temp dir
rm -rf "${TEMP_DIR}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will only cleanup if its reached no? what if the script exists early for some reason? on github netlify build runners that's not an issue and these get wiped anyways but if people build locally and crash occurs their tmp dir's will leave a the temp_dir behind on every crash no?

Not a big deal but just a thought

Comment on lines +109 to +116
# Remove existing [[params.versions]] entries from the tagged config
# to prevent duplication when our override config is merged
sed -i '/^\[\[params\.versions\]\]/,/^$/d' "${TEMP_DIR}/docs/config.toml"

# Fix hardcoded absolute paths in content files so they respect the versioned baseURL.
# Raw HTML links in Hugo shortcodes bypass baseURL processing.
find "${TEMP_DIR}/docs/content" -name "*.md" -exec \
sed -i "s|href=\"/docs|href=\"${URL_PATH}docs|g" {} \;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an AI discovered potential issue as i would not have found this but apparently on MacOS sed parses slightly differently e.g. On macOS, sed -i requires an empty string argument (sed -i '') and If contributors build docs locally on macOS, this will fail. Since it runs on Netlify (Linux), it's fine for CI.

We would need someone using MacOS to confirm it.

Did a bit of digging and found the following which explains it here

Suggested change
# Remove existing [[params.versions]] entries from the tagged config
# to prevent duplication when our override config is merged
sed -i '/^\[\[params\.versions\]\]/,/^$/d' "${TEMP_DIR}/docs/config.toml"
# Fix hardcoded absolute paths in content files so they respect the versioned baseURL.
# Raw HTML links in Hugo shortcodes bypass baseURL processing.
find "${TEMP_DIR}/docs/content" -name "*.md" -exec \
sed -i "s|href=\"/docs|href=\"${URL_PATH}docs|g" {} \;
# Remove existing [[params.versions]] entries from the tagged config
# to prevent duplication when our override config is merged
sed -i'' -e '/^\[\[params\.versions\]\]/,/^$/d' "${TEMP_DIR}/docs/config.toml"
# Fix hardcoded absolute paths in content files so they respect the versioned baseURL.
# Raw HTML links in Hugo shortcodes bypass baseURL processing.
find "${TEMP_DIR}/docs/content" -name "*.md" -exec \
sed -i'' -e "s|href=\"/docs|href=\"${URL_PATH}docs|g" {} \;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is well known by MacOS users, especially the different behavoiour of the -i parameter. We usually just do some hackery to override the MacOS stock sed with gsed, the Linux-compatible one. I have done this

% which sed
/usr/local/bin/sed
% ls -l /usr/local/bin/sed
lrwxr-xr-x  1 root  admin  22 15 May 14:10 /usr/local/bin/sed -> /opt/homebrew/bin/gsed
% sed --version
sed (GNU sed) 4.10

So in short it is fine to ignore this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants