|
| 1 | +name: Deploy Cloud Functions |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [master] |
| 6 | + paths: |
| 7 | + - 'src/ingestion/**' |
| 8 | + - 'src/enrichment/**' |
| 9 | + - 'src/serving/**' |
| 10 | + |
| 11 | +env: |
| 12 | + PROJECT_ID: profitscout-lx6bb |
| 13 | + REGION: us-central1 |
| 14 | + RUNTIME: python312 |
| 15 | + |
| 16 | +jobs: |
| 17 | + detect-changes: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + outputs: |
| 20 | + ingestion: ${{ steps.changes.outputs.ingestion }} |
| 21 | + enrichment: ${{ steps.changes.outputs.enrichment }} |
| 22 | + serving: ${{ steps.changes.outputs.serving }} |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + fetch-depth: 2 |
| 27 | + |
| 28 | + - name: Detect changed paths |
| 29 | + id: changes |
| 30 | + run: | |
| 31 | + # Get changed files between HEAD and previous commit |
| 32 | + CHANGED=$(git diff --name-only HEAD~1 HEAD) |
| 33 | + |
| 34 | + echo "Changed files:" |
| 35 | + echo "$CHANGED" |
| 36 | + |
| 37 | + # Check which modules changed |
| 38 | + if echo "$CHANGED" | grep -q "^src/ingestion/"; then |
| 39 | + echo "ingestion=true" >> $GITHUB_OUTPUT |
| 40 | + else |
| 41 | + echo "ingestion=false" >> $GITHUB_OUTPUT |
| 42 | + fi |
| 43 | + |
| 44 | + if echo "$CHANGED" | grep -q "^src/enrichment/"; then |
| 45 | + echo "enrichment=true" >> $GITHUB_OUTPUT |
| 46 | + else |
| 47 | + echo "enrichment=false" >> $GITHUB_OUTPUT |
| 48 | + fi |
| 49 | + |
| 50 | + if echo "$CHANGED" | grep -q "^src/serving/"; then |
| 51 | + echo "serving=true" >> $GITHUB_OUTPUT |
| 52 | + else |
| 53 | + echo "serving=false" >> $GITHUB_OUTPUT |
| 54 | + fi |
| 55 | +
|
| 56 | + deploy-ingestion: |
| 57 | + needs: detect-changes |
| 58 | + if: needs.detect-changes.outputs.ingestion == 'true' |
| 59 | + runs-on: ubuntu-latest |
| 60 | + steps: |
| 61 | + - uses: actions/checkout@v4 |
| 62 | + |
| 63 | + - name: Authenticate to GCP |
| 64 | + uses: google-github-actions/auth@v2 |
| 65 | + with: |
| 66 | + credentials_json: ${{ secrets.GCP_SA_KEY }} |
| 67 | + |
| 68 | + - name: Set up Cloud SDK |
| 69 | + uses: google-github-actions/setup-gcloud@v2 |
| 70 | + |
| 71 | + - name: Deploy ingestion functions |
| 72 | + run: | |
| 73 | + echo "🚀 Deploying ingestion functions..." |
| 74 | + |
| 75 | + FUNCTIONS=( |
| 76 | + "run_price_populator" |
| 77 | + "sync_spy_price_history" |
| 78 | + "fetch_news" |
| 79 | + "fetch_options_chain" |
| 80 | + "run_technicals_collector" |
| 81 | + "refresh_stock_metadata" |
| 82 | + "run_calendar_events_loader" |
| 83 | + "fetch_transcripts" |
| 84 | + "extract_sec_filings" |
| 85 | + "load_financial_statements" |
| 86 | + "run_fundamentals_loader" |
| 87 | + "run_history_archiver" |
| 88 | + ) |
| 89 | + |
| 90 | + for fn in "${FUNCTIONS[@]}"; do |
| 91 | + echo " Deploying $fn..." |
| 92 | + gcloud functions deploy "$fn" \ |
| 93 | + --gen2 \ |
| 94 | + --region=${{ env.REGION }} \ |
| 95 | + --runtime=${{ env.RUNTIME }} \ |
| 96 | + --source=src/ingestion \ |
| 97 | + --entry-point="$fn" \ |
| 98 | + --trigger-http \ |
| 99 | + --allow-unauthenticated \ |
| 100 | + --timeout=540s \ |
| 101 | + --memory=1Gi || echo "⚠️ Failed to deploy $fn" |
| 102 | + done |
| 103 | +
|
| 104 | + deploy-enrichment: |
| 105 | + needs: detect-changes |
| 106 | + if: needs.detect-changes.outputs.enrichment == 'true' |
| 107 | + runs-on: ubuntu-latest |
| 108 | + steps: |
| 109 | + - uses: actions/checkout@v4 |
| 110 | + |
| 111 | + - name: Authenticate to GCP |
| 112 | + uses: google-github-actions/auth@v2 |
| 113 | + with: |
| 114 | + credentials_json: ${{ secrets.GCP_SA_KEY }} |
| 115 | + |
| 116 | + - name: Set up Cloud SDK |
| 117 | + uses: google-github-actions/setup-gcloud@v2 |
| 118 | + |
| 119 | + - name: Deploy enrichment functions |
| 120 | + run: | |
| 121 | + echo "🚀 Deploying enrichment functions..." |
| 122 | + |
| 123 | + FUNCTIONS=( |
| 124 | + "run_mda_analyzer" |
| 125 | + "run_transcript_analyzer" |
| 126 | + "run_financials_analyzer" |
| 127 | + "run_fundamentals_analyzer" |
| 128 | + "run_technicals_analyzer" |
| 129 | + "run_news_analyzer" |
| 130 | + "run_business_summarizer" |
| 131 | + "run_score_aggregator" |
| 132 | + "run_options_candidate_selector" |
| 133 | + "run_options_analyzer" |
| 134 | + "run_options_feature_engineering" |
| 135 | + "run_thesis_generator" |
| 136 | + ) |
| 137 | + |
| 138 | + for fn in "${FUNCTIONS[@]}"; do |
| 139 | + echo " Deploying $fn..." |
| 140 | + gcloud functions deploy "$fn" \ |
| 141 | + --gen2 \ |
| 142 | + --region=${{ env.REGION }} \ |
| 143 | + --runtime=${{ env.RUNTIME }} \ |
| 144 | + --source=src/enrichment \ |
| 145 | + --entry-point="$fn" \ |
| 146 | + --trigger-http \ |
| 147 | + --allow-unauthenticated \ |
| 148 | + --timeout=540s \ |
| 149 | + --memory=2Gi || echo "⚠️ Failed to deploy $fn" |
| 150 | + done |
| 151 | +
|
| 152 | + deploy-serving: |
| 153 | + needs: detect-changes |
| 154 | + if: needs.detect-changes.outputs.serving == 'true' |
| 155 | + runs-on: ubuntu-latest |
| 156 | + steps: |
| 157 | + - uses: actions/checkout@v4 |
| 158 | + |
| 159 | + - name: Authenticate to GCP |
| 160 | + uses: google-github-actions/auth@v2 |
| 161 | + with: |
| 162 | + credentials_json: ${{ secrets.GCP_SA_KEY }} |
| 163 | + |
| 164 | + - name: Set up Cloud SDK |
| 165 | + uses: google-github-actions/setup-gcloud@v2 |
| 166 | + |
| 167 | + - name: Deploy serving functions |
| 168 | + run: | |
| 169 | + echo "🚀 Deploying serving functions..." |
| 170 | + |
| 171 | + FUNCTIONS=( |
| 172 | + "run_social_media_poster" |
| 173 | + "run_performance_tracker_updater" |
| 174 | + "run_winners_dashboard_generator" |
| 175 | + "run_recommendations_generator" |
| 176 | + "run_sync_calendar_to_firestore" |
| 177 | + "run_sync_options_to_firestore" |
| 178 | + "run_sync_winners_to_firestore" |
| 179 | + "run_dashboard_generator" |
| 180 | + "run_data_cruncher" |
| 181 | + "run_page_generator" |
| 182 | + "run_price_chart_generator" |
| 183 | + "run_data_bundler" |
| 184 | + "run_sync_to_firestore" |
| 185 | + "run_sync_options_candidates_to_firestore" |
| 186 | + "run_sync_performance_tracker_to_firestore" |
| 187 | + "run_sync_spy_to_firestore" |
| 188 | + ) |
| 189 | + |
| 190 | + for fn in "${FUNCTIONS[@]}"; do |
| 191 | + echo " Deploying $fn..." |
| 192 | + gcloud functions deploy "$fn" \ |
| 193 | + --gen2 \ |
| 194 | + --region=${{ env.REGION }} \ |
| 195 | + --runtime=${{ env.RUNTIME }} \ |
| 196 | + --source=src/serving \ |
| 197 | + --entry-point="$fn" \ |
| 198 | + --trigger-http \ |
| 199 | + --allow-unauthenticated \ |
| 200 | + --timeout=540s \ |
| 201 | + --memory=1Gi || echo "⚠️ Failed to deploy $fn" |
| 202 | + done |
| 203 | +
|
| 204 | + notify: |
| 205 | + needs: [deploy-ingestion, deploy-enrichment, deploy-serving] |
| 206 | + if: always() |
| 207 | + runs-on: ubuntu-latest |
| 208 | + steps: |
| 209 | + - name: Deployment summary |
| 210 | + run: | |
| 211 | + echo "## Deployment Summary" >> $GITHUB_STEP_SUMMARY |
| 212 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 213 | + echo "| Module | Status |" >> $GITHUB_STEP_SUMMARY |
| 214 | + echo "|--------|--------|" >> $GITHUB_STEP_SUMMARY |
| 215 | + echo "| Ingestion | ${{ needs.deploy-ingestion.result || 'skipped' }} |" >> $GITHUB_STEP_SUMMARY |
| 216 | + echo "| Enrichment | ${{ needs.deploy-enrichment.result || 'skipped' }} |" >> $GITHUB_STEP_SUMMARY |
| 217 | + echo "| Serving | ${{ needs.deploy-serving.result || 'skipped' }} |" >> $GITHUB_STEP_SUMMARY |
0 commit comments