|
| 1 | +name: Staging Deployment |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +jobs: |
| 9 | + deploy-staging: |
| 10 | + name: Deploy to Staging |
| 11 | + runs-on: ubuntu-latest |
| 12 | + if: github.event.head_commit.author.name != 'github-actions[bot]' |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout repository |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Set up Rust |
| 21 | + uses: dtolnay/rust-toolchain@stable |
| 22 | + with: |
| 23 | + targets: wasm32-unknown-unknown |
| 24 | + |
| 25 | + - name: Install Soroban CLI |
| 26 | + run: | |
| 27 | + cargo install --locked soroban-cli |
| 28 | +
|
| 29 | + - name: Deploy Contracts to Testnet |
| 30 | + id: deploy_contracts |
| 31 | + env: |
| 32 | + SOROBAN_SECRET_KEY: ${{ secrets.STAGING_SOROBAN_SECRET_KEY }} |
| 33 | + SOROBAN_NETWORK: testnet |
| 34 | + run: | |
| 35 | + ./scripts/deploy_contracts.sh testnet |
| 36 | + VAULT_ID=$(jq -r '.contracts.vault' deployments/contracts.testnet.json) |
| 37 | + STRATEGY_ID=$(jq -r '.contracts.mock_korean_strategy' deployments/contracts.testnet.json) |
| 38 | + echo "vault_id=$VAULT_ID" >> $GITHUB_OUTPUT |
| 39 | + echo "strategy_id=$STRATEGY_ID" >> $GITHUB_OUTPUT |
| 40 | +
|
| 41 | + - name: Set up Node.js |
| 42 | + uses: actions/setup-node@v4 |
| 43 | + with: |
| 44 | + node-version: 20 |
| 45 | + cache: 'npm' |
| 46 | + |
| 47 | + - name: Deploy Backend |
| 48 | + working-directory: backend |
| 49 | + env: |
| 50 | + DATABASE_URL: ${{ secrets.STAGING_DATABASE_URL }} |
| 51 | + VAULT_CONTRACT_ID: ${{ steps.deploy_contracts.outputs.vault_id }} |
| 52 | + run: | |
| 53 | + npm ci |
| 54 | + npx prisma migrate deploy |
| 55 | + # Replace with your actual backend deployment command (e.g., Vercel, Railway, Render) |
| 56 | + # Example: npx vercel --token ${{ secrets.VERCEL_TOKEN }} --prod --yes |
| 57 | + echo "Backend deployment simulated" |
| 58 | + echo "BACKEND_URL=https://yieldvault-backend-staging.vercel.app" >> $GITHUB_ENV |
| 59 | +
|
| 60 | + - name: Deploy Frontend |
| 61 | + working-directory: frontend |
| 62 | + env: |
| 63 | + VITE_VAULT_CONTRACT_ID: ${{ steps.deploy_contracts.outputs.vault_id }} |
| 64 | + VITE_API_URL: ${{ env.BACKEND_URL }} |
| 65 | + run: | |
| 66 | + npm ci |
| 67 | + npm run build |
| 68 | + # Replace with your actual frontend deployment command |
| 69 | + # Example: npx vercel --token ${{ secrets.VERCEL_TOKEN }} --prod --yes |
| 70 | + echo "Frontend deployment simulated" |
| 71 | + echo "STAGING_URL=https://yieldvault-staging.vercel.app" >> $GITHUB_ENV |
| 72 | +
|
| 73 | + - name: Post Staging URL to PR |
| 74 | + uses: actions/github-script@v7 |
| 75 | + with: |
| 76 | + script: | |
| 77 | + const { owner, repo } = context.repo; |
| 78 | + const sha = context.sha; |
| 79 | + |
| 80 | + // Find PRs associated with this commit |
| 81 | + const prs = await github.rest.repos.listPullRequestsAssociatedWithCommit({ |
| 82 | + owner, |
| 83 | + repo, |
| 84 | + commit_sha: sha, |
| 85 | + }); |
| 86 | + |
| 87 | + if (prs.data.length > 0) { |
| 88 | + const prNumber = prs.data[0].number; |
| 89 | + const body = `🚀 **Staging Environment Updated!**\n\n- **Frontend:** [${process.env.STAGING_URL}](${process.env.STAGING_URL})\n- **Backend API:** [${process.env.BACKEND_URL}](${process.env.BACKEND_URL})\n- **Vault Contract ID:** \`${{ steps.deploy_contracts.outputs.vault_id }}\`\n\n_This environment was automatically deployed to reflect the latest state of the \`main\` branch._`; |
| 90 | + |
| 91 | + await github.rest.issues.createComment({ |
| 92 | + owner, |
| 93 | + repo, |
| 94 | + issue_number: prNumber, |
| 95 | + body, |
| 96 | + }); |
| 97 | + } |
0 commit comments