Skip to content

New Catalog frontend #2021

New Catalog frontend

New Catalog frontend #2021

Workflow file for this run

name: Build and Deploy Catalog (TSX)
on:
push:
branches:
- '**'
paths:
- apps/**/data.yaml
- apps/*/example/**
- apps/*/charts/**
- k0rdent_catalog.tsx
- tsweb/**
- scripts/generate_catalog_json.py
- scripts/generate_html_pages.py
- scripts/utils.py
- .github/workflows/gh-pages-deploy.yml
pull_request:
types: [opened, synchronize, reopened]
paths:
- apps/**/data.yaml
- apps/*/example/**
- apps/*/charts/**
- k0rdent_catalog.tsx
- tsweb/**
- scripts/generate_catalog_json.py
- scripts/generate_html_pages.py
- scripts/utils.py
- .github/workflows/gh-pages-deploy.yml
permissions:
contents: write
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.x"
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: "22"
- name: Install Python dependencies
run: pip install pyyaml jinja2 ruyaml jsonschema packaging
- name: Determine base path and SITE_URL
id: base
run: |
if [ "${{ github.repository }}" = "k0rdent/catalog" ]; then
echo "path=/latest/" >> "$GITHUB_OUTPUT"
echo "site_url=https://catalog.k0rdent.io" >> "$GITHUB_OUTPUT"
else
REPO_NAME="${{ github.event.repository.name }}"
OWNER="${{ github.repository_owner }}"
echo "path=/${REPO_NAME}/latest/" >> "$GITHUB_OUTPUT"
echo "site_url=https://${OWNER}.github.io/${REPO_NAME}" >> "$GITHUB_OUTPUT"
fi
- name: Generate catalog data for all versions
env:
SITE_URL: ${{ steps.base.outputs.site_url }}
run: |
mkdir -p tsweb/public
OUTPUT_DIR=tsweb/public python3 scripts/generate_catalog_json.py --all-versions
- name: Generate index.json for all versions
env:
SITE_URL: ${{ steps.base.outputs.site_url }}
run: |
python3 -c "
import yaml, subprocess, shutil, os
with open('versions.yaml') as f:
cfg = yaml.safe_load(f)
for v in cfg['versions']:
subprocess.run(['python3', 'scripts/generate_index.py'], env={**os.environ, 'VERSION': v}, check=True)
dst = os.path.join('tsweb/public', v)
os.makedirs(dst, exist_ok=True)
shutil.copy2('mkdocs/index.json', os.path.join(dst, 'index.json'))
os.makedirs(os.path.join(dst, 'schema'), exist_ok=True)
if os.path.exists('mkdocs/schema/index.json'):
shutil.copy2('mkdocs/schema/index.json', os.path.join(dst, 'schema/index.json'))
"
- name: Install Node dependencies
working-directory: tsweb
run: npm ci --ignore-scripts 2>/dev/null || npm install
- name: Build SPA
working-directory: tsweb
env:
BASE_PATH: ${{ steps.base.outputs.path }}
run: npx vite build
- name: Assemble deploy folder with versioned data
run: |
mkdir -p tsweb/deploy/latest
# SPA bundle goes into /latest/ (the default entry point)
cp -r tsweb/dist/* tsweb/deploy/latest/
cp tsweb/dist/index.html tsweb/deploy/404.html
cp tsweb/dist/index.html tsweb/deploy/latest/404.html
echo '<html><head><meta http-equiv="refresh" content="0;url=latest/"></head></html>' > tsweb/deploy/index.html
# Copy versions.json to root for the SPA version selector
cp tsweb/public/versions.json tsweb/deploy/latest/versions.json
# Copy versioned data (catalog.json, install.json, index.json, logos) per version
python3 -c "
import yaml, shutil, os
with open('versions.yaml') as f:
cfg = yaml.safe_load(f)
for v in cfg['versions']:
src = os.path.join('tsweb/public', v)
dst = os.path.join('tsweb/deploy', v)
if os.path.exists(src):
shutil.copytree(src, dst, dirs_exist_ok=True)
# Each version also needs the SPA for direct URL access
shutil.copy2('tsweb/dist/index.html', os.path.join(dst, 'index.html'))
shutil.copy2('tsweb/dist/index.html', os.path.join(dst, '404.html'))
# Copy SPA assets
assets_src = os.path.join('tsweb/dist/assets')
assets_dst = os.path.join(dst, 'assets')
if os.path.exists(assets_src) and not os.path.exists(assets_dst):
shutil.copytree(assets_src, assets_dst)
# Copy versions.json to each version folder
shutil.copy2('tsweb/public/versions.json', os.path.join(dst, 'versions.json'))
# /latest/ gets the latest version's data
latest = cfg['latest']
latest_src = os.path.join('tsweb/public', latest)
if os.path.exists(latest_src):
shutil.copytree(latest_src, 'tsweb/deploy/latest', dirs_exist_ok=True)
# Shared logos at root level (from latest)
logos_src = os.path.join(latest_src, 'logos')
if os.path.exists(logos_src):
shutil.copytree(logos_src, 'tsweb/deploy/latest/logos', dirs_exist_ok=True)
print(f'Assembled {len(cfg[\"versions\"])} versions, latest={latest}')
"
- name: Add CNAME for custom domain (main repo only)
if: github.repository == 'k0rdent/catalog'
run: echo "catalog.k0rdent.io" > tsweb/deploy/CNAME
- name: Deploy to gh-pages (push only)
if: github.event_name == 'push'
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: tsweb/deploy
publish_branch: gh-pages
force_orphan: true
user_name: github-actions[bot]
user_email: 41898282+github-actions[bot]@users.noreply.github.com
commit_message: "Deploy catalog from ${{ github.sha }}"