Skip to content

build(deps): bump uuid from 11.1.0 to 13.0.0 #3

build(deps): bump uuid from 11.1.0 to 13.0.0

build(deps): bump uuid from 11.1.0 to 13.0.0 #3

Workflow file for this run

name: Deploy to Cloudflare
on:
push:
branches: [main, stable]
pull_request:
branches: [main, stable]
permissions:
contents: read
pull-requests: write
deployments: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Find or Create deployment comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
id: comment
with:
script: |
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('### Cloudflare Deployment')
);
const now = new Date();
const sriLankaTime = new Intl.DateTimeFormat('en-US', {
timeZone: 'Asia/Colombo',
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false
}).format(now);
const branchName = context.payload.pull_request
? context.payload.pull_request.head.ref
: context.ref.replace('refs/heads/', '');
const body = `### Cloudflare Deployment
**Status:** 🔄 Deploying...
**Commit:** ${context.sha.substring(0, 7)}
**Branch:** ${branchName}
Please wait while your application is being deployed to Cloudflare.
---
Last updated: ${sriLankaTime} +05:30 GMT`;
let commentId;
if (botComment) {
const { data: updatedComment } = await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
commentId = updatedComment.id;
} else {
const { data: newComment } = await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
commentId = newComment.id;
}
return commentId;
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.1.38
- name: Setup .env.local for CI
run: |
cat << 'EOF' > .env.local
${{ secrets.ENV_SECRET }}
EOF
- name: Install dependencies
run: bun install
- name: Run linter
run: bun run lint
- name: Run type check
run: bun run type-check
- name: Build application
run: bun run build
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
- name: Format branch name for alias
id: format-branch
run: |
BRANCH_NAME="${{ github.head_ref || github.ref_name }}"
FORMATTED_BRANCH=$(echo "$BRANCH_NAME" | tr '[:upper:]' '[:lower:]')
FORMATTED_BRANCH=$(echo "$FORMATTED_BRANCH" | sed 's/[^a-z0-9-]/-/g')
FORMATTED_BRANCH=$(echo "$FORMATTED_BRANCH" | sed 's/-\+/-/g')
FORMATTED_BRANCH=$(echo "$FORMATTED_BRANCH" | sed 's/^-\+\|-\+$//g')
if [[ ! "$FORMATTED_BRANCH" =~ ^[a-z] ]]; then
FORMATTED_BRANCH="br-$FORMATTED_BRANCH"
fi
FORMATTED_BRANCH=$(echo "$FORMATTED_BRANCH" | cut -c1-32)
FORMATTED_BRANCH=$(echo "$FORMATTED_BRANCH" | sed 's/-$//g')
echo "FORMATTED_BRANCH=$FORMATTED_BRANCH" >> $GITHUB_OUTPUT
echo "Original branch: $BRANCH_NAME"
echo "Formatted branch: $FORMATTED_BRANCH"
- name: Deploy to Cloudflare (Preview)
if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref_name != 'stable')
id: deploy
shell: bash
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
run: |
set -euo pipefail
FORMATTED_BRANCH="${{ steps.format-branch.outputs.FORMATTED_BRANCH }}"
echo "Deploying preview with dev database for branch alias: $FORMATTED_BRANCH"
UPLOAD_OUT="$(bun run wrangler versions upload --config wrangler.jsonc --preview-alias "$FORMATTED_BRANCH" 2>&1 | tee /dev/stderr)"
VERSION_ID="$(printf '%s\n' "$UPLOAD_OUT" | grep -Eo '[0-9a-fA-F-]{36}' | head -n1 || true)"
if [[ -z "${VERSION_ID:-}" ]]; then
echo "❌ Failed to extract Version ID from upload output." >&2
exit 1
fi
echo "Uploaded Version ID: $VERSION_ID"
PREVIEW_URL="$(printf '%s\n' "$UPLOAD_OUT" | grep -o 'https://[a-zA-Z0-9.-]*\.workers\.dev' | head -n1 || true)"
if [[ -z "${PREVIEW_URL:-}" ]]; then
bun run wrangler versions view "$VERSION_ID" --json > deployment-output.json
PREVIEW_URL="$(cat deployment-output.json | jq -r '.preview_url // empty' 2>/dev/null || true)"
fi
if [[ -z "${PREVIEW_URL:-}" ]]; then
SHORT_VERSION="${VERSION_ID%%-*}"
PREVIEW_URL="https://${SHORT_VERSION}-b3-opennext-dev.workers.dev"
fi
echo "Preview URL: $PREVIEW_URL"
if [[ "${{ github.ref_name }}" != "stable" ]] && [[ ! -f deployment-output.json ]]; then
bun run wrangler versions view "$VERSION_ID" --json > deployment-output.json
fi
if [[ -f deployment-output.json ]]; then
cat deployment-output.json
fi
{
echo "PREVIEW_URL=$PREVIEW_URL"
if [[ "${{ github.ref_name }}" != "stable" ]]; then
echo "VERSION_ID=$VERSION_ID"
if [[ -f deployment-output.json ]]; then
echo "DEPLOYMENT_OUTPUT<<EOF"
cat deployment-output.json
echo "EOF"
fi
fi
} >> "$GITHUB_OUTPUT"
- name: Deploy to Cloudflare (Production)
id: deploy-prod
shell: bash
if: github.event_name == 'push' && github.ref_name == 'stable'
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
run: |
FORMATTED_BRANCH="${{ steps.format-branch.outputs.FORMATTED_BRANCH }}"
echo "Deploying to production with production database"
UPLOAD_OUT="$(bun run wrangler deploy --config wrangler.production.jsonc 2>&1 | tee /dev/stderr)"
VERSION_ID="$(printf '%s\n' "$UPLOAD_OUT" | grep -Eo '[0-9a-fA-F-]{36}' | head -n1 || true)"
if [[ -z "${VERSION_ID:-}" ]]; then
echo "❌ Failed to extract Version ID from upload output." >&2
exit 1
fi
echo "Uploaded Version ID: $VERSION_ID"
- name: Update comment on success
if: success() && github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const commentId = '${{ steps.comment.outputs.result }}';
const commitUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${context.sha}`;
const branchName = context.payload.pull_request
? context.payload.pull_request.head.ref
: context.ref.replace('refs/heads/', '');
const branchUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/tree/${branchName}`;
const now = new Date();
const sriLankaTime = new Intl.DateTimeFormat('en-US', {
timeZone: 'Asia/Colombo',
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false
}).format(now);
const formattedBranch = '${{ steps.format-branch.outputs.FORMATTED_BRANCH }}';
const deploymentUrl = '${{ steps.deploy.outputs.PREVIEW_URL }}';
let deploymentSubdomain = '';
const match = deploymentUrl.match(/^https:\/\/[^-]+-(.+)$/);
if (match && match[1]) {
deploymentSubdomain = match[1];
}
const branchCfUrl = `https://${formattedBranch}-${deploymentSubdomain}`;
let urlSection = '';
if (deploymentUrl) {
urlSection = `
**🔗 Preview URL:**
- Commit URL: [${deploymentUrl}](${deploymentUrl})
- Branch URL: [${branchCfUrl}](${branchCfUrl})`;
}
const body = `### Cloudflare Deployment
**Status:** ✅ Successfully deployed!
**Commit:** [${context.sha.substring(0, 7)}](${commitUrl})
**Branch:** [${branchName}](${branchUrl})
${urlSection}
Your application has been successfully deployed to Cloudflare.
---
Last updated: ${sriLankaTime} +05:30 GMT`;
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: commentId,
body: body
});
- name: Update comment on failure
if: failure() && github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const commentId = '${{ steps.comment.outputs.result }}';
const commitUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${context.sha}`;
const branchName = context.payload.pull_request
? context.payload.pull_request.head.ref
: context.ref.replace('refs/heads/', '');
const branchUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/tree/${branchName}`;
const now = new Date();
const sriLankaTime = new Intl.DateTimeFormat('en-US', {
timeZone: 'Asia/Colombo',
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false
}).format(now);
const body = `### Cloudflare Deployment
**Status:** ❌ Deployment failed
**Commit:** [${context.sha.substring(0, 7)}](${commitUrl})
**Branch:** [${branchName}](${branchUrl})
The deployment to Cloudflare failed. Please check the [workflow logs](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}) for more details.
---
Last updated: ${sriLankaTime} +05:30 GMT`;
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: commentId,
body: body
});