Skip to content

feat: add release automation workflow #109

feat: add release automation workflow

feat: add release automation workflow #109

Workflow file for this run

name: PR Preview Deployment
on:
pull_request:
types: [opened, synchronize, reopened, closed]
# Permissions for GitHub Pages deployment
permissions:
contents: write
pages: write
id-token: write
pull-requests: write
jobs:
build-and-deploy:
name: Build and Deploy PR Preview
# Only build/deploy when PR is open (not closed)
if: github.event.action != 'closed'
runs-on: ubuntu-latest
steps:
- name: Checkout code
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 (compile check only, ignore test failures)
run: npm run build
continue-on-error: false
- name: Copy bundle to DITA demo
run: npm run copy-to-dita
- name: Build Storybook static site
run: npm run build-storybook
continue-on-error: true
- name: Prepare PR preview directory
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
mkdir -p _site/pr-${PR_NUMBER}
# Copy DITA demo to PR directory
if [ -d "dita-demo" ]; then
cp -r dita-demo/* _site/pr-${PR_NUMBER}/
echo "✅ DITA demo copied to _site/pr-${PR_NUMBER}/"
else
echo "⚠️ Warning: dita-demo not found, skipping DITA deployment"
fi
# Copy Storybook build to PR directory
if [ -d "storybook-static" ]; then
mkdir -p _site/pr-${PR_NUMBER}/storybook
cp -r storybook-static/* _site/pr-${PR_NUMBER}/storybook/
echo "✅ Storybook copied to _site/pr-${PR_NUMBER}/storybook/"
else
echo "⚠️ Warning: storybook-static not found, skipping Storybook deployment"
fi
- name: Checkout gh-pages branch (or create if missing)
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 PR preview to gh-pages
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
cd gh-pages-repo
# Configure git if not already done
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"
# Copy new PR preview
mkdir -p pr-${PR_NUMBER}
cp -r ../_site/pr-${PR_NUMBER}/* pr-${PR_NUMBER}/
# Add and commit
git add pr-${PR_NUMBER}
git commit -m "Deploy preview for PR #${PR_NUMBER}" || echo "No changes to commit"
# Push to gh-pages
git push origin gh-pages
cleanup:
name: Clean up PR Preview
# Only cleanup when PR is closed or merged
if: github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- name: Checkout gh-pages branch
uses: actions/checkout@v4
with:
ref: gh-pages
fetch-depth: 0
- name: Remove PR preview directory
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Remove PR directory if it exists
if [ -d "pr-${PR_NUMBER}" ]; then
git rm -rf pr-${PR_NUMBER}
git commit -m "Clean up preview for PR #${PR_NUMBER}"
git push origin gh-pages
echo "✅ Removed pr-${PR_NUMBER}/ from gh-pages"
else
echo "ℹ️ No preview directory found for PR #${PR_NUMBER}"
fi