Merge pull request #89 from DeepBlueCLtd/011-release-automation #129
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: Deploy to GitHub Pages | |
| on: | |
| push: | |
| branches: [main] | |
| # Permissions for pushing to gh-pages branch | |
| permissions: | |
| contents: write | |
| # Allow one concurrent deployment | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: true | |
| jobs: | |
| deploy: | |
| name: Build and Deploy Demo to gh-pages | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout main branch | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build bundle | |
| run: npm run build:dita | |
| - name: Create demo site directory | |
| run: | | |
| mkdir -p _site | |
| if [ -d "dita-demo" ]; then | |
| cp -r dita-demo/* _site/ | |
| echo "✅ DITA demo copied to _site/" | |
| else | |
| echo "❌ Error: dita-demo directory not found" | |
| exit 1 | |
| fi | |
| cp -r dist _site/ | |
| - name: Checkout gh-pages branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: gh-pages | |
| path: gh-pages-repo | |
| fetch-depth: 0 | |
| continue-on-error: true | |
| - name: Initialize gh-pages branch if needed | |
| run: | | |
| if [ ! -d "gh-pages-repo/.git" ]; then | |
| echo "📦 gh-pages branch doesn't exist, creating..." | |
| mkdir -p gh-pages-repo | |
| cd gh-pages-repo | |
| git init | |
| git checkout -b gh-pages | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| echo "# GitHub Pages" > README.md | |
| git add README.md | |
| git commit -m "Initialize gh-pages branch" | |
| git remote add origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git | |
| git push -u origin gh-pages | |
| echo "✅ gh-pages branch created" | |
| else | |
| echo "✅ gh-pages branch already exists" | |
| fi | |
| - name: Deploy demo to gh-pages main/ folder | |
| run: | | |
| cd gh-pages-repo | |
| # Configure git | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # Pull latest changes | |
| git pull origin gh-pages || echo "No remote changes" | |
| # Clean up: Remove all root-level files and non-folder items | |
| # Keep only main/ and pr-*/ directories | |
| find . -maxdepth 1 -type f -delete | |
| find . -maxdepth 1 -type d ! -name '.' ! -name '.git' ! -name 'main' ! -name 'pr-*' -exec rm -rf {} + | |
| # Remove old main/ folder and recreate | |
| rm -rf main/ | |
| mkdir -p main | |
| # Copy new demo files to main/ | |
| cp -r ../_site/* main/ | |
| # Add and commit | |
| git add -A | |
| git commit -m "Deploy demo from main branch to main/ (cleaned root)" || echo "No changes to commit" | |
| # Push to gh-pages | |
| git push origin gh-pages |