File tree Expand file tree Collapse file tree
supabase/functions/github-import Expand file tree Collapse file tree Original file line number Diff line number Diff line change 7777 SUPABASE_JWT_SECRET : ${{ secrets.SUPABASE_JWT_SECRET || secrets.POWERSYNC_SUPABASE_JWT_SECRET }}
7878 POWERGIT_EMAIL : ${{ secrets.POWERGIT_EMAIL }}
7979 POWERGIT_PASSWORD : ${{ secrets.POWERGIT_PASSWORD }}
80+ POWERSYNC_ORG : ${{ github.event.inputs.org }}
8081 POWERSYNC_DAEMON_PORT : 5030
8182 POWERSYNC_SUPABASE_ONLY : " true"
8283 run : |
8586 if [ -z "$SUPABASE_ANON_KEY" ]; then echo "Missing SUPABASE_ANON_KEY secret" && exit 1; fi
8687 if [ -z "$POWERGIT_EMAIL" ]; then echo "Missing POWERGIT_EMAIL secret" && exit 1; fi
8788 if [ -z "$POWERGIT_PASSWORD" ]; then echo "Missing POWERGIT_PASSWORD secret" && exit 1; fi
89+ case "${POWERSYNC_ORG:-}" in
90+ gh-*|github-*)
91+ if [ -z "$SUPABASE_SERVICE_ROLE_KEY" ]; then
92+ echo "Missing SUPABASE_SERVICE_ROLE_KEY secret (required to push to ${POWERSYNC_ORG})."
93+ echo "Add SUPABASE_SERVICE_ROLE_KEY (or POWERSYNC_SUPABASE_SERVICE_ROLE_KEY) to GitHub repository secrets and re-run."
94+ exit 1
95+ fi
96+ ;;
97+ esac
8898 nohup pnpm --filter @powersync-community/powergit-daemon start -- --port ${POWERSYNC_DAEMON_PORT:-5030} > daemon.log 2>&1 &
8999 echo $! > daemon.pid
90100 for i in $(seq 1 30); do
@@ -110,6 +120,7 @@ jobs:
110120 fi
111121 sleep 1
112122 done
123+ echo "Daemon supabase writer mode: $(echo "$STATUS_JSON" | jq -r '.context.supabaseWriterMode // ""')"
113124
114125 - name : Record import job running
115126 if : ${{ github.event.inputs.job_id != '' }}
Original file line number Diff line number Diff line change @@ -123,6 +123,20 @@ async function authenticateDaemonViaSupabasePassword({
123123 return devicePayload ;
124124 }
125125 const challengeId = extractChallengeId ( devicePayload ) ;
126+ if ( ! challengeId && devicePayload ?. status === 'pending' ) {
127+ const token = typeof devicePayload . token === 'string' && devicePayload . token . trim ( ) ? devicePayload . token . trim ( ) : null ;
128+ if ( token ) {
129+ return waitFor ( async ( ) => {
130+ const status = await fetch ( `${ baseUrl } /auth/status` )
131+ . then ( async ( res ) => ( res . ok ? ( ( await res . json ( ) . catch ( ( ) => null ) ) as DaemonAuthResponse | null ) : null ) )
132+ . catch ( ( ) => null ) ;
133+ if ( status ?. status === 'ready' && typeof status . token === 'string' && status . token . trim ( ) ) {
134+ return status ;
135+ }
136+ return null ;
137+ } , WAIT_TIMEOUT_MS ) ;
138+ }
139+ }
126140 if ( ! challengeId ) {
127141 const reason = devicePayload && 'reason' in devicePayload ? String ( ( devicePayload as any ) . reason ?? '' ) : '' ;
128142 throw new Error ( `Daemon did not return a device challenge. ${ reason } ` . trim ( ) ) ;
Original file line number Diff line number Diff line change @@ -597,6 +597,13 @@ export async function startDaemon(options: ResolveDaemonConfigOptions = {}): Pro
597597 if ( authMetadata ) {
598598 Object . assign ( context , authMetadata ) ;
599599 }
600+ const hasActiveSession = Boolean ( supabaseSession && authToken && ! isJwtExpired ( authToken , 5_000 ) ) ;
601+ context . supabaseWriterMode = writerUsesServiceRole
602+ ? 'service-role key'
603+ : hasActiveSession
604+ ? 'Supabase session'
605+ : 'anon/public key' ;
606+ context . supabaseWriterUsesServiceRole = writerUsesServiceRole ;
600607 return Object . keys ( context ) . length > 0 ? context : null ;
601608 } ;
602609
@@ -1053,9 +1060,13 @@ export async function startDaemon(options: ResolveDaemonConfigOptions = {}): Pro
10531060
10541061 const role = ( membership as { role ?: unknown } | null ) ?. role ;
10551062 if ( role !== 'admin' && role !== 'write' ) {
1063+ const isReservedImportOrg = orgId . startsWith ( 'gh-' ) || orgId . startsWith ( 'github-' ) ;
10561064 throw new Error (
10571065 `Not authorized to push to ${ orgId } /${ repoId } . ` +
1058- 'Ask an org admin to add you as a member with write access.' ,
1066+ 'Ask an org admin to add you as a member with write access.' +
1067+ ( isReservedImportOrg
1068+ ? ' (For GitHub imports into gh-*/github-* orgs, set SUPABASE_SERVICE_ROLE_KEY in CI so the daemon can write.)'
1069+ : '' ) ,
10591070 ) ;
10601071 }
10611072 }
You can’t perform that action at this time.
0 commit comments