docs: standardize print syntax to keyword-style in control flow #75
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Sync Standard Library Documentation | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| sync-docs: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Docs Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| path: 'docs-repo' | |
| - name: Checkout Website Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: 'zenc-lang/www' | |
| token: ${{ secrets.WEBSITE_REPO_TOKEN }} | |
| path: 'website' | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Split Language Reference | |
| run: | | |
| cd docs-repo | |
| python3 scripts/split_reference.py | |
| - name: Sync Files to Website Repo | |
| run: | | |
| # Sync Standard Library (localized) | |
| mkdir -p website/docs.zenc-lang.org/content/std/ | |
| rsync -avz --delete --exclude='_index*.md' docs-repo/std/ website/docs.zenc-lang.org/content/std/ | |
| # Rename all README files to _index files for Zola | |
| find website/docs.zenc-lang.org/content/std/ -name "README*.md" | while read file; do | |
| target=$(echo "$file" | sed 's/README/_index/') | |
| mv "$file" "$target" | |
| done | |
| # Sync Language Tour (Split Reference) | |
| mkdir -p website/docs.zenc-lang.org/content/tour/ | |
| rsync -avz --delete --exclude='_index.md' docs-repo/reference/ website/docs.zenc-lang.org/content/tour/ | |
| # Sync Rosetta Examples | |
| mkdir -p website/docs.zenc-lang.org/content/examples/rosetta/ | |
| rsync -avz --delete --exclude='_index*.md' docs-repo/rosetta/ website/docs.zenc-lang.org/content/examples/rosetta/ | |
| # Rename all README files to _index files | |
| find website/docs.zenc-lang.org/content/examples/rosetta/ -name "README*.md" | while read file; do | |
| target=$(echo "$file" | sed 's/README/_index/') | |
| mv "$file" "$target" | |
| done | |
| # Section Guard: Ensure _index.<lang>.md exists for all languages to prevent Zola build crash | |
| LANGS="es pt it de ru zh-cn zh-tw" | |
| find website/docs.zenc-lang.org/content/ -name "_index.md" | while read index_file; do | |
| dir=$(dirname "$index_file") | |
| for lang in $LANGS; do | |
| lang_index="$dir/_index.$lang.md" | |
| if [ ! -f "$lang_index" ]; then | |
| echo " [GUARD] Creating fallback for $lang_index" | |
| cp "$index_file" "$lang_index" | |
| fi | |
| done | |
| done | |
| # Sync config.toml (Source of truth is docs/site/config.toml) | |
| cp docs-repo/site/config.toml website/docs.zenc-lang.org/config.toml | |
| # Ensure all synced files have frontmatter (if missing) and clean Rosetta templates | |
| find website/docs.zenc-lang.org/content/ -name "*.md" | while read file; do | |
| # 1. Clean Rosetta templates ({{trans|...}}) | |
| sed -i 's/{{trans|.*}}//g' "$file" | |
| # 2. Add frontmatter if missing | |
| if ! head -n 1 "$file" | grep -q "^+++"; then | |
| TITLE=$(grep -m 1 "^# " "$file" | sed 's/^# //; s/"/\\"/g' || echo "Documentation") | |
| TEMP=$(mktemp) | |
| echo "+++" > "$TEMP" | |
| echo "title = \"$TITLE\"" >> "$TEMP" | |
| echo "+++" >> "$TEMP" | |
| echo "" >> "$TEMP" | |
| cat "$file" >> "$TEMP" | |
| mv "$TEMP" "$file" | |
| fi | |
| done | |
| - name: Commit and Push to Website Repo | |
| run: | | |
| cd website | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add docs.zenc-lang.org/content/std/ docs.zenc-lang.org/content/examples/rosetta/ docs.zenc-lang.org/content/tour/ | |
| git diff --quiet && git diff --staged --quiet || (git commit -m "docs: auto-sync documentation and rosetta examples" && git push) |