Skip to content

feat: Login with Internet Identity #504

feat: Login with Internet Identity

feat: Login with Internet Identity #504

Workflow file for this run

name: Documentation
on:
push:
tags:
- 'v*'
- '!v*-*' # exclude pre-release tags (e.g. v0.2.0-beta.0)
branches:
- main
- 'docs/v*'
- '!docs/v*-*' # exclude pre-release doc branches
paths:
- 'docs/**'
- 'docs-site/**'
- '.github/workflows/docs.yml'
pull_request:
paths:
- 'docs/**'
- 'docs-site/**'
- '.github/workflows/docs.yml'
workflow_dispatch:
permissions:
contents: write
env:
PUBLIC_SITE: https://cli.internetcomputer.org
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
# Build job - validates that docs build successfully
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup Node
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: '22'
cache: 'npm'
cache-dependency-path: docs-site/package-lock.json
- name: Install dependencies
working-directory: ./docs-site
run: npm ci
- name: Build documentation site
working-directory: ./docs-site
run: npm run build
env:
NODE_ENV: production
PUBLIC_SITE: ${{ env.PUBLIC_SITE }}
# Publish root index, versions list, and IC config files - only runs on main branch
publish-root-files:
if: github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup Node
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: '22'
- name: Prepare root files
run: |
mkdir -p root/.well-known
# Copy versions.json from repo
cp docs-site/versions.json root/versions.json
# Copy IC asset canister config files
cp docs-site/icp.yaml root/icp.yaml
cp docs-site/.ic-assets.json5 root/.ic-assets.json5
mkdir -p root/.icp/data/mappings
cp docs-site/.icp/data/mappings/ic.ids.json root/.icp/data/mappings/ic.ids.json
# Copy custom domain file
cp docs-site/public/.well-known/ic-domains root/.well-known/ic-domains
# Copy Matomo analytics script (site ID defined once here, not per-version)
cp docs-site/matomo.js root/matomo.js
# Extract the latest version from versions.json
LATEST_VERSION=$(jq -r ".versions[] | select(.latest == true) | .version" docs-site/versions.json)
# If no releases yet, redirect to main branch docs
if [[ -z "$LATEST_VERSION" ]]; then
echo "⚠️ No releases yet, redirecting to main branch docs"
LATEST_VERSION="main"
else
echo "✅ Redirecting to version: ${LATEST_VERSION}"
fi
# Generate index.html that redirects to latest version
cat > root/index.html << EOF
<!doctype html>
<html>
<head>
<meta http-equiv="refresh" content="0; url=./${LATEST_VERSION}/" />
<meta name="robots" content="noindex" />
</head>
</html>
EOF
echo "LATEST_VERSION=${LATEST_VERSION}" >> $GITHUB_ENV
- name: Copy llms.txt from latest version on docs-deployment branch
run: |
# Fetch the llms.txt from the latest version's folder on docs-deployment.
# This file was deployed by publish-versioned-docs and is always in sync
# with the versioned .md endpoints it links to.
git fetch origin docs-deployment --depth=1
if git show "origin/docs-deployment:${LATEST_VERSION}/llms.txt" > root/llms.txt 2>/dev/null; then
echo "✅ Copied llms.txt from /${LATEST_VERSION}/llms.txt to root"
else
echo "⚠️ No llms.txt found at /${LATEST_VERSION}/llms.txt on docs-deployment — skipping"
rm -f root/llms.txt
fi
- name: Prepend version navigation to root llms.txt
if: hashFiles('root/llms.txt') != ''
run: |
# Build a version navigation header from versions.json.
# Only the root llms.txt gets this — versioned copies stay static.
SITE="${PUBLIC_SITE}"
HEADER="This documentation is for v${LATEST_VERSION}. Other versions are available:"
VERSION_LINES=""
for version in $(jq -r '.versions[].version' docs-site/versions.json); do
if [[ "$version" != "$LATEST_VERSION" ]]; then
VERSION_LINES="${VERSION_LINES}\n- [v${version}](${SITE}/${version}/llms.txt)"
fi
done
VERSION_LINES="${VERSION_LINES}\n- [Development (main)](${SITE}/main/llms.txt)"
# Insert after the description blockquote (line starting with ">")
sed -i "s|^> .*|&\n\n${HEADER}${VERSION_LINES}|" root/llms.txt
echo "✅ Added version navigation to root llms.txt"
- name: Deploy root files to docs-deployment branch
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./root
publish_branch: docs-deployment
keep_files: true
# Publish main branch docs for preview (always available at /main/)
publish-main-docs:
if: github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup Node
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: '22'
cache: 'npm'
cache-dependency-path: docs-site/package-lock.json
- name: Install dependencies
working-directory: ./docs-site
run: npm ci
- name: Build main branch docs
working-directory: ./docs-site
run: |
echo "Building with base: /main/"
npm run build
env:
NODE_ENV: production
PUBLIC_BASE_PATH: /main/
PUBLIC_SITE: ${{ env.PUBLIC_SITE }}
- name: Deploy main docs to docs-deployment branch
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs-site/dist
publish_branch: docs-deployment
destination_dir: main
keep_files: true
# Publish versioned docs - runs on tags (v*) or docs branches (docs/v*)
publish-versioned-docs:
if: github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/v') || startsWith(github.ref, 'refs/heads/docs/v'))
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup Node
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: '22'
cache: 'npm'
cache-dependency-path: docs-site/package-lock.json
- name: Install dependencies
working-directory: ./docs-site
run: npm ci
- name: Extract version from tag or branch
run: |
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
# Tag: v0.1.0 -> extract major.minor -> 0.1
VERSION=${GITHUB_REF#refs/tags/v}
# Strip patch version (0.1.0 -> 0.1)
VERSION=${VERSION%.*}
echo "DOCS_VERSION=${VERSION}" >> $GITHUB_ENV
echo "DOCS_BASE_PATH=/${VERSION}/" >> $GITHUB_ENV
elif [[ "${GITHUB_REF}" == refs/heads/docs/v* ]]; then
# Branch: docs/v0.1 -> extract version -> 0.1
VERSION=${GITHUB_REF#refs/heads/docs/v}
echo "DOCS_VERSION=${VERSION}" >> $GITHUB_ENV
echo "DOCS_BASE_PATH=/${VERSION}/" >> $GITHUB_ENV
else
echo "❌ Docs should only be published for version tags (v*) or docs branches (docs/v*)"
echo "Current ref: ${GITHUB_REF}"
exit 1
fi
echo "Building docs for version ${VERSION} with base: /${VERSION}/"
- name: Build documentation site
working-directory: ./docs-site
run: npm run build
env:
NODE_ENV: production
PUBLIC_BASE_PATH: ${{ env.DOCS_BASE_PATH }}
PUBLIC_SITE: ${{ env.PUBLIC_SITE }}
- name: Deploy versioned docs to docs-deployment branch
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs-site/dist
publish_branch: docs-deployment
destination_dir: ${{ env.DOCS_VERSION }}
# Deploy docs-deployment branch to IC asset canister.
# Runs when at least one publish job succeeded (skipped on PR builds).
# always() prevents auto-skip when publish-versioned-docs is skipped (e.g. on main branch pushes).
deploy-to-ic:
needs: [publish-root-files, publish-main-docs, publish-versioned-docs]
if: always() && github.event_name != 'pull_request' && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled')
uses: ./.github/workflows/docs-deploy.yml
secrets: inherit