Merge pull request #451 from codeit-FE-15-Part4-Team1/develop #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy to Production | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| env: | |
| VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} | |
| VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| - name: Install pnpm | |
| run: | | |
| npm install -g pnpm | |
| pnpm --version | |
| - name: Install Vercel CLI | |
| run: npm install -g vercel@latest | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Run linting and type checking | |
| run: | | |
| pnpm lint | |
| pnpm type-check | |
| - name: Pull Vercel Environment Variables | |
| run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} | |
| - name: Build project | |
| run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }} | |
| - name: Deploy to Vercel | |
| id: deploy | |
| run: | | |
| echo "🚀 Starting production deployment..." | |
| vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }} > vercel-output.txt | |
| if [ -f vercel-output.txt ] && [ -s vercel-output.txt ]; then | |
| production_url=$(cat vercel-output.txt) | |
| echo "production_url=$production_url" >> $GITHUB_OUTPUT | |
| echo "✅ Production deployment successful: $production_url" | |
| else | |
| echo "❌ Error: Production deployment failed" | |
| exit 1 | |
| fi | |
| - name: Sync to forked repository | |
| if: steps.deploy.outcome == 'success' | |
| run: | | |
| echo "🔄 Starting repository sync..." | |
| # Configure Git | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| # Clone destination repository | |
| git clone https://x-access-token:${{ secrets.AUTO_ACTIONS }}@github.com/Yongmin0423/RoamReady.git dest-repo | |
| cd dest-repo | |
| # Ensure we're on the main branch | |
| git checkout main | |
| # Copy project files (excluding git and node_modules) | |
| rsync -av --delete \ | |
| --exclude='.git' \ | |
| --exclude='node_modules' \ | |
| --exclude='.vercel' \ | |
| --exclude='.next' \ | |
| ../ . | |
| # Check if there are changes | |
| if git diff --quiet && git diff --staged --quiet; then | |
| echo "✅ No changes to sync" | |
| else | |
| git add . | |
| git commit -m "🚀 Auto-deploy: ${{ github.event.head_commit.message }}" | |
| git push origin main | |
| echo "✅ Successfully synced to forked repository" | |
| fi | |
| - name: Deployment summary | |
| if: always() | |
| run: | | |
| echo "## 🎉 Deployment Summary" | |
| echo "**Branch**: main" | |
| echo "**Commit**: ${{ github.sha }}" | |
| echo "**Message**: ${{ github.event.head_commit.message }}" | |
| if [ "${{ steps.deploy.outcome }}" == "success" ]; then | |
| echo "**Status**: ✅ Success" | |
| echo "**URL**: ${{ steps.deploy.outputs.production_url }}" | |
| else | |
| echo "**Status**: ❌ Failed" | |
| fi |