Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
211 changes: 211 additions & 0 deletions .github/workflows/deploy-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
name: Deploy to GitHub Pages

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

# Allow one concurrent deployment
concurrency:
group: pages-${{ github.ref }}
cancel-in-progress: true

# Sets permissions of the GITHUB_TOKEN
permissions:
contents: read
pages: write
id-token: write
pull-requests: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for git-based features

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT

- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build site
run: |
# Set base URL for PR previews
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "Building PR preview..."
export BASE_URL="/docs-ng/pr-${{ github.event.pull_request.number }}/"
else
echo "Building production site..."
export BASE_URL="/docs-ng/"
fi
pnpm run docs:build
env:
NODE_ENV: production

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/.vitepress/dist

deploy-production:
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

- name: Comment on related PRs
uses: actions/github-script@v7
with:
script: |
const { data: prs } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
base: 'main'
});

for (const pr of prs) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
body: `✅ Production deployment updated!\n\nView at: ${{ steps.deployment.outputs.page_url }}`
});
}

deploy-preview:
needs: build
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: github-pages
path: ./preview

- name: Extract artifact
run: |
cd preview
tar -xf artifact.tar
rm artifact.tar

- name: Deploy PR Preview
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./preview
destination_dir: pr-${{ github.event.pull_request.number }}
keep_files: false

- name: Comment PR
uses: actions/github-script@v7
with:
script: |
const prNumber = context.issue.number;
const previewUrl = `https://${{ github.repository_owner }}.github.io/docs-ng/pr-${prNumber}/`;

// Find existing preview comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});

const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('📝 Documentation Preview')
);

const commentBody = `## 📝 Documentation Preview

Preview deployment is ready! 🚀

**Preview URL:** ${previewUrl}

The preview will be updated automatically with each new commit.

---
<sub>Built with commit ${context.sha.substring(0, 7)}</sub>`;

if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: commentBody
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: commentBody
});
}

cleanup-preview:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- name: Checkout gh-pages branch
uses: actions/checkout@v4
with:
ref: gh-pages

- name: Remove preview directory
run: |
rm -rf pr-${{ github.event.pull_request.number }}
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "chore: cleanup preview for PR #${{ github.event.pull_request.number }}" || echo "No changes to commit"
git push

- name: Comment cleanup
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: '🧹 Preview deployment cleaned up.'
});
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ See `scripts/tests/README.md` for more details.

See `scripts/README.md` for documentation aggregation details.

## GitHub Pages Deployment

The documentation site is automatically deployed to GitHub Pages:

- **Production**: Automatically deployed when changes are merged to `main`
- URL: https://gardenlinux.github.io/docs-ng/
- **PR Previews**: Each pull request gets its own preview deployment
- URL: https://gardenlinux.github.io/docs-ng/pr-{PR_NUMBER}/
- Automatically updated with each commit
- Cleaned up when PR is closed

The workflow is configured in `.github/workflows/deploy-pages.yml`.

For detailed information about the deployment system, see the [GitHub Pages Deployment Guide](docs/contributing/github-pages-deployment.md).

## Commands

Run `make help` for all available commands.
Expand Down
Loading