Skip to content

Fix a formatting issue #133

Fix a formatting issue

Fix a formatting issue #133

Workflow file for this run

name: CI/CD
on:
pull_request:
branches: [main]
push:
branches: [main]
workflow_dispatch:
permissions:
pull-requests: write
contents: read
jobs:
ci:
name: CI
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: latest
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ env.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: Check
run: pnpm check
- name: Type check
run: pnpm typecheck
- name: Knip
run: pnpm knip
- name: Test
run: pnpm test
deploy-preview:
name: Deploy Preview
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
needs: ci
environment:
name: Preview
url: ${{ steps.deploy.outputs.deployment-url }}
steps:
- name: Find Existing Comment
id: find-comment
uses: actions/github-script@v7
with:
script: |
const comments = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const botComment = comments.data.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('🚀 Preview Deployment')
);
if (botComment) {
console.log(`Found existing comment: ${botComment.id}`);
return botComment.id;
}
return null;
- name: Create/Update Loading Comment
uses: actions/github-script@v7
with:
script: |
const commentId = '${{ steps.find-comment.outputs.result }}';
const commentBody = `## 🚀 Preview Deployment
**Status:** ⏳ Loading...
**Commit:** \`${{ github.event.pull_request.head.sha }}\`
_Deployment in progress..._`;
if (commentId && commentId !== 'null') {
await github.rest.issues.updateComment({
comment_id: commentId,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
console.log(`Updated existing comment to loading: ${commentId}`);
} else {
const response = await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
console.log(`Created loading comment: ${response.data.id}`);
}
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: latest
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ env.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
run: pnpm build
- name: Deploy Preview
id: deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
accountId: ${{ secrets.CF_ACCOUNT_ID }}
command: versions upload
- name: Update Comment with Success
uses: actions/github-script@v7
with:
script: |
const deploymentUrl = '${{ steps.deploy.outputs.deployment-url }}';
const commentId = '${{ steps.find-comment.outputs.result }}';
const commentBody = `## 🚀 Preview Deployment
**Status:** ✅ Ready!
**Preview URL:** [Open Preview](${deploymentUrl})
**Commit:** \`${{ github.event.pull_request.head.sha }}\`
_Built and deployed successfully_`;
if (commentId && commentId !== 'null') {
await github.rest.issues.updateComment({
comment_id: commentId,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
console.log(`Updated existing comment to success: ${commentId}`);
} else {
// Find the loading comment we just created
const comments = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const loadingComment = comments.data.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('⏳ Loading...')
);
if (loadingComment) {
await github.rest.issues.updateComment({
comment_id: loadingComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
console.log(`Updated loading comment to success: ${loadingComment.id}`);
} else {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
console.log('Created new success comment');
}
}
deploy-production:
name: Deploy Production
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
needs: ci
environment:
name: Production
url: https://trytanstackdb.com
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: latest
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ env.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: Deploy Production
run: pnpm deploy.prod
env:
CF_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
CF_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }}