Skip to content

Fix translation worker route and deploy for capacitor-tutorial.com. #37

Fix translation worker route and deploy for capacitor-tutorial.com.

Fix translation worker route and deploy for capacitor-tutorial.com. #37

Workflow file for this run

name: Deploy
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
workflow_dispatch:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24.x
- uses: actions/checkout@v6
- uses: oven-sh/setup-bun@v2
- run: bun install
- run: bun run build
env:
BEARER_TOKEN: ${{ secrets.BEARER_TOKEN }}
ORAMA_CLOUD_API_KEY: ${{ secrets.ORAMA_CLOUD_API_KEY }}
ORAMA_CLOUD_ENDPOINT: ${{ secrets.ORAMA_CLOUD_ENDPOINT }}
CLOUDFLARE_TURNSTILE_SITE_KEY: ${{ secrets.CLOUDFLARE_TURNSTILE_SITE_KEY }}
PUBLIC_TRANSLATION_API_HOST: https://capacitor-tutorial.com/
- name: Set branch name
id: vars
run: |
ref="${{ github.event.pull_request.head.ref || github.ref_name }}"
if [ "$ref" = "refs/heads/main" ] || [ "$ref" = "main" ]; then
echo "branch=main" >> $GITHUB_OUTPUT
else
echo "branch=${ref}" >> $GITHUB_OUTPUT
fi
- name: Ensure Cloudflare Pages project exists
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: |
set -e
project_name="capacitor-tutorial"
api="https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/pages/projects/${project_name}"
status=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" "$api")
if [ "$status" = "404" ]; then
echo "Project does not exist. Creating..."
curl -s -X POST "https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/pages/projects" \
-H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \
-H "Content-Type: application/json" \
--data "{\"name\":\"${project_name}\",\"production_branch\":\"main\"}"
else
echo "Project exists or another error occurred (status: $status)."
fi
- run: bunx wrangler@latest pages deploy dist --project-name capacitor-tutorial --branch ${{ steps.vars.outputs.branch }}
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- name: Comment deployed link on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const branch = '${{ steps.vars.outputs.branch }}';
const url = `https://${branch}.capacitor-tutorial.pages.dev/`;
const body = `🚀 Preview deployed: [${url}](${url})`;
await github.rest.issues.createComment({
body,
repo: context.repo.repo,
owner: context.repo.owner,
issue_number: context.issue.number,
});
deploy_translation_worker:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 24.x
- uses: oven-sh/setup-bun@v2
- run: bun install
- name: Deploy CF Worker Translation
run: bun run deploy:cloudflare:translation:prod
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}