-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (104 loc) · 3.78 KB
/
firebase-preview.yml
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
name: Firebase Preview Deploy
on:
pull_request:
branches:
- main
jobs:
deploy-preview:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
issues: write
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
- name: 📦 Setup Node
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
cache: 'npm'
- name: 📂 Install dependencies
run: npm ci
- name: 🔨 Build the app
run: npm run build
# 🚨 Run Lint check
- name: 🚨 Run Lint
run: npm run lint:fix | tee lint-results.txt
# 🎨 Run Prettier format check
- name: 🎨 Run Prettier
run: npm run format | tee prettier-results.txt
- name: 🧪 Test the app with Vitest
run: npm run test:ci | tee test-results.txt
# 🚮 Clean up all results for comment
- name: 🚮 Clean up results
run: |
sed -i 's/\x1b\[[0-9;]*m//g' prettier-results.txt
sed -i 's/\x1b\[[0-9;]*m//g' lint-results.txt
sed -i 's/\x1b\[[0-9;]*m//g' test-results.txt
# 📄 Format all results for better readability
- name: 📄 Format all results
run: |
{
echo "### 🧪 Test Results"
echo ""
if grep -q "failed" test-results.txt; then
echo "❌ **Some tests failed**:"
echo '```'
grep -E "Test Files|Tests|Duration|failed" test-results.txt
echo '```'
echo "💥 Please review the failed tests above."
else
echo "✅ **Tests Passed**: All tests passed successfully!"
fi
echo ""
echo "---"
echo ""
echo "### 🎨 Prettier Format Check"
echo ""
if grep -q "(changed)" prettier-results.txt; then
echo "⚠️ **Prettier Issues Found** - Some format issues are fixed automatically by Prettier:"
echo '```'
grep -E "\s+\(changed\)" prettier-results.txt || true
echo '```'
else
echo "✅ **Prettier**: No formatting issues found!"
fi
echo ""
echo "### 🎨 Lint Check"
echo ""
if grep -qE "^[^0]* problems" lint-results.txt; then
echo "⚠️ **Lint Issues Found** - PLEASE FIX THEM!"
echo '```'
cat lint-results.txt
echo '```'
else
echo "✅ **Lint**: No linting issues found!"
fi
} > formatted-results.txt
- name: 🚀 Install Firebase CLI
run: npm install -g firebase-tools
- name: 🌐 Deploy to Firebase Preview Channel
id: firebase_deploy
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
run: |
firebase hosting:channel:deploy pr-${{ github.event.number }} --expires 2d | tee deploy-output.txt
- name: 🔗 Extract Preview URL
id: extract_url
run: |
URL=$(grep -oP 'https:\/\/[^\s]+pr-${{ github.event.number }}[^\s]+' deploy-output.txt)
echo "PREVIEW_URL=${URL}" >> $GITHUB_ENV
- name: 💬 Post test results and preview link to PR
uses: actions/github-script@v7
with:
script: |
const previewUrl = process.env.PREVIEW_URL;
const fs = require('fs');
const testResults = fs.readFileSync('formatted-results.txt', 'utf8');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `🚀 Preview for this PR is available at: ${previewUrl} \n\n ${testResults}`
});