Skip to content
Closed
Show file tree
Hide file tree
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
129 changes: 129 additions & 0 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
name: Preview Deployment

on:
pull_request:
types: [opened, synchronize, reopened]
pull_request_target:
types: [closed]

jobs:
deploy-preview:
if: github.event.action != 'closed'
runs-on: ubuntu-latest
name: Deploy Preview

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- name: Cache Rust dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-

- name: Build
run: cargo install -q worker-build && worker-build --release

- name: Deploy to Cloudflare Workers
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: deploy --name firefly-api-pr-${{ github.event.number }} --compatibility-date 2025-06-22
workingDirectory: '.'
env:
FIREFLY_API_AUTHN_TOKEN: ${{ secrets.FIREFLY_API_AUTHN_TOKEN }}
BILIBILI_SESSDATA: ${{ secrets.BILIBILI_SESSDATA }}
SPOTIFY_WEB_API_CLIENT_ID: ${{ secrets.SPOTIFY_WEB_API_CLIENT_ID }}
SPOTIFY_WEB_API_CLIENT_SECRET: ${{ secrets.SPOTIFY_WEB_API_CLIENT_SECRET }}
SPOTIFY_WEB_API_REDIRECT_URI: ${{ secrets.SPOTIFY_WEB_API_REDIRECT_URI }}
- name: Comment PR
uses: actions/github-script@v7
with:
script: |
const prNumber = context.issue.number;
const previewUrl = `https://firefly-api-pr-${prNumber}.eikasia30.workers.dev`;

// Find existing preview comment
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});

const botComment = comments.data.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('🚀 Preview Deployment')
);

const body = `🚀 **Preview Deployment**

Your preview deployment is ready!

**🔗 Preview URL:** ${previewUrl}

This preview will be updated automatically when you push new commits to this PR.

<sub>Deployed from commit: ${context.sha.substring(0, 7)}</sub>`;

if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: body
});
}

cleanup-preview:
if: github.event.action == 'closed'
runs-on: ubuntu-latest
name: Cleanup Preview

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Delete preview deployment
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: delete firefly-api-pr-${{ github.event.number }}
continue-on-error: true

- name: Comment PR cleanup
uses: actions/github-script@v7
with:
script: |
const prNumber = context.issue.number;

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: `🧹 **Preview Cleaned Up**

The preview deployment for this PR has been removed.`
});
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
target
node_modules
.wrangler
.dev.vars
.dev.vars

# test request json file
request.json
Loading
Loading