Skip to content

Deploy CDN Script

Deploy CDN Script #5

Workflow file for this run

name: Deploy CDN Script
on:
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
# ── Setup ────────────────────────────────────────────────
- name: Checkout code
uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
# ── Build ────────────────────────────────────────────────
- name: Build CDN script (master)
if: github.ref == 'refs/heads/master'
run: pnpm bundle
- name: Build CDN script (dev)
if: github.ref == 'refs/heads/dev'
run: pnpm bundle:dev
- name: Build npm package
run: pnpm build
# ── Unit tests ──────────────────────────────────────────
- name: Run unit tests
run: pnpm test:units
# ── Script E2E tests ────────────────────────────────────
- name: Copy tracker to test apps
run: |
mkdir -p test/mpa/public test/spa/static
cp build/stonks.js test/mpa/public/stonks.js
cp build/stonks.js test/spa/static/stonks.js
- name: Pack and install npm package into test apps
run: |
TARBALL=$(pnpm pack | tail -1)
TARBALL_PATH="$(pwd)/$TARBALL"
cd test/mpa && pnpm add --save-dev "$TARBALL_PATH"
cd ../spa && pnpm add --save-dev "$TARBALL_PATH"
- name: Build MPA test app
run: pnpm build
working-directory: test/mpa
- name: Build SPA test app
run: pnpm build
working-directory: test/spa
- name: Install Chromium for Puppeteer
run: npx puppeteer browsers install chrome
- name: Start servers and wait for readiness
run: |
(cd test/mpa && pnpm preview --host 0.0.0.0) &
(cd test/spa && pnpm preview --host 0.0.0.0) &
echo "Waiting for MPA server (port 4321)..."
timeout 30 bash -c 'until curl -sf http://127.0.0.1:4321 > /dev/null 2>&1; do sleep 1; done'
echo "MPA server is ready"
echo "Waiting for SPA server (port 5173)..."
timeout 30 bash -c 'until curl -s -o /dev/null http://127.0.0.1:5173 2>&1; do sleep 1; done'
echo "SPA server is ready"
- name: Run script E2E tests
run: pnpm test:e2e:script
env:
SKIP_BUILD: "1"
SKIP_SERVERS: "1"
# ── Deploy to Cloudflare R2 ─────────────────────────────
- name: Upload stonks.js to R2 (master)
if: github.ref == 'refs/heads/master'
run: |
export CLOUDFLARE_API_TOKEN=$(printf '%s' "$CLOUDFLARE_API_TOKEN" | tr -d '\n\r')
npx wrangler r2 object put one-dollar-analytic/stonks.js --file=build/stonks.js --content-type=text/javascript --remote
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- name: Upload stonks-dev.js to R2 (dev)
if: github.ref == 'refs/heads/dev'
run: |
export CLOUDFLARE_API_TOKEN=$(printf '%s' "$CLOUDFLARE_API_TOKEN" | tr -d '\n\r')
npx wrangler r2 object put one-dollar-analytic/stonks-dev.js --file=build/stonks.js --content-type=text/javascript --remote
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}