Skip to content

refactor(useGoalsUpdater): Refactor hook into modules and add tests. #45

refactor(useGoalsUpdater): Refactor hook into modules and add tests.

refactor(useGoalsUpdater): Refactor hook into modules and add tests. #45

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}`
});