-
Notifications
You must be signed in to change notification settings - Fork 0
112 lines (98 loc) · 3.97 KB
/
Copy pathdeploy.yml
File metadata and controls
112 lines (98 loc) · 3.97 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
name: Deploy & Sync
on:
push:
branches: [main]
jobs:
deploy:
name: Deploy Worker
runs-on: ubuntu-latest
outputs:
worker_url: ${{ steps.get-url.outputs.url }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Inject persona config into wrangler.toml
run: node scripts/inject-config.js
- name: Create Vectorize index (idempotent)
run: |
output=$(npx wrangler vectorize create twinflare-vectorize-index \
--dimensions=1024 \
--metric=cosine 2>&1) \
|| echo "$output" | grep -qiE "already exist|duplicate_name|duplicate" \
|| { echo "$output"; exit 1; }
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- name: Deploy Worker
run: npx wrangler deploy
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- name: Set Worker secrets
run: |
echo "${{ secrets.PUBLIC_API_TOKEN }}" | npx wrangler secret put PUBLIC_API_TOKEN
if [ -n "${{ secrets.OPENAI_API_KEY }}" ]; then
echo "${{ secrets.OPENAI_API_KEY }}" | npx wrangler secret put OPENAI_API_KEY
fi
if [ -n "${{ secrets.ANTHROPIC_API_KEY }}" ]; then
echo "${{ secrets.ANTHROPIC_API_KEY }}" | npx wrangler secret put ANTHROPIC_API_KEY
fi
if [ -n "${{ secrets.GOOGLE_API_KEY }}" ]; then
echo "${{ secrets.GOOGLE_API_KEY }}" | npx wrangler secret put GOOGLE_API_KEY
fi
if [ -n "${{ secrets.OPENROUTER_API_KEY }}" ]; then
echo "${{ secrets.OPENROUTER_API_KEY }}" | npx wrangler secret put OPENROUTER_API_KEY
fi
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- name: Get Worker URL
id: get-url
run: |
# wrangler.toml name field → <name>.<subdomain>.workers.dev
WORKER_NAME=$(grep '^name' wrangler.toml | head -1 | sed 's/name = "\(.*\)"/\1/')
SUBDOMAIN=$(npx wrangler whoami 2>/dev/null | grep -oP 'workers\.dev subdomain: \K\S+' || echo "")
if [ -n "$SUBDOMAIN" ]; then
echo "url=https://${WORKER_NAME}.${SUBDOMAIN}.workers.dev" >> "$GITHUB_OUTPUT"
else
echo "url=" >> "$GITHUB_OUTPUT"
fi
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
sync:
name: Sync Knowledge Docs
runs-on: ubuntu-latest
needs: deploy
# Run sync whenever docs/ or config changes, or on first deploy
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2 # Need HEAD~1 for diff
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Check for doc/config changes
id: changes
run: |
if git diff --name-only HEAD~1 HEAD 2>/dev/null | grep -qE '^(docs/|twinflare\.config\.json)'; then
echo "changed=true" >> "$GITHUB_OUTPUT"
elif ! git rev-parse HEAD~1 >/dev/null 2>&1; then
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
fi
- name: Sync docs to Vectorize
if: steps.changes.outputs.changed == 'true'
run: node scripts/sync.js
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
- name: No doc changes
if: steps.changes.outputs.changed != 'true'
run: echo "No changes in docs/ or twinflare.config.json — skipping sync."