Skip to content

v1.3.1

v1.3.1 #22

Workflow file for this run

name: Deploy to CDN
on:
release:
types: [published]
push:
tags:
- "v*"
workflow_dispatch:
inputs:
version:
description: 'Version to deploy (e.g., 1.2.3)'
required: true
type: string
jobs:
deploy-cdn:
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 10
run_install: false
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 23
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Create dist directory
run: mkdir -p dist
- name: Minify JavaScript
run: pnpm minify
- name: Prepare release files
run: pnpm prepare-release
- name: Get version
id: version
run: |
if [ "${{ github.event_name }}" == "release" ]; then
VERSION="${{ github.event.release.tag_name }}"
elif [ "${{ github.event_name }}" == "push" ] && [ "${{ github.ref_type }}" == "tag" ]; then
VERSION="${{ github.ref_name }}"
else
VERSION="${{ inputs.version }}"
fi
# Remove 'v' prefix if present
VERSION=${VERSION#v}
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "πŸ“‹ Deploying version: ${VERSION}"
- name: Test Cloudflare API connection
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: |
echo "πŸ” Testing Cloudflare API connection..."
curl -s "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/tokens/verify" \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" | jq '.'
- name: Deploy via Wrangler
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: |
r2 object put ${{ secrets.CLOUDFLARE_R2_BUCKET_NAME }}/v${{ steps.version.outputs.version }}/script.min.js --file=dist/script.min.js
r2 object put ${{ secrets.CLOUDFLARE_R2_BUCKET_NAME }}/latest/script.min.js --file=dist/script.min.js
r2 object put ${{ secrets.CLOUDFLARE_R2_BUCKET_NAME }}/script.min.js --file=dist/script.min.js
- name: Verify deployment
env:
CLOUDFLARE_R2_CUSTOM_DOMAIN: ${{ secrets.CLOUDFLARE_R2_CUSTOM_DOMAIN }}
VERSION: ${{ steps.version.outputs.version }}
run: |
echo "πŸ” Verifying deployment..."
sleep 10 # Wait for propagation
# Test versioned URL
VERSIONED_URL="https://$CLOUDFLARE_R2_CUSTOM_DOMAIN/v$VERSION/script.min.js"
echo "Testing: $VERSIONED_URL"
if curl -s -f -I "$VERSIONED_URL" > /dev/null; then
echo "βœ… Versioned URL is accessible"
else
echo "❌ Versioned URL failed"
fi
# Test latest URL
LATEST_URL="https://$CLOUDFLARE_R2_CUSTOM_DOMAIN/latest/script.min.js"
echo "Testing: $LATEST_URL"
if curl -s -f -I "$LATEST_URL" > /dev/null; then
echo "βœ… Latest URL is accessible"
else
echo "❌ Latest URL failed"
fi
# Test root URL
ROOT_URL="https://$CLOUDFLARE_R2_CUSTOM_DOMAIN/script.min.js"
echo "Testing: $ROOT_URL"
if curl -s -f -I "$ROOT_URL" > /dev/null; then
echo "βœ… Root URL is accessible"
else
echo "❌ Root URL failed"
fi
- name: Create deployment summary
env:
CLOUDFLARE_R2_CUSTOM_DOMAIN: ${{ secrets.CLOUDFLARE_R2_CUSTOM_DOMAIN }}
VERSION: ${{ steps.version.outputs.version }}
run: |
echo "## πŸŽ‰ CDN Deployment Successful" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** \`$VERSION\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### πŸ“ Available URLs:" >> $GITHUB_STEP_SUMMARY
echo "- **Versioned:** https://$CLOUDFLARE_R2_CUSTOM_DOMAIN/v$VERSION/script.min.js" >> $GITHUB_STEP_SUMMARY
echo "- **Latest:** https://$CLOUDFLARE_R2_CUSTOM_DOMAIN/latest/script.min.js" >> $GITHUB_STEP_SUMMARY
echo "- **Root:** https://$CLOUDFLARE_R2_CUSTOM_DOMAIN/script.min.js" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### πŸ”§ Usage:" >> $GITHUB_STEP_SUMMARY
echo '```html' >> $GITHUB_STEP_SUMMARY
echo "<script src=\"https://$CLOUDFLARE_R2_CUSTOM_DOMAIN/script.min.js\" data-key=\"your-publishable-key\"></script>" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY