Skip to content

Relocate docs into namesake repo #4

Relocate docs into namesake repo

Relocate docs into namesake repo #4

Workflow file for this run

name: Deploy
on:
push:
branches: [main]
paths:
- "web/**"
- "docs/**"
- "pnpm-lock.yaml"
pull_request:
branches: [main]
paths:
- "web/**"
- "docs/**"
- "pnpm-lock.yaml"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
deployments: write
pull-requests: write
statuses: write
jobs:
changes:
name: Detect Changes
runs-on: ubuntu-latest
outputs:
web: ${{ steps.filter.outputs.web }}
docs: ${{ steps.filter.outputs.docs }}
steps:
- name: Checkout
uses: actions/checkout@v6.0.3
with:
persist-credentials: false
- name: Detect changed packages
uses: dorny/paths-filter@v3
id: filter
with:
filters: |
web:
- "web/**"
- "pnpm-lock.yaml"
docs:
- "docs/**"
- "pnpm-lock.yaml"
deploy-web:
name: Web (${{ github.event_name == 'pull_request' && 'Preview' || 'Production' }})
needs: changes
if: needs.changes.outputs.web == 'true'
runs-on: ubuntu-latest
outputs:
url: ${{ steps.preview.outputs.deployment-url }}
duration: ${{ steps.duration.outputs.value }}
steps:
- name: Checkout
uses: actions/checkout@v6.0.3
with:
fetch-depth: 0
persist-credentials: false
- name: Setup PNPM
uses: pnpm/action-setup@v6.0.8
- name: Setup Node
uses: actions/setup-node@v6
with:
node-version: "24.x"
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Start timer
id: timer
run: echo "start=$(date +%s)" >> $GITHUB_OUTPUT
- name: Build
run: pnpm --filter namesake-web build:only
- name: Deploy (Production)
if: github.event_name == 'push'
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
workingDirectory: web
command: deploy
secrets: |
RESEND_API_KEY
env:
RESEND_API_KEY: ${{ secrets.RESEND_API_KEY }}
- name: Deploy (Preview)
if: github.event_name == 'pull_request'
id: preview
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
workingDirectory: web
command: deploy --env preview
githubToken: ${{ secrets.GITHUB_TOKEN }}
secrets: |
RESEND_API_KEY
env:
RESEND_API_KEY: ${{ secrets.RESEND_API_KEY }}
- name: Calculate duration
id: duration
if: github.event_name == 'pull_request'
run: echo "value=$(( $(date +%s) - ${{ steps.timer.outputs.start }} ))s" >> $GITHUB_OUTPUT
- name: Set commit status (success)
if: github.event_name == 'pull_request' && success()
run: |
gh api "repos/${{ github.repository }}/statuses/${{ github.event.pull_request.head.sha }}" \
-f state=success \
-f context="Preview / Web" \
-f description="Preview deployed in ${{ steps.duration.outputs.value }}" \
-f target_url="${{ steps.preview.outputs.deployment-url }}"
env:
GH_TOKEN: ${{ github.token }}
- name: Set commit status (failure)
if: github.event_name == 'pull_request' && failure()
run: |
gh api "repos/${{ github.repository }}/statuses/${{ github.event.pull_request.head.sha }}" \
-f state=failure \
-f context="Preview / Web" \
-f description="Preview deployment failed"
env:
GH_TOKEN: ${{ github.token }}
deploy-docs:
name: Docs (${{ github.event_name == 'pull_request' && 'Preview' || 'Production' }})
needs: changes
if: needs.changes.outputs.docs == 'true'
runs-on: ubuntu-latest
outputs:
url: ${{ steps.preview.outputs.deployment-url }}
duration: ${{ steps.duration.outputs.value }}
steps:
- name: Checkout
uses: actions/checkout@v6.0.3
with:
persist-credentials: false
- name: Setup PNPM
uses: pnpm/action-setup@v6.0.8
- name: Setup Node
uses: actions/setup-node@v6
with:
node-version: "24.x"
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Start timer
id: timer
run: echo "start=$(date +%s)" >> $GITHUB_OUTPUT
- name: Build
run: pnpm --filter namesake-docs build:only
- name: Deploy (Production)
if: github.event_name == 'push'
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
workingDirectory: docs
command: deploy
- name: Deploy (Preview)
if: github.event_name == 'pull_request'
id: preview
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
workingDirectory: docs
command: deploy --env preview
githubToken: ${{ secrets.GITHUB_TOKEN }}
- name: Calculate duration
id: duration
if: github.event_name == 'pull_request'
run: echo "value=$(( $(date +%s) - ${{ steps.timer.outputs.start }} ))s" >> $GITHUB_OUTPUT
- name: Set commit status (success)
if: github.event_name == 'pull_request' && success()
run: |
gh api "repos/${{ github.repository }}/statuses/${{ github.event.pull_request.head.sha }}" \
-f state=success \
-f context="Preview / Docs" \
-f description="Preview deployed in ${{ steps.duration.outputs.value }}" \
-f target_url="${{ steps.preview.outputs.deployment-url }}"
env:
GH_TOKEN: ${{ github.token }}
- name: Set commit status (failure)
if: github.event_name == 'pull_request' && failure()
run: |
gh api "repos/${{ github.repository }}/statuses/${{ github.event.pull_request.head.sha }}" \
-f state=failure \
-f context="Preview / Docs" \
-f description="Preview deployment failed"
env:
GH_TOKEN: ${{ github.token }}
comment:
name: Preview Comment
needs: [deploy-web, deploy-docs]
if: |
always() &&
github.event_name == 'pull_request' &&
(needs.deploy-web.result == 'success' || needs.deploy-docs.result == 'success')
runs-on: ubuntu-latest
steps:
- name: Post or update preview comment
uses: actions/github-script@v7
env:
WEB_URL: ${{ needs.deploy-web.outputs.url }}
WEB_DURATION: ${{ needs.deploy-web.outputs.duration }}
DOCS_URL: ${{ needs.deploy-docs.outputs.url }}
DOCS_DURATION: ${{ needs.deploy-docs.outputs.duration }}
PR_SHA: ${{ github.event.pull_request.head.sha }}
ACTOR: ${{ github.actor }}
with:
script: |
const marker = '<!-- namesake-preview -->';
const sha = process.env.PR_SHA;
const shaShort = sha.slice(0, 7);
const actor = process.env.ACTOR;
const commitUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/pull/${context.issue.number}/commits/${sha}`;
const deployments = [
{ label: 'Web', url: process.env.WEB_URL, duration: process.env.WEB_DURATION },
{ label: 'Docs', url: process.env.DOCS_URL, duration: process.env.DOCS_DURATION },
].filter(d => d.url);
const rows = deployments
.map(d => `| ${d.label} | ${d.url} | ${d.duration} |`)
.join('\n');
const body = [
marker,
`### Previews`,
`**@${actor}** · [\`${shaShort}\`](${commitUrl})`,
'',
'| Package | URL | Duration |',
'| --- | --- | --- |',
rows,
].join('\n');
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}