1
1
import { execSync } from 'child_process'
2
2
; ( async ( ) => {
3
+ // Set remote to use GitHub App token
3
4
if ( process . env . RELEASE_GITHUB_TOKEN ) {
4
5
const remoteUrl = `https://x-access-token:${ process . env . RELEASE_GITHUB_TOKEN } @github.com/supabase/supabase-js.git`
5
6
execSync ( `git remote set-url origin "${ remoteUrl } "` )
6
7
}
7
8
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
13
10
const gh_token_bak = process . env . GITHUB_TOKEN
14
11
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
20
24
const authHeader = `AUTHORIZATION: basic ${ Buffer . from ( `x-access-token:${ process . env . RELEASE_GITHUB_TOKEN } ` ) . toString ( 'base64' ) } `
21
25
execSync ( `git config --local http.https://github.com/.extraheader "${ authHeader } "` )
22
26
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
+ }
27
35
process . env . GITHUB_TOKEN = gh_token_bak
28
36
29
37
// ---- Create release branch + PR ----
30
- // switch back to the releaser GitHub token
38
+ // Switch back to the releaser GitHub token
31
39
process . env . GITHUB_TOKEN = process . env . RELEASE_GITHUB_TOKEN
32
40
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`
34
59
35
60
try {
36
61
execSync ( `git checkout -b ${ branchName } ` )
@@ -45,14 +70,9 @@ import { execSync } from 'child_process'
45
70
console . log ( 'No changes to commit' )
46
71
}
47
72
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
-
53
73
execSync ( `git push origin ${ branchName } ` )
54
74
55
- // Open PR using GitHub CLI
75
+ // Open PR using GitHub CLI (GH_TOKEN is automatically picked up in CI)
56
76
execSync (
57
77
`gh pr create --base master --head ${ branchName } --title "chore(repo): test permissions" --body "chore(repo): test permissions"` ,
58
78
{ stdio : 'inherit' }
0 commit comments