Skip to content

Relocate docs into namesake repo #10

Relocate docs into namesake repo

Relocate docs into namesake repo #10

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
jobs:
deploy-web:
name: Web (${{ github.event_name == 'pull_request' && 'Preview' || 'Production' }})
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
pull-requests: write
statuses: write
outputs:
url: ${{ steps.deploy.outputs.deployment-url }}
steps:
- name: Checkout
uses: actions/checkout@v6.0.3
with:
fetch-depth: 0
persist-credentials: false
- name: Post building comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
env:
PR_SHA: ${{ github.event.pull_request.head.sha }}
RUN_NUMBER: ${{ github.run_number }}
RUN_ID: ${{ github.run_id }}
with:
script: |
const marker = '<!-- namesake-preview -->';
const sha = process.env.PR_SHA;
const shaShort = sha.slice(0, 7);
const runNumber = process.env.RUN_NUMBER;
const workflowUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${process.env.RUN_ID}`;
const commitUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${sha}`;
const body = [
marker,
`## Preview Deploys`,
'',
'| Package | Status | URL |',
'| :--- | :--- | :--- |',
'| Web | 🔄 Building... | — |',
'| Docs | 🔄 Building... | — |',
'',
`_Generated in workflow [#${runNumber}](${workflowUrl}) for commit [\`${shaShort}\`](${commitUrl})_`,
].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,
});
}
- 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: Build
run: pnpm --filter namesake-web build:only
- name: Deploy
id: deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
workingDirectory: web
command: deploy
githubToken: ${{ secrets.GITHUB_TOKEN }}
secrets: |
RESEND_API_KEY
env:
RESEND_API_KEY: ${{ secrets.RESEND_API_KEY }}
- name: Set commit status (success)
if: github.event_name == 'pull_request' && success()
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
SHA: ${{ github.event.pull_request.head.sha }}
DEPLOY_URL: ${{ steps.deploy.outputs.deployment-url }}
run: |
gh api "repos/$REPO/statuses/$SHA" \
-f state=success \
-f context="Preview / Web" \
-f description="Preview deployed" \
-f target_url="$DEPLOY_URL"
- name: Set commit status (failure)
if: github.event_name == 'pull_request' && failure()
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
SHA: ${{ github.event.pull_request.head.sha }}
run: |
gh api "repos/$REPO/statuses/$SHA" \
-f state=failure \
-f context="Preview / Web" \
-f description="Preview deployment failed"
deploy-docs:
name: Docs (${{ github.event_name == 'pull_request' && 'Preview' || 'Production' }})
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
statuses: write
outputs:
url: ${{ steps.deploy.outputs.deployment-url }}
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: Build
run: pnpm --filter namesake-docs build:only
- name: Deploy
id: deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
workingDirectory: docs
command: deploy
githubToken: ${{ secrets.GITHUB_TOKEN }}
- name: Set commit status (success)
if: github.event_name == 'pull_request' && success()
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
SHA: ${{ github.event.pull_request.head.sha }}
DEPLOY_URL: ${{ steps.deploy.outputs.deployment-url }}
run: |
gh api "repos/$REPO/statuses/$SHA" \
-f state=success \
-f context="Preview / Docs" \
-f description="Preview deployed" \
-f target_url="$DEPLOY_URL"
- name: Set commit status (failure)
if: github.event_name == 'pull_request' && failure()
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
SHA: ${{ github.event.pull_request.head.sha }}
run: |
gh api "repos/$REPO/statuses/$SHA" \
-f state=failure \
-f context="Preview / Docs" \
-f description="Preview deployment failed"
comment:
name: Preview Comment
needs: [deploy-web, deploy-docs]
if: always() && github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Update preview comment
uses: actions/github-script@v7
env:
WEB_URL: ${{ needs.deploy-web.outputs.url }}
WEB_RESULT: ${{ needs.deploy-web.result }}
DOCS_URL: ${{ needs.deploy-docs.outputs.url }}
DOCS_RESULT: ${{ needs.deploy-docs.result }}
PR_SHA: ${{ github.event.pull_request.head.sha }}
RUN_NUMBER: ${{ github.run_number }}
RUN_ID: ${{ github.run_id }}
with:
script: |
const marker = '<!-- namesake-preview -->';
const sha = process.env.PR_SHA;
const shaShort = sha.slice(0, 7);
const runNumber = process.env.RUN_NUMBER;
const workflowUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${process.env.RUN_ID}`;
const commitUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${sha}`;
const deployments = [
{ label: 'Web', result: process.env.WEB_RESULT, url: process.env.WEB_URL },
{ label: 'Docs', result: process.env.DOCS_RESULT, url: process.env.DOCS_URL },
];
const rows = deployments.map(d => {
if (d.result === 'success') return `| ${d.label} | ✅ Deployed | [${d.url}](${d.url}) |`;
return `| ${d.label} | ❌ Failed | — |`;
}).join('\n');
const body = [
marker,
`## Preview Deploys`,
'',
'| Package | Status | URL |',
'| :--- | :--- | :--- |',
rows,
'',
`_Generated in workflow [#${runNumber}](${workflowUrl}) for commit [\`${shaShort}\`](${commitUrl})_`,
].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,
});
}