# ── Web: Preview (Pull Requests) ────────────────────────────────────────────── # Triggered on pull_request open/sync → deploys to https://{pr-number}.{base_domain} # Triggered on pull_request_closed → cleans up the preview directory # # Preview environments share staging Appwrite credentials. # PR number is available as $CI_COMMIT_PULL_REQUEST. # # Required Woodpecker secrets: # base_domain e.g. budget.kushalgaywala.com # staging_appwrite_endpoint # staging_appwrite_project_id # ssh_private_key # deploy_host # deploy_user # deploy_path # ───────────────────────────────────────────────────────────────────────────── when: - event: [pull_request, pull_request_closed] steps: - name: build image: node:20-alpine environment: BASE_DOMAIN: from_secret: base_domain VITE_APPWRITE_ENDPOINT: from_secret: staging_appwrite_endpoint VITE_APPWRITE_PROJECT_ID: from_secret: staging_appwrite_project_id commands: - export MR_URL="https://$CI_COMMIT_PULL_REQUEST.$BASE_DOMAIN" - npm ci - VITE_APP_URL=$MR_URL npm run build:preview -w @budgetwise/web when: - event: pull_request - name: deploy image: alpine environment: SSH_PRIVATE_KEY: from_secret: ssh_private_key DEPLOY_HOST: from_secret: deploy_host DEPLOY_USER: from_secret: deploy_user DEPLOY_PATH: from_secret: deploy_path commands: - apk add --no-cache rsync openssh-client - eval $(ssh-agent -s) - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - - mkdir -p ~/.ssh && chmod 700 ~/.ssh - ssh-keyscan -H "$DEPLOY_HOST" >> ~/.ssh/known_hosts - rsync -avz --delete apps/web/dist/ "$DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH/mr-$CI_COMMIT_PULL_REQUEST/" when: - event: pull_request - name: cleanup image: alpine environment: SSH_PRIVATE_KEY: from_secret: ssh_private_key DEPLOY_HOST: from_secret: deploy_host DEPLOY_USER: from_secret: deploy_user DEPLOY_PATH: from_secret: deploy_path commands: - apk add --no-cache openssh-client - eval $(ssh-agent -s) - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - - mkdir -p ~/.ssh && chmod 700 ~/.ssh - ssh-keyscan -H "$DEPLOY_HOST" >> ~/.ssh/known_hosts - ssh "$DEPLOY_USER@$DEPLOY_HOST" "rm -rf $DEPLOY_PATH/mr-$CI_COMMIT_PULL_REQUEST" when: - event: pull_request_closed