Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 110 additions & 25 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,119 @@ on:
jobs:
deploy-production:
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
uses: lifinance/github-actions/.github/workflows/cloudflare-worker-deploy.yaml@main
with:
environment: production
build-command: "bun run build"
node-version: "20"
secrets:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
runs-on: ubuntu-latest
name: Deploy to Production
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Install dependencies
run: bun install --frozen-lockfile

- name: Build application
env:
PRIVATE_POLYMER_MAINNET_ZONE_API_KEY: ${{ secrets.PRIVATE_POLYMER_MAINNET_ZONE_API_KEY }}
PRIVATE_POLYMER_TESTNET_ZONE_API_KEY: ${{ secrets.PRIVATE_POLYMER_TESTNET_ZONE_API_KEY }}
PUBLIC_WALLET_CONNECT_PROJECT_ID: ${{ secrets.PUBLIC_WALLET_CONNECT_PROJECT_ID }}
run: bun run build

- name: Deploy to Cloudflare Workers
uses: cloudflare/wrangler-action@v3
env:
PRIVATE_POLYMER_MAINNET_ZONE_API_KEY: ${{ secrets.PRIVATE_POLYMER_MAINNET_ZONE_API_KEY }}
PRIVATE_POLYMER_TESTNET_ZONE_API_KEY: ${{ secrets.PRIVATE_POLYMER_TESTNET_ZONE_API_KEY }}
PUBLIC_WALLET_CONNECT_PROJECT_ID: ${{ secrets.PUBLIC_WALLET_CONNECT_PROJECT_ID }}
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
wranglerVersion: "4.71.0"
command: deploy --env production

deploy-preview:
if: github.event_name == 'pull_request' && github.event.action != 'closed'
uses: lifinance/github-actions/.github/workflows/cloudflare-worker-deploy.yaml@main
with:
environment: preview
build-command: "bun run build"
node-version: "20"
preview-name: lintent-pr-${{ github.event.pull_request.number }}
secrets:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
runs-on: ubuntu-latest
name: Deploy Preview
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Install dependencies
run: bun install --frozen-lockfile

- name: Build application
env:
PRIVATE_POLYMER_MAINNET_ZONE_API_KEY: ${{ secrets.PRIVATE_POLYMER_MAINNET_ZONE_API_KEY }}
PRIVATE_POLYMER_TESTNET_ZONE_API_KEY: ${{ secrets.PRIVATE_POLYMER_TESTNET_ZONE_API_KEY }}
PUBLIC_WALLET_CONNECT_PROJECT_ID: ${{ secrets.PUBLIC_WALLET_CONNECT_PROJECT_ID }}
run: bun run build

- name: Deploy to Cloudflare Workers
id: deploy
uses: cloudflare/wrangler-action@v3
env:
PRIVATE_POLYMER_MAINNET_ZONE_API_KEY: ${{ secrets.PRIVATE_POLYMER_MAINNET_ZONE_API_KEY }}
PRIVATE_POLYMER_TESTNET_ZONE_API_KEY: ${{ secrets.PRIVATE_POLYMER_TESTNET_ZONE_API_KEY }}
PUBLIC_WALLET_CONNECT_PROJECT_ID: ${{ secrets.PUBLIC_WALLET_CONNECT_PROJECT_ID }}
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
wranglerVersion: "4.71.0"
command: deploy --name lintent-pr-${{ github.event.pull_request.number }}

- name: Post deployment comment
uses: actions/github-script@v7
with:
script: |
const maxAttempts = 3;
const delayMs = 10000;
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
try {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `🚀 **Preview deployed!**\n\n**Worker:** \`lintent-pr-${{ github.event.pull_request.number }}\`\n**URL:** ${{ steps.deploy.outputs.deployment-url }}`
});
return;
} catch (error) {
core.warning(`Attempt ${attempt}/${maxAttempts} failed: ${error.message}`);
if (attempt === maxAttempts) throw error;
await new Promise(r => setTimeout(r, delayMs));
}
}

cleanup-preview:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
uses: lifinance/github-actions/.github/workflows/cloudflare-worker-deploy.yaml@main
with:
delete-preview: true
preview-name: lintent-pr-${{ github.event.pull_request.number }}
node-version: "20"
secrets:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
runs-on: ubuntu-latest
name: Cleanup Preview Worker
steps:
- name: Delete preview worker
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
wranglerVersion: "4.71.0"
command: delete --name lintent-pr-${{ github.event.pull_request.number }} --force
Loading