ci: fix incorrect deploy hook, skip build and deploy on cache hit #53
This file contains 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
# GitHub Actions workflow for running Jest backend tests. | |
# Features: | |
# - Automated testing on push/PR | |
# - Environment setup | |
# - Cache hit detection for builds | |
# - Test execution | |
# - Results reporting | |
# - Deployment trigger | |
# | |
# By Dulapah Vibulsanti (https://dulapahv.dev) | |
name: 🧪 Jest Tests | |
permissions: | |
contents: read | |
actions: write | |
checks: write | |
on: | |
push: | |
branches: [main, master] | |
pull_request: | |
branches: [main, master] | |
jobs: | |
test: | |
name: 🧪 Run Server Tests | |
runs-on: ubuntu-latest | |
env: | |
CI: true | |
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} | |
TURBO_TEAM: ${{ vars.TURBO_TEAM }} | |
steps: | |
# Checkout code | |
- name: 📥 Checkout code | |
uses: actions/checkout@v4 | |
# Install pnpm | |
- name: 📦 Install pnpm | |
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0 | |
# Setup Node.js | |
- name: 🔧 Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 22 | |
cache: 'pnpm' | |
# Turbo cache | |
- name: 💾 Cache Turbo | |
id: turbo-cache | |
uses: actions/cache@v4 | |
with: | |
path: .turbo | |
key: ${{ runner.os }}-turbo-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-turbo- | |
# Check for server changes using turbo | |
- name: 🔍 Check for server changes | |
id: check-changes | |
run: | | |
# Install only the minimal dependencies needed for turbo | |
pnpm install turbo --no-frozen-lockfile | |
# Run dry-run build to check for changes | |
if pnpm turbo build --filter=server --dry-run > /dev/null 2>&1; then | |
echo "No changes detected in server package" | |
echo "skip_build=true" >> $GITHUB_OUTPUT | |
else | |
echo "Changes detected in server package" | |
echo "skip_build=false" >> $GITHUB_OUTPUT | |
fi | |
# Install dependencies | |
- name: 🏗️ Install dependencies | |
if: steps.check-changes.outputs.skip_build != 'true' | |
run: pnpm install | |
# Build packages | |
- name: 🔨 Build packages | |
if: steps.check-changes.outputs.skip_build != 'true' | |
run: pnpm build:server | |
# Run Jest tests | |
- name: 🧪 Run Jest tests | |
run: pnpm test:server | |
# Upload test results | |
- name: 📊 Upload test results | |
if: always() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: jest-report | |
path: apps/server/test-results/junit.xml | |
retention-days: 30 | |
# Trigger Render deployment if tests pass | |
- name: 🚀 Trigger Render Deployment | |
if: success() && github.ref == 'refs/heads/main' | |
run: | | |
curl -X POST "${{ secrets.RENDER_DEPLOY_HOOK }}" |