|
| 1 | +name: Ping Supabase to Prevent Pausing |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 9 * * 1,4' # Runs at 9:00 AM UTC every Monday and Thursday |
| 6 | + workflow_dispatch: # Allows manual triggering from the GitHub UI |
| 7 | + |
| 8 | +jobs: |
| 9 | + ping: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + # Step 1: Checkout the repository |
| 14 | + - name: Checkout repository |
| 15 | + uses: actions/checkout@v3 |
| 16 | + |
| 17 | + # Step 2: Set up Node.js |
| 18 | + - name: Set up Node.js |
| 19 | + uses: actions/setup-node@v3 |
| 20 | + with: |
| 21 | + node-version: '18' # Use Node.js 18 |
| 22 | + |
| 23 | + # Step 3: Install Supabase Client |
| 24 | + - name: Install Supabase Client |
| 25 | + run: npm install @supabase/supabase-js --force |
| 26 | + |
| 27 | + # Step 4: Ping Supabase |
| 28 | + - name: Ping Supabase |
| 29 | + env: |
| 30 | + SUPABASE_URL: ${{ secrets.NEXT_PUBLIC_SUPABASE_URL }} # Supabase project URL |
| 31 | + SUPABASE_KEY: ${{ secrets.NEXT_SERVICE_ROLE_KEY }} # Supabase service role key |
| 32 | + run: | |
| 33 | + node -e " |
| 34 | + (async () => { |
| 35 | + try { |
| 36 | + // Debugging: Log environment variables (optional) |
| 37 | + console.log('Supabase URL:', process.env.SUPABASE_URL); |
| 38 | + console.log('Supabase Key:', process.env.SUPABASE_KEY); |
| 39 | +
|
| 40 | + // Import Supabase client |
| 41 | + const { createClient } = require('@supabase/supabase-js'); |
| 42 | + const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_KEY); |
| 43 | +
|
| 44 | + // Ping Supabase by querying a table (e.g., 'songs') |
| 45 | + const { data, error } = await supabase.from('record').select('*').limit(10); |
| 46 | +
|
| 47 | + // Handle errors |
| 48 | + if (error) throw error; |
| 49 | +
|
| 50 | + // Log success |
| 51 | + console.log('Ping successful:', data); |
| 52 | + } catch (err) { |
| 53 | + // Log and exit with error |
| 54 | + console.error('Error pinging Supabase:', err.message); |
| 55 | + process.exit(1); |
| 56 | + } |
| 57 | + })(); |
| 58 | + " |
0 commit comments