docs: auto-sync Rosetta Code examples from zenc repo #11
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: Sync Files to Website Repo | |
| run: | | |
| # Sync Standard Library | |
| 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/ | |
| if [ -f "website/docs.zenc-lang.org/content/std/README.md" ]; then | |
| mv website/docs.zenc-lang.org/content/std/README.md website/docs.zenc-lang.org/content/std/_index.md | |
| fi | |
| for file in website/docs.zenc-lang.org/content/std/*.md; do | |
| 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 | |
| # Sync Rosetta Examples | |
| if [ -d "docs-repo/rosetta" ]; then | |
| 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/ | |
| for file in website/docs.zenc-lang.org/content/examples/rosetta/*.md; do | |
| if ! head -n 1 "$file" | grep -q "^+++"; then | |
| TITLE=$(grep -m 1 "^# " "$file" | sed 's/^# //; s/"/\\"/g' || echo "Rosetta Code") | |
| TEMP=$(mktemp) | |
| echo "+++" > "$TEMP" | |
| echo "title = \"$TITLE\"" >> "$TEMP" | |
| echo "+++" >> "$TEMP" | |
| echo "" >> "$TEMP" | |
| cat "$file" >> "$TEMP" | |
| mv "$TEMP" "$file" | |
| fi | |
| done | |
| fi | |
| - 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/ | |
| git diff --quiet && git diff --staged --quiet || (git commit -m "docs: auto-sync documentation and rosetta examples" && git push) |