-
-
Notifications
You must be signed in to change notification settings - Fork 2
78 lines (75 loc) · 2.96 KB
/
deploy.yml
File metadata and controls
78 lines (75 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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@v4
- 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 }}
- name: Set branch name
id: vars
run: |
ref=${{ github.event.pull_request.head.ref }}
if [ "$ref" == "refs/heads/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,
});