Publish Wiki #4
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: Publish Wiki | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - "docs/**" | |
| - "README.md" | |
| - "samples/**/README.md" | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| publish-wiki: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Checkout wiki | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ github.repository }}.wiki | |
| path: wiki | |
| - name: Sync docs to wiki | |
| run: | | |
| # Remove old wiki pages that came from docs (keep any manually created pages) | |
| # We track synced files so we can clean up removed docs | |
| cd wiki | |
| # Remove all .md files in wiki root that we manage | |
| # (files that exist in docs/ or were previously synced) | |
| find . -maxdepth 1 -name '*.md' ! -name '_*' -delete | |
| # Remove old samples directory if it exists | |
| rm -rf samples | |
| cd .. | |
| # Define reusable sed pattern for converting markdown links to wiki links | |
| WIKI_LINK_PATTERN='s/\(\[[^]]*\]\)\(([^)]*\)\.md)/\1\2)/g' | |
| # Copy main README.md as Home.md (the wiki root/introduction) | |
| # Convert links: | |
| # 1. README.md -> Home | |
| # 2. docs/file.md -> file (remove docs/ prefix and .md extension) | |
| # 3. file.md -> file (remove .md extension) | |
| # 4. samples/Basic/FunctionalStateMachine.Samples -> samples/Basic/README | |
| # 5. samples/VendingMachine -> samples/VendingMachine/README | |
| # 6. samples/StockPurchaser -> samples/StockPurchaser/README | |
| sed 's|\(\[[^]]*\]\)(README\.md)|\1(Home)|g; s|docs/\([^)]*\)\.md|\1|g; '"$WIKI_LINK_PATTERN"'; s|(samples/Basic/FunctionalStateMachine.Samples)|(samples/Basic/README)|g; s|(samples/VendingMachine)|(samples/VendingMachine/README)|g; s|(samples/StockPurchaser)|(samples/StockPurchaser/README)|g' README.md > wiki/Home.md | |
| # Copy docs to wiki | |
| for file in docs/*.md; do | |
| filename=$(basename "$file") | |
| # Skip index.md since README.md is now Home.md | |
| if [ "$filename" = "index.md" ]; then | |
| continue | |
| fi | |
| target="wiki/$filename" | |
| # Copy file and convert relative .md links to wiki links | |
| sed 's/\(\[[^]]*\]\)(index\.md)/\1(Home)/g; '"$WIKI_LINK_PATTERN" "$file" > "$target" | |
| done | |
| # Create samples directory in wiki | |
| mkdir -p wiki/samples | |
| # Copy samples documentation | |
| # Basic samples | |
| if [ -f "samples/Basic/README.md" ]; then | |
| mkdir -p wiki/samples/Basic | |
| sed "$WIKI_LINK_PATTERN" samples/Basic/README.md > wiki/samples/Basic/README.md | |
| fi | |
| # VendingMachine sample | |
| if [ -f "samples/VendingMachine/VendingMachineSampleApp/README.md" ]; then | |
| mkdir -p wiki/samples/VendingMachine | |
| sed "$WIKI_LINK_PATTERN" samples/VendingMachine/VendingMachineSampleApp/README.md > wiki/samples/VendingMachine/README.md | |
| fi | |
| # StockPurchaser sample | |
| if [ -f "samples/StockPurchaser/StockPurchaserSampleApp/README.md" ]; then | |
| mkdir -p wiki/samples/StockPurchaser | |
| sed "$WIKI_LINK_PATTERN" samples/StockPurchaser/StockPurchaserSampleApp/README.md > wiki/samples/StockPurchaser/README.md | |
| fi | |
| - name: Push to wiki | |
| run: | | |
| cd wiki | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add -A | |
| if git diff --cached --quiet; then | |
| echo "No wiki changes to commit." | |
| else | |
| git commit -m "Sync docs to wiki from ${{ github.sha }}" | |
| git push | |
| fi |