11import { execSync } from 'child_process'
22; ( async ( ) => {
3+ // Set remote to use GitHub App token
34 if ( process . env . RELEASE_GITHUB_TOKEN ) {
45 const remoteUrl = `https://x-access-token:${ process . env . RELEASE_GITHUB_TOKEN } @github.com/supabase/supabase-js.git`
56 execSync ( `git remote set-url origin "${ remoteUrl } "` )
67 }
78
8- // releaseChangelog should use the GitHub token with permission for tagging
9- // before switching the token, backup the GITHUB_TOKEN so that it
10- // can be restored afterwards and used by releasePublish. We can't use the same
11- // token, because releasePublish wants a token that has the id_token: write permission
12- // so that we can use OIDC for trusted publishing
9+ // Backup GITHUB_TOKEN for later restore
1310 const gh_token_bak = process . env . GITHUB_TOKEN
1411 process . env . GITHUB_TOKEN = process . env . RELEASE_GITHUB_TOKEN
15- // backup original auth header
16- const originalAuth = execSync ( 'git config --local http.https://github.com/.extraheader' )
17- . toString ( )
18- . trim ( )
19- // switch the token used
12+
13+ // Backup original auth header
14+ let originalAuth = ''
15+ try {
16+ originalAuth = execSync ( 'git config --local http.https://github.com/.extraheader' )
17+ . toString ( )
18+ . trim ( )
19+ } catch {
20+ // Might not exist, ignore
21+ }
22+
23+ // Switch the token used for git http requests
2024 const authHeader = `AUTHORIZATION: basic ${ Buffer . from ( `x-access-token:${ process . env . RELEASE_GITHUB_TOKEN } ` ) . toString ( 'base64' ) } `
2125 execSync ( `git config --local http.https://github.com/.extraheader "${ authHeader } "` )
2226
23- // npm publish with OIDC
24- // not strictly necessary to restore the header but do it incase we require it later
25- execSync ( `git config --local http.https://github.com/.extraheader "${ originalAuth } "` )
26- // restore the GH token
27+ // [Your code for changelog/tagging or npm publish goes here...]
28+
29+ // Restore the header (if it existed) and GH token
30+ if ( originalAuth ) {
31+ execSync ( `git config --local http.https://github.com/.extraheader "${ originalAuth } "` )
32+ } else {
33+ execSync ( `git config --local --unset http.https://github.com/.extraheader || true` )
34+ }
2735 process . env . GITHUB_TOKEN = gh_token_bak
2836
2937 // ---- Create release branch + PR ----
30- // switch back to the releaser GitHub token
38+ // Switch back to the releaser GitHub token
3139 process . env . GITHUB_TOKEN = process . env . RELEASE_GITHUB_TOKEN
3240
33- const branchName = `release-test}`
41+ // Remove ALL credential helpers to ensure only our token is used
42+ try {
43+ execSync ( 'git config --system --unset credential.helper || true' )
44+ } catch { }
45+ try {
46+ execSync ( 'git config --global --unset credential.helper || true' )
47+ } catch { }
48+ try {
49+ execSync ( 'git config --local --unset credential.helper || true' )
50+ } catch { }
51+
52+ // Ensure remote is set again before push
53+ if ( process . env . RELEASE_GITHUB_TOKEN ) {
54+ const remoteUrl = `https://x-access-token:${ process . env . RELEASE_GITHUB_TOKEN } @github.com/supabase/supabase-js.git`
55+ execSync ( `git remote set-url origin "${ remoteUrl } "` )
56+ }
57+
58+ const branchName = `release-test`
3459
3560 try {
3661 execSync ( `git checkout -b ${ branchName } ` )
@@ -45,14 +70,9 @@ import { execSync } from 'child_process'
4570 console . log ( 'No changes to commit' )
4671 }
4772
48- if ( process . env . RELEASE_GITHUB_TOKEN ) {
49- const remoteUrl = `https://x-access-token:${ process . env . RELEASE_GITHUB_TOKEN } @github.com/supabase/supabase-js.git`
50- execSync ( `git remote set-url origin "${ remoteUrl } "` )
51- }
52-
5373 execSync ( `git push origin ${ branchName } ` )
5474
55- // Open PR using GitHub CLI
75+ // Open PR using GitHub CLI (GH_TOKEN is automatically picked up in CI)
5676 execSync (
5777 `gh pr create --base master --head ${ branchName } --title "chore(repo): test permissions" --body "chore(repo): test permissions"` ,
5878 { stdio : 'inherit' }
0 commit comments