mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 23:29:02 +02:00
feat(ci): set up deployment workflow for website
This commit is contained in:
parent
c3250cfd72
commit
6998a3593e
94
.github/actions/deploy-to-cloudflare-pages/action.yml
vendored
Normal file
94
.github/actions/deploy-to-cloudflare-pages/action.yml
vendored
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
name: "Deploy to Cloudflare Pages"
|
||||||
|
description: "Deploys to Cloudflare Pages on either a temporary branch with preview comment, or on the production version if on the main branch."
|
||||||
|
inputs:
|
||||||
|
project_name:
|
||||||
|
description: "CloudFlare Pages project name"
|
||||||
|
comment_body:
|
||||||
|
description: "The message to display when deployment is ready"
|
||||||
|
default: "Deployment is ready."
|
||||||
|
required: false
|
||||||
|
production_url:
|
||||||
|
description: "The URL to mention as the production URL."
|
||||||
|
required: true
|
||||||
|
deploy_dir:
|
||||||
|
description: "The directory from which to deploy."
|
||||||
|
required: true
|
||||||
|
runs:
|
||||||
|
using: composite
|
||||||
|
steps:
|
||||||
|
# Install wrangler globally to avoid workspace issues
|
||||||
|
- name: Install Wrangler
|
||||||
|
shell: bash
|
||||||
|
run: npm install -g wrangler
|
||||||
|
|
||||||
|
# Deploy using Wrangler (use pre-installed wrangler)
|
||||||
|
- name: Deploy to Cloudflare Pages
|
||||||
|
id: deploy
|
||||||
|
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
|
||||||
|
uses: cloudflare/wrangler-action@v3
|
||||||
|
with:
|
||||||
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
|
command: pages deploy ${{ inputs.deploy_dir }} --project-name=${{ inputs.project_name}} --branch=${{ github.ref_name }}
|
||||||
|
wranglerVersion: '' # Use pre-installed version
|
||||||
|
|
||||||
|
# Deploy preview for PRs
|
||||||
|
- name: Deploy Preview to Cloudflare Pages
|
||||||
|
id: preview-deployment
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
|
uses: cloudflare/wrangler-action@v3
|
||||||
|
with:
|
||||||
|
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||||
|
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||||
|
command: pages deploy ${{ inputs.deploy_dir }} --project-name=${{ inputs.project_name}} --branch=pr-${{ github.event.pull_request.number }}
|
||||||
|
wranglerVersion: '' # Use pre-installed version
|
||||||
|
|
||||||
|
# Post deployment URL as PR comment
|
||||||
|
- name: Comment PR with Preview URL
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
|
uses: actions/github-script@v8
|
||||||
|
env:
|
||||||
|
COMMENT_BODY: ${{ inputs.comment_body }}
|
||||||
|
PRODUCTION_URL: ${{ inputs.production_url }}
|
||||||
|
PROJECT_NAME: ${{ inputs.project_name }}
|
||||||
|
with:
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
script: |
|
||||||
|
const prNumber = context.issue.number;
|
||||||
|
// Construct preview URL based on Cloudflare Pages pattern
|
||||||
|
const projectName = process.env.PROJECT_NAME;
|
||||||
|
const previewUrl = `https://pr-${prNumber}.${projectName}.pages.dev`;
|
||||||
|
|
||||||
|
// Check if we already commented
|
||||||
|
const comments = await github.rest.issues.listComments({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
issue_number: prNumber
|
||||||
|
});
|
||||||
|
|
||||||
|
const customMessage = process.env.COMMENT_BODY;
|
||||||
|
const botComment = comments.data.find(comment =>
|
||||||
|
comment.user.type === 'Bot' &&
|
||||||
|
comment.body.includes(customMessage)
|
||||||
|
);
|
||||||
|
|
||||||
|
const mainUrl = process.env.PRODUCTION_URL;
|
||||||
|
const commentBody = `${customMessage}!\n\n🔗 Preview URL: ${previewUrl}\n📖 Production URL: ${mainUrl}\n\n✅ All checks passed\n\n_This preview will be updated automatically with new commits._`;
|
||||||
|
|
||||||
|
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({
|
||||||
|
issue_number: prNumber,
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
body: commentBody
|
||||||
|
});
|
||||||
|
}
|
99
.github/workflows/deploy-docs.yml
vendored
99
.github/workflows/deploy-docs.yml
vendored
@ -16,10 +16,10 @@ on:
|
|||||||
- 'requirements-docs.txt'
|
- 'requirements-docs.txt'
|
||||||
- '.github/workflows/deploy-docs.yml'
|
- '.github/workflows/deploy-docs.yml'
|
||||||
- 'scripts/fix-mkdocs-structure.ts'
|
- 'scripts/fix-mkdocs-structure.ts'
|
||||||
|
|
||||||
# Allow manual triggering from Actions tab
|
# Allow manual triggering from Actions tab
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
# Run on pull requests for preview deployments
|
# Run on pull requests for preview deployments
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
@ -38,55 +38,55 @@ jobs:
|
|||||||
name: Build and Deploy MkDocs
|
name: Build and Deploy MkDocs
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 10
|
timeout-minutes: 10
|
||||||
|
|
||||||
# Required permissions for deployment
|
# Required permissions for deployment
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
deployments: write
|
deployments: write
|
||||||
pull-requests: write # For PR preview comments
|
pull-requests: write # For PR preview comments
|
||||||
id-token: write # For OIDC authentication (if needed)
|
id-token: write # For OIDC authentication (if needed)
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Repository
|
- name: Checkout Repository
|
||||||
uses: actions/checkout@v5
|
uses: actions/checkout@v5
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Fetch all history for git info and mkdocs-git-revision-date plugin
|
fetch-depth: 0 # Fetch all history for git info and mkdocs-git-revision-date plugin
|
||||||
|
|
||||||
- name: Setup Python
|
- name: Setup Python
|
||||||
uses: actions/setup-python@v6
|
uses: actions/setup-python@v6
|
||||||
with:
|
with:
|
||||||
python-version: '3.13'
|
python-version: '3.13'
|
||||||
cache: 'pip'
|
cache: 'pip'
|
||||||
cache-dependency-path: 'requirements-docs.txt'
|
cache-dependency-path: 'requirements-docs.txt'
|
||||||
|
|
||||||
- name: Install MkDocs and Dependencies
|
- name: Install MkDocs and Dependencies
|
||||||
run: |
|
run: |
|
||||||
pip install --upgrade pip
|
pip install --upgrade pip
|
||||||
pip install -r requirements-docs.txt
|
pip install -r requirements-docs.txt
|
||||||
env:
|
env:
|
||||||
PIP_DISABLE_PIP_VERSION_CHECK: 1
|
PIP_DISABLE_PIP_VERSION_CHECK: 1
|
||||||
|
|
||||||
# Setup pnpm before fixing docs structure
|
# Setup pnpm before fixing docs structure
|
||||||
- name: Setup pnpm
|
- name: Setup pnpm
|
||||||
uses: pnpm/action-setup@v4
|
uses: pnpm/action-setup@v4
|
||||||
|
|
||||||
# Setup Node.js with pnpm
|
# Setup Node.js with pnpm
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v5
|
uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: '22'
|
node-version: '22'
|
||||||
cache: 'pnpm'
|
cache: 'pnpm'
|
||||||
|
|
||||||
# Install Node.js dependencies for the TypeScript script
|
# Install Node.js dependencies for the TypeScript script
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: |
|
run: |
|
||||||
pnpm install --frozen-lockfile
|
pnpm install --frozen-lockfile
|
||||||
|
|
||||||
- name: Fix Documentation Structure
|
- name: Fix Documentation Structure
|
||||||
run: |
|
run: |
|
||||||
# Fix duplicate navigation entries by moving overview pages to index.md
|
# Fix duplicate navigation entries by moving overview pages to index.md
|
||||||
pnpm run chore:fix-mkdocs-structure
|
pnpm run chore:fix-mkdocs-structure
|
||||||
|
|
||||||
- name: Build MkDocs Site
|
- name: Build MkDocs Site
|
||||||
run: |
|
run: |
|
||||||
# Build with strict mode but allow expected warnings
|
# Build with strict mode but allow expected warnings
|
||||||
@ -115,74 +115,11 @@ jobs:
|
|||||||
test -f site/sitemap.xml || (echo "ERROR: site/sitemap.xml not found" && exit 1)
|
test -f site/sitemap.xml || (echo "ERROR: site/sitemap.xml not found" && exit 1)
|
||||||
test -d site/assets || (echo "ERROR: site/assets directory not found" && exit 1)
|
test -d site/assets || (echo "ERROR: site/assets directory not found" && exit 1)
|
||||||
echo "✅ Site validation passed"
|
echo "✅ Site validation passed"
|
||||||
|
|
||||||
# Install wrangler globally to avoid workspace issues
|
- name: Deploy
|
||||||
- name: Install Wrangler
|
uses: ./.github/actions/deploy-to-cloudflare-pages
|
||||||
run: |
|
|
||||||
npm install -g wrangler
|
|
||||||
|
|
||||||
# Deploy using Wrangler (use pre-installed wrangler)
|
|
||||||
- name: Deploy to Cloudflare Pages
|
|
||||||
id: deploy
|
|
||||||
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
|
|
||||||
uses: cloudflare/wrangler-action@v3
|
|
||||||
with:
|
with:
|
||||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
project_name: "trilium-docs"
|
||||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
comment_body: "📚 Documentation preview is ready"
|
||||||
command: pages deploy site --project-name=trilium-docs --branch=${{ github.ref_name }}
|
production_url: "https://docs.triliumnotes.org"
|
||||||
wranglerVersion: '' # Use pre-installed version
|
deploy_dir: "site"
|
||||||
|
|
||||||
# Deploy preview for PRs
|
|
||||||
- name: Deploy Preview to Cloudflare Pages
|
|
||||||
id: preview-deployment
|
|
||||||
if: github.event_name == 'pull_request'
|
|
||||||
uses: cloudflare/wrangler-action@v3
|
|
||||||
with:
|
|
||||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
|
||||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
|
||||||
command: pages deploy site --project-name=trilium-docs --branch=pr-${{ github.event.pull_request.number }}
|
|
||||||
wranglerVersion: '' # Use pre-installed version
|
|
||||||
|
|
||||||
# Post deployment URL as PR comment
|
|
||||||
- name: Comment PR with Preview URL
|
|
||||||
if: github.event_name == 'pull_request'
|
|
||||||
uses: actions/github-script@v8
|
|
||||||
with:
|
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
script: |
|
|
||||||
const prNumber = context.issue.number;
|
|
||||||
// Construct preview URL based on Cloudflare Pages pattern
|
|
||||||
const previewUrl = `https://pr-${prNumber}.trilium-docs.pages.dev`;
|
|
||||||
const mainUrl = 'https://docs.triliumnotes.org';
|
|
||||||
|
|
||||||
// Check if we already commented
|
|
||||||
const comments = await github.rest.issues.listComments({
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
issue_number: prNumber
|
|
||||||
});
|
|
||||||
|
|
||||||
const botComment = comments.data.find(comment =>
|
|
||||||
comment.user.type === 'Bot' &&
|
|
||||||
comment.body.includes('Documentation preview is ready')
|
|
||||||
);
|
|
||||||
|
|
||||||
const commentBody = `📚 Documentation preview is ready!\n\n🔗 Preview URL: ${previewUrl}\n📖 Production URL: ${mainUrl}\n\n✅ All checks passed\n\n_This preview will be updated automatically with new commits._`;
|
|
||||||
|
|
||||||
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({
|
|
||||||
issue_number: prNumber,
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
body: commentBody
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
38
.github/workflows/website.yml
vendored
Normal file
38
.github/workflows/website.yml
vendored
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
name: Deploy website
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths:
|
||||||
|
- "apps/website/**"
|
||||||
|
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- "apps/website/**"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
deployments: write
|
||||||
|
pull-requests: write # For PR preview comments
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: pnpm/action-setup@v4
|
||||||
|
|
||||||
|
- name: Build the website
|
||||||
|
run: |
|
||||||
|
pnpm i
|
||||||
|
pnpm website:build
|
||||||
|
|
||||||
|
- name: Deploy
|
||||||
|
uses: ./.github/actions/deploy-to-cloudflare-pages
|
||||||
|
with:
|
||||||
|
project_name: "trilium-homepage"
|
||||||
|
comment_body: "📚 Website preview is ready"
|
||||||
|
production_url: "https://triliumnotes.org"
|
||||||
|
deploy_dir: "apps/website/dist"
|
@ -17,6 +17,7 @@
|
|||||||
"desktop:start": "pnpm run --filter desktop dev",
|
"desktop:start": "pnpm run --filter desktop dev",
|
||||||
"desktop:build": "pnpm run --filter desktop build",
|
"desktop:build": "pnpm run --filter desktop build",
|
||||||
"desktop:start-prod": "pnpm run --filter desktop start-prod",
|
"desktop:start-prod": "pnpm run --filter desktop start-prod",
|
||||||
|
"website:build": "pnpm run --filter website build",
|
||||||
"electron:build": "pnpm desktop:build",
|
"electron:build": "pnpm desktop:build",
|
||||||
"electron:start": "pnpm desktop:start",
|
"electron:start": "pnpm desktop:start",
|
||||||
"electron:start-prod": "pnpm desktop:start-prod",
|
"electron:start-prod": "pnpm desktop:start-prod",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user