-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup-preview-workflow.ps1
More file actions
149 lines (132 loc) · 5.59 KB
/
Copy pathsetup-preview-workflow.ps1
File metadata and controls
149 lines (132 loc) · 5.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Preview Workflow Setup Script - Fixed Version
Write-Host "🔥 Creating Firebase Preview Workflow..." -ForegroundColor Cyan
Write-Host ""
# Create the .github/workflows directory if it doesn't exist
$workflowDir = ".github/workflows"
if (-not (Test-Path $workflowDir)) {
New-Item -ItemType Directory -Path $workflowDir -Force | Out-Null
Write-Host "✅ Created directory: $workflowDir" -ForegroundColor Green
}
# Create the fixed preview.yml workflow file
@'
name: Deploy Preview
on:
workflow_dispatch:
inputs:
branch:
description: 'Branch to deploy'
required: false
default: 'main'
type: string
channel:
description: 'Preview channel name'
required: false
default: 'manual-preview'
type: string
pull_request:
types: [opened, synchronize]
jobs:
preview:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch || github.event.pull_request.head.ref || 'main' }}
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- name: Install dependencies
run: pnpm install
- name: Build project
run: pnpm run build
- name: Deploy to Firebase Preview Channel
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
CHANNEL_NAME="${{ github.event.inputs.channel }}"
else
CHANNEL_NAME="pr-${{ github.event.number }}"
fi
echo "📦 Deploying to channel: $CHANNEL_NAME"
firebase hosting:channel:deploy "$CHANNEL_NAME" \
--expires 7d \
--project ytstudio-pr
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
- name: Output Preview URL
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
CHANNEL_NAME="${{ github.event.inputs.channel }}"
else
CHANNEL_NAME="pr-${{ github.event.number }}"
fi
echo "✅ Preview deployed successfully!"
echo "🔗 Preview URL: https://ytstudio-pr--$CHANNEL_NAME.web.app"
'@ | Out-File -FilePath ".github/workflows/preview.yml" -Encoding utf8
Write-Host "✅ Created .github/workflows/preview.yml" -ForegroundColor Green
# Commit and push
Write-Host ""
$commitNow = Read-Host "Do you want to commit and push the workflow now? (y/n)"
if ($commitNow -eq 'y') {
Write-Host "📦 Committing workflow..." -ForegroundColor Yellow
git add .github/workflows/preview.yml
git commit -m "fix: Update preview workflow with main branch as default"
git push origin main
Write-Host "✅ Committed and pushed!" -ForegroundColor Green
}
# Show next steps
Write-Host ""
Write-Host "🎯 Next Steps:" -ForegroundColor Cyan
Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Gray
Write-Host ""
Write-Host "1️⃣ Run with default settings (main branch):" -ForegroundColor Yellow
Write-Host " gh workflow run preview.yml" -ForegroundColor White
Write-Host ""
Write-Host "2️⃣ Run with specific branch:" -ForegroundColor Yellow
Write-Host " gh workflow run preview.yml -f branch=main -f channel=my-test" -ForegroundColor White
Write-Host ""
Write-Host "3️⃣ Check workflow status:" -ForegroundColor Yellow
Write-Host " gh run list --workflow=preview.yml --limit 5" -ForegroundColor White
Write-Host ""
Write-Host "4️⃣ View workflow logs:" -ForegroundColor Yellow
Write-Host " gh run view --workflow=preview.yml --latest --log" -ForegroundColor White
Write-Host ""
Write-Host "5️⃣ Deploy preview directly (local):" -ForegroundColor Yellow
Write-Host " firebase hosting:channel:deploy my-test --expires 7d --project ytstudio-pr" -ForegroundColor White
Write-Host ""
# Optional: Test the workflow
$testNow = Read-Host "Do you want to trigger the workflow manually now? (y/n)"
if ($testNow -eq 'y') {
Write-Host "🚀 Triggering workflow..." -ForegroundColor Yellow
# Check if FIREBASE_TOKEN exists
$tokenExists = gh secret list 2>$null | Select-String "FIREBASE_TOKEN"
if ($tokenExists) {
gh workflow run preview.yml
Write-Host "✅ Workflow triggered!" -ForegroundColor Green
Write-Host ""
Write-Host "Check status: gh run list --workflow=preview.yml --limit 3" -ForegroundColor White
Write-Host "View logs: gh run view --workflow=preview.yml --latest --log" -ForegroundColor White
} else {
Write-Host "❌ Cannot trigger workflow: FIREBASE_TOKEN secret is missing" -ForegroundColor Red
Write-Host ""
Write-Host "Please set up the token first:" -ForegroundColor Yellow
Write-Host "1. Run: firebase login:ci" -ForegroundColor White
Write-Host "2. Copy the token" -ForegroundColor White
Write-Host "3. Run: gh secret set FIREBASE_TOKEN" -ForegroundColor White
}
}
Write-Host ""
Write-Host "✅ Setup complete!" -ForegroundColor Green
Write-Host ""
Write-Host "📋 Workflow Features:" -ForegroundColor Cyan
Write-Host " • Manual trigger with branch selection" -ForegroundColor White
Write-Host " • Automatic PR previews" -ForegroundColor White
Write-Host " • Uses main branch as default" -ForegroundColor White
Write-Host " • 7-day preview expiration" -ForegroundColor White
Write-Host " • pnpm support" -ForegroundColor White