Skip to content

Commit f4dc29e

Browse files
committed
fix: demo ci issues (#359)
1 parent a47d47c commit f4dc29e

File tree

10 files changed

+209
-305
lines changed

10 files changed

+209
-305
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: 'Install Sqruff CLI'
2+
description: 'Install sqruff SQL linter and formatter'
3+
author: 'quarylabs (forked fix from fank)'
4+
5+
inputs:
6+
version:
7+
description: 'Version of Sqruff CLI to install'
8+
required: false
9+
default: 'latest'
10+
github-token:
11+
description: 'GitHub token for API requests (helps avoid rate limiting)'
12+
required: false
13+
default: ''
14+
15+
runs:
16+
using: 'composite'
17+
steps:
18+
- run: |
19+
set -e # Exit on error
20+
21+
# Function to make GitHub API calls with optional token
22+
github_api_call() {
23+
local url=$1
24+
if [ -n "${{ inputs.github-token }}" ]; then
25+
curl -s -H "Authorization: token ${{ inputs.github-token }}" "$url"
26+
else
27+
curl -s "$url"
28+
fi
29+
}
30+
31+
# Determine version to install
32+
if [ "${{ inputs.version }}" = "latest" ]; then
33+
echo "Fetching latest Sqruff release..."
34+
API_RESPONSE=$(github_api_call "https://api.github.com/repos/quarylabs/sqruff/releases/latest")
35+
36+
# Check if API call was successful
37+
if echo "$API_RESPONSE" | grep -q "API rate limit exceeded"; then
38+
echo "::error::GitHub API rate limit exceeded. Please provide a github-token input."
39+
exit 1
40+
fi
41+
42+
LATEST_VERSION=$(echo "$API_RESPONSE" | grep '"tag_name"' | cut -d '"' -f 4)
43+
44+
if [ -z "$LATEST_VERSION" ]; then
45+
echo "::error::Failed to fetch latest version from GitHub API"
46+
echo "API Response: $API_RESPONSE"
47+
exit 1
48+
fi
49+
50+
echo "Latest version is $LATEST_VERSION"
51+
VERSION=$LATEST_VERSION
52+
else
53+
VERSION=${{ inputs.version }}
54+
fi
55+
56+
# Detect architecture
57+
ARCH=$(uname -m)
58+
case $ARCH in
59+
x86_64)
60+
BINARY_NAME="sqruff-linux-x86_64-musl"
61+
;;
62+
aarch64|arm64)
63+
BINARY_NAME="sqruff-linux-aarch64-musl"
64+
;;
65+
*)
66+
echo "::error::Unsupported architecture: $ARCH"
67+
exit 1
68+
;;
69+
esac
70+
71+
# Download and install
72+
echo "Installing Sqruff CLI version $VERSION for architecture $ARCH"
73+
DOWNLOAD_URL="https://github.com/quarylabs/sqruff/releases/download/$VERSION/${BINARY_NAME}.tar.gz"
74+
75+
echo "Downloading from: $DOWNLOAD_URL"
76+
if ! wget -q --show-progress "$DOWNLOAD_URL" -O sqruff-cli.tar.gz; then
77+
echo "::error::Failed to download Sqruff CLI from $DOWNLOAD_URL"
78+
exit 1
79+
fi
80+
81+
echo "Extracting archive..."
82+
if ! tar -xzf sqruff-cli.tar.gz; then
83+
echo "::error::Failed to extract tarball"
84+
exit 1
85+
fi
86+
87+
echo "Installing binary..."
88+
if ! sudo mv sqruff /usr/local/bin/sqruff; then
89+
echo "::error::Failed to install sqruff binary"
90+
exit 1
91+
fi
92+
93+
# Make sure it's executable
94+
sudo chmod +x /usr/local/bin/sqruff
95+
96+
# Verify installation
97+
echo "Verifying installation..."
98+
if sqruff --version; then
99+
echo "✅ Sqruff CLI installed successfully!"
100+
else
101+
echo "::error::Failed to verify Sqruff CLI installation"
102+
exit 1
103+
fi
104+
shell: bash

.github/workflows/ci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ jobs:
3434
deno-version: '1.45.2'
3535

3636
- name: Install sqruff
37-
uses: quarylabs/install-sqruff-cli-action@main
37+
uses: ./.github/actions/setup-sqruff
38+
with:
39+
github-token: ${{ secrets.GITHUB_TOKEN }}
3840

3941
- name: Setup Atlas
4042
uses: ariga/setup-atlas@master
@@ -75,7 +77,9 @@ jobs:
7577
deno-version: '1.45.2'
7678

7779
- name: Install sqruff
78-
uses: quarylabs/install-sqruff-cli-action@main
80+
uses: ./.github/actions/setup-sqruff
81+
with:
82+
github-token: ${{ secrets.GITHUB_TOKEN }}
7983

8084
- name: Setup Atlas
8185
uses: ariga/setup-atlas@master

apps/demo/PLAUSIBLE_SETUP.md

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This guide walks you through setting up Plausible Analytics with a Cloudflare Wo
55
## Overview
66

77
The setup consists of three parts:
8+
89
1. Plausible dashboard configuration
910
2. Cloudflare Worker proxy deployment
1011
3. SvelteKit app configuration
@@ -43,19 +44,22 @@ The setup consists of three parts:
4344
2. Delete the default code
4445
3. Copy the code from `cloudflare-worker-plausible-proxy.js`
4546
4. **Update the configuration** at the top of the file:
47+
4648
```javascript
4749
// Replace with your Plausible script URL from Part 1
4850
const ProxyScript = 'https://plausible.io/js/pa-XXXXX.js';
4951
5052
// Customize these paths (avoid obvious names)
51-
const ScriptName = '/metrics/script.js'; // Change to something unique
52-
const Endpoint = '/metrics/event'; // Should match folder above
53+
const ScriptName = '/metrics/script.js'; // Change to something unique
54+
const Endpoint = '/metrics/event'; // Should match folder above
5355
```
56+
5457
5. Click "Save and Deploy"
5558

5659
### Step 3: Test the Worker
5760

5861
1. Your worker will be available at:
62+
5963
```
6064
https://your-worker-name.your-account.workers.dev
6165
```
@@ -78,6 +82,7 @@ If your site is on Cloudflare CDN, you can run the proxy as a subdirectory:
7882
4. Click "Save"
7983

8084
Now your proxy will be available at:
85+
8186
```
8287
https://yourdomain.com/analytics/metrics/script.js
8388
https://yourdomain.com/analytics/metrics/event
@@ -91,24 +96,25 @@ Open `apps/demo/src/routes/+layout.svelte` and update the TODO section:
9196

9297
```typescript
9398
onMount(() => {
94-
initPlausible({
95-
domain: 'demo.pgflow.dev', // Your actual domain
96-
apiHost: 'https://your-worker.workers.dev/metrics', // Your proxy URL
97-
trackLocalhost: false // Set to true for testing locally
98-
});
99+
initPlausible({
100+
domain: 'demo.pgflow.dev', // Your actual domain
101+
apiHost: 'https://your-worker.workers.dev/metrics', // Your proxy URL
102+
trackLocalhost: false // Set to true for testing locally
103+
});
99104
});
100105
```
101106

102107
**Configuration options:**
103108

104109
- **Without custom route** (worker URL):
110+
105111
```typescript
106-
apiHost: 'https://your-worker-name.your-account.workers.dev/metrics'
112+
apiHost: 'https://your-worker-name.your-account.workers.dev/metrics';
107113
```
108114

109115
- **With custom route** (subdirectory):
110116
```typescript
111-
apiHost: '/analytics/metrics' // Relative path works!
117+
apiHost: '/analytics/metrics'; // Relative path works!
112118
```
113119

114120
## Part 4: Track Custom Events
@@ -123,19 +129,23 @@ track('button_clicked');
123129

124130
// Event with properties
125131
track('signup', {
126-
tier: 'pro',
127-
plan: 'monthly',
128-
source: 'landing_page'
132+
tier: 'pro',
133+
plan: 'monthly',
134+
source: 'landing_page'
129135
});
130136

131137
// Event with revenue tracking
132-
track('purchase', {
133-
product: 'pro-plan',
134-
quantity: 1
135-
}, {
136-
amount: 29.99,
137-
currency: 'USD'
138-
});
138+
track(
139+
'purchase',
140+
{
141+
product: 'pro-plan',
142+
quantity: 1
143+
},
144+
{
145+
amount: 29.99,
146+
currency: 'USD'
147+
}
148+
);
139149
```
140150

141151
### Common Event Examples
@@ -158,11 +168,13 @@ track('documentation_download', { doc_type: 'api_reference' });
158168
## Part 5: Verify Installation
159169

160170
1. **Start your dev server**:
171+
161172
```bash
162173
pnpm nx dev demo
163174
```
164175

165176
2. **Open your browser console** and look for:
177+
166178
```
167179
[Plausible] Initialized successfully
168180
```
@@ -173,10 +185,12 @@ track('documentation_download', { doc_type: 'api_reference' });
173185
- Note: It may take a few seconds for events to appear
174186

175187
4. **Test custom events**:
188+
176189
```typescript
177190
// In browser console or your code
178191
track('test_event', { test: true });
179192
```
193+
180194
- Check Plausible dashboard > Custom Events to see it
181195

182196
## Troubleshooting

apps/demo/cloudflare-worker-plausible-proxy.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// CONFIGURATION - UPDATE THIS VALUE!
99
// Get this from your Plausible dashboard (Site Settings > Site Installation)
1010
// It will look like: https://plausible.io/js/script.js (or pa-XXXXX.js for custom domains)
11-
const ProxyScript = 'https://plausible.io/js/script.js'; // ← UPDATE THIS!
11+
const ProxyScript = 'https://plausible.io/js/script.js'; // ← UPDATE THIS!
1212

1313
// Customize these paths to avoid ad-blocker detection
1414
const ScriptName = '/stats/script.js';
@@ -18,34 +18,34 @@ const Endpoint = '/stats/event';
1818
const ScriptWithoutExtension = ScriptName.replace('.js', '');
1919

2020
addEventListener('fetch', (event) => {
21-
event.passThroughOnException();
22-
event.respondWith(handleRequest(event));
21+
event.passThroughOnException();
22+
event.respondWith(handleRequest(event));
2323
});
2424

2525
async function handleRequest(event) {
26-
const pathname = new URL(event.request.url).pathname;
27-
const [baseUri, ...extensions] = pathname.split('.');
26+
const pathname = new URL(event.request.url).pathname;
27+
const [baseUri] = pathname.split('.');
2828

29-
if (baseUri.endsWith(ScriptWithoutExtension)) {
30-
return getScript(event, extensions);
31-
} else if (pathname.endsWith(Endpoint)) {
32-
return postData(event);
33-
}
29+
if (baseUri.endsWith(ScriptWithoutExtension)) {
30+
return getScript(event);
31+
} else if (pathname.endsWith(Endpoint)) {
32+
return postData(event);
33+
}
3434

35-
return new Response(null, { status: 404 });
35+
return new Response(null, { status: 404 });
3636
}
3737

38-
async function getScript(event, extensions) {
39-
let response = await caches.default.match(event.request);
40-
if (!response) {
41-
response = await fetch(ProxyScript);
42-
event.waitUntil(caches.default.put(event.request, response.clone()));
43-
}
44-
return response;
38+
async function getScript(event) {
39+
let response = await caches.default.match(event.request);
40+
if (!response) {
41+
response = await fetch(ProxyScript);
42+
event.waitUntil(caches.default.put(event.request, response.clone()));
43+
}
44+
return response;
4545
}
4646

4747
async function postData(event) {
48-
const request = new Request(event.request);
49-
request.headers.delete('cookie');
50-
return await fetch('https://plausible.io/api/event', request);
48+
const request = new Request(event.request);
49+
request.headers.delete('cookie');
50+
return await fetch('https://plausible.io/api/event', request);
5151
}

apps/demo/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"dependencies": {
4848
"@pgflow/client": "workspace:*",
4949
"@pgflow/dsl": "workspace:*",
50-
"@plausible-analytics/tracker": "^0.4.4",
5150
"@supabase/supabase-js": "^2.78.0",
5251
"@xyflow/svelte": "^1.4.1",
5352
"shiki": "^3.14.0"

0 commit comments

Comments
 (0)