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
31 changes: 31 additions & 0 deletions .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Cleanup PR Preview

on:
pull_request:
types: [closed]

jobs:
cleanup:
runs-on: ubuntu-latest
# Skip if secrets are not available (e.g., forks)
if: ${{ !github.event.pull_request.head.repo.fork }}
permissions:
contents: read

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

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

- name: Remove PR preview
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_DEFAULT_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_DEFAULT_ACCOUNT_ID }}
run: bunx sst remove --stage pr-${{ github.event.pull_request.number }}
49 changes: 49 additions & 0 deletions .github/workflows/deploy-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Deploy Production

on:
workflow_dispatch:
inputs:
ref:
description: "Git ref to deploy (branch, tag, or SHA)"
required: false
default: "main"
reason:
description: "Reason for deployment (optional)"
required: false

jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.ref }}

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

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

- name: Build
run: bun run build

- name: Deploy to production
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_DEFAULT_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_DEFAULT_ACCOUNT_ID }}
run: bunx sst deploy --stage production

- name: Deployment summary
run: |
echo "## Production Deployment Complete" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Deployed ref:** ${{ github.event.inputs.ref }}" >> $GITHUB_STEP_SUMMARY
echo "**Reason:** ${{ github.event.inputs.reason || 'Not specified' }}" >> $GITHUB_STEP_SUMMARY
echo "**URL:** https://docs.t-req.io" >> $GITHUB_STEP_SUMMARY
87 changes: 87 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Deploy

on:
pull_request:
types: [opened, synchronize, reopened]
push:
branches:
- main

concurrency:
group: deploy-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true

jobs:
deploy:
runs-on: ubuntu-latest
# Skip if secrets are not available (e.g., forks)
if: ${{ github.event_name == 'push' || !github.event.pull_request.head.repo.fork }}
permissions:
contents: read
pull-requests: write

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

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

- name: Build
run: bun run build

- name: Deploy to PR preview
if: github.event_name == 'pull_request'
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_DEFAULT_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_DEFAULT_ACCOUNT_ID }}
run: bunx sst deploy --stage pr-${{ github.event.pull_request.number }}

- name: Deploy to dev
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_DEFAULT_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_DEFAULT_ACCOUNT_ID }}
run: bunx sst deploy --stage dev

- name: Comment PR with preview URL
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request.number;
const previewUrl = `https://docs-pr-${prNumber}.t-req.io`;
const body = `## 🚀 Preview Deployment\n\nYour changes have been deployed to:\n\n**📖 Docs:** ${previewUrl}\n\nThis preview will be automatically removed when the PR is closed.`;

// Find existing comment
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('Preview Deployment')
);

if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body
});
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ node_modules
# Turbo
.turbo

# SST
.sst

# Build Outputs
dist
out
Expand Down
Loading