|
| 1 | +# Build and Push to Lovable (Asper Beauty Shop) |
| 2 | +# Repo: asperpharma/understand-project |
| 3 | +# Live: https://asperbeautyshop-com.lovable.app |
| 4 | +# |
| 5 | +# On push to main (or manual run): build + test, then notify Lovable via webhook. |
| 6 | +# The "Notify Lovable" deploy job runs only when LOVABLE_WEBHOOK_URL is set. |
| 7 | +# Setup: see .github/SECRETS.md — add LOVABLE_WEBHOOK_URL in repo Actions secrets. |
| 8 | + |
| 9 | +name: Build and Push to Lovable |
| 10 | + |
| 11 | +on: |
| 12 | + push: |
| 13 | + branches: [main] |
| 14 | + workflow_dispatch: |
| 15 | + |
| 16 | +env: |
| 17 | + AZURE_WEBAPP_PACKAGE_PATH: "." |
| 18 | + NODE_VERSION: "20.x" |
| 19 | + |
| 20 | +permissions: |
| 21 | + contents: read |
| 22 | + |
| 23 | +jobs: |
| 24 | + build: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + steps: |
| 27 | + - name: Checkout |
| 28 | + uses: actions/checkout@v4 |
| 29 | + |
| 30 | + - name: Set up Node.js |
| 31 | + uses: actions/setup-node@v4 |
| 32 | + with: |
| 33 | + node-version: ${{ env.NODE_VERSION }} |
| 34 | + cache: "npm" |
| 35 | + |
| 36 | + - name: npm install, build, and test |
| 37 | + run: | |
| 38 | + npm ci |
| 39 | + npm run build --if-present |
| 40 | + npm run test --if-present |
| 41 | +
|
| 42 | + - name: Upload artifact for deployment job |
| 43 | + uses: actions/upload-artifact@v4 |
| 44 | + with: |
| 45 | + name: node-app |
| 46 | + path: . |
| 47 | + |
| 48 | + deploy: |
| 49 | + permissions: |
| 50 | + contents: none |
| 51 | + runs-on: ubuntu-latest |
| 52 | + needs: build |
| 53 | + if: secrets.LOVABLE_WEBHOOK_URL != '' |
| 54 | + environment: |
| 55 | + name: Development |
| 56 | + url: https://asperbeautyshop-com.lovable.app |
| 57 | + steps: |
| 58 | + - name: Download artifact from build job |
| 59 | + uses: actions/download-artifact@v4 |
| 60 | + with: |
| 61 | + name: node-app |
| 62 | + |
| 63 | + - name: Notify Lovable (push file changes for deploy) |
| 64 | + continue-on-error: true |
| 65 | + env: |
| 66 | + LOVABLE_WEBHOOK_URL: ${{ secrets.LOVABLE_WEBHOOK_URL }} |
| 67 | + run: | |
| 68 | + if [ "${{ github.event_name }}" = "push" ] && [ -f "$GITHUB_EVENT_PATH" ]; then |
| 69 | + ADDED=$(jq -r '.commits[].added[]?' "$GITHUB_EVENT_PATH" | sort | uniq | jq -R . | jq -s .) |
| 70 | + MODIFIED=$(jq -r '.commits[].modified[]?' "$GITHUB_EVENT_PATH" | sort | uniq | jq -R . | jq -s .) |
| 71 | + REMOVED=$(jq -r '.commits[].removed[]?' "$GITHUB_EVENT_PATH" | sort | uniq | jq -R . | jq -s .) |
| 72 | + else |
| 73 | + ADDED="[]" |
| 74 | + MODIFIED="[]" |
| 75 | + REMOVED="[]" |
| 76 | + fi |
| 77 | + COMPARE_URL="${{ github.event.compare }}" |
| 78 | + [ -z "$COMPARE_URL" ] && COMPARE_URL="https://github.com/${{ github.repository }}/commit/${{ github.sha }}" |
| 79 | + PAYLOAD=$(jq -n \ |
| 80 | + --arg repo "${{ github.repository }}" \ |
| 81 | + --arg commit "${{ github.sha }}" \ |
| 82 | + --arg sender "${{ github.actor }}" \ |
| 83 | + --arg url "$COMPARE_URL" \ |
| 84 | + --argjson added "$ADDED" \ |
| 85 | + --argjson modified "$MODIFIED" \ |
| 86 | + --argjson removed "$REMOVED" \ |
| 87 | + '{repo: $repo, commit: $commit, sender: $sender, compare_url: $url, added: $added, modified: $modified, removed: $removed}') |
| 88 | + echo "Sending to Lovable..." |
| 89 | + curl -s -f -X POST "$LOVABLE_WEBHOOK_URL" \ |
| 90 | + -H "Content-Type: application/json" \ |
| 91 | + -d "$PAYLOAD" || echo "Webhook call failed (non-fatal)." |
0 commit comments