refactor(sdk): move go/container decorators to codepathfinder package… #14
This file contains hidden or 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
| name: Deploy Rules to R2 | |
| # Required Secrets (same as stdlib-r2-upload.yml): | |
| # - R2_ACCOUNT_ID: Cloudflare R2 Account ID | |
| # - R2_ACCESS_KEY_ID: Cloudflare R2 Access Key ID | |
| # - R2_SECRET_ACCESS_KEY: Cloudflare R2 Secret Access Key | |
| # | |
| # These secrets are already configured for stdlib uploads and will be reused. | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'rules/**/*.py' | |
| - 'rules/**/*.yaml' | |
| - 'rules/**/manifest.json' | |
| - 'tools/process_rules_for_r2.py' | |
| - 'tools/upload_rules_to_r2.sh' | |
| workflow_dispatch: # Allow manual trigger | |
| inputs: | |
| environment: | |
| description: 'Target environment' | |
| required: false | |
| default: 'production' | |
| type: choice | |
| options: | |
| - production | |
| jobs: | |
| process-and-upload: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Process rules | |
| run: | | |
| python3 tools/process_rules_for_r2.py \ | |
| --rules-dir ./rules \ | |
| --output-dir ./dist/rules \ | |
| --base-url https://assets.codepathfinder.dev/rules | |
| echo "📊 Processing summary:" | |
| find dist/rules -type f -name "*.zip" -exec ls -lh {} \; | |
| - name: Upload to R2 | |
| env: | |
| R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }} | |
| AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }} | |
| run: | | |
| # Construct R2 endpoint from account ID (same as stdlib workflow) | |
| export R2_ENDPOINT="https://${R2_ACCOUNT_ID}.r2.cloudflarestorage.com" | |
| # Install AWS CLI if not present | |
| if ! command -v aws &> /dev/null; then | |
| curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" | |
| unzip -q awscliv2.zip | |
| sudo ./aws/install | |
| fi | |
| # Run upload script (non-interactive in CI) | |
| export UPLOAD_CONFIRMED=yes | |
| bash tools/upload_rules_to_r2.sh ./dist/rules | |
| - name: Upload artifacts (for debugging) | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: processed-rules | |
| path: dist/rules/ | |
| retention-days: 7 | |
| - name: Purge Cloudflare cache | |
| if: success() | |
| env: | |
| CLOUDFLARE_ZONE_ID: ${{ secrets.CLOUDFLARE_ZONE_ID }} | |
| CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| run: | | |
| if [ -n "$CLOUDFLARE_ZONE_ID" ] && [ -n "$CLOUDFLARE_API_TOKEN" ]; then | |
| # Count files to purge | |
| FILE_COUNT=$(find dist/rules -name "*.zip" | wc -l | tr -d ' ') | |
| echo "🔄 Purging Cloudflare cache for $FILE_COUNT rule bundle(s)..." | |
| # Build JSON array of file URLs to purge | |
| FILES_JSON="[" | |
| FIRST=true | |
| find dist/rules -name "*.zip" | while read -r zipfile; do | |
| # Extract relative path from dist/rules/ | |
| relative_path="${zipfile#dist/rules/}" | |
| url="https://assets.codepathfinder.dev/rules/${relative_path}" | |
| if [ "$FIRST" = true ]; then | |
| FILES_JSON="${FILES_JSON}\"${url}\"" | |
| FIRST=false | |
| else | |
| FILES_JSON="${FILES_JSON},\"${url}\"" | |
| fi | |
| done | |
| FILES_JSON="${FILES_JSON}]" | |
| # Purge cache via Cloudflare API (suppress response to avoid leaking sensitive data) | |
| HTTP_CODE=$(curl -s -w "%{http_code}" -o /tmp/cf_response.json \ | |
| -X POST "https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE_ID/purge_cache" \ | |
| -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ | |
| -H "Content-Type: application/json" \ | |
| --data "{\"files\":${FILES_JSON}}") | |
| # Check if purge was successful (don't print response body) | |
| if [ "$HTTP_CODE" = "200" ] && grep -q '"success":true' /tmp/cf_response.json 2>/dev/null; then | |
| echo "✅ Cache purged successfully for $FILE_COUNT bundle(s)" | |
| else | |
| echo "⚠️ Cache purge failed (HTTP $HTTP_CODE) - non-critical" | |
| echo "Files will be available after cache expires (24h)" | |
| fi | |
| # Clean up response file | |
| rm -f /tmp/cf_response.json | |
| else | |
| echo "⚠️ Cloudflare credentials not configured - skipping cache purge" | |
| echo "Add CLOUDFLARE_ZONE_ID and CLOUDFLARE_API_TOKEN secrets to enable automatic cache purging" | |
| echo "Files will be available after cache expires (24h)" | |
| fi | |
| - name: Trigger website deploy | |
| if: success() | |
| # This step will be implemented in PR-07 | |
| run: | | |
| echo "Website deploy hook will be added in PR-07" | |
| # curl -X POST ${{ secrets.VERCEL_DEPLOY_HOOK }} | |
| - name: Summary | |
| if: success() | |
| run: | | |
| echo "### ✅ Rules deployed successfully" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Bundles uploaded:**" >> $GITHUB_STEP_SUMMARY | |
| find dist/rules -name "*.zip" -exec basename {} \; | sort >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Manifest URL:** https://assets.codepathfinder.dev/rules/manifest.json" >> $GITHUB_STEP_SUMMARY |