Skip to content

Commit 0a1e1cb

Browse files
committed
fix(ci): handle missing git auth header in release-canary script
1 parent 248ac09 commit 0a1e1cb

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

scripts/release-canary.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,14 @@ import { execSync } from 'child_process'
4040
// so that we can use OIDC for trusted publishing
4141
const gh_token_bak = process.env.GITHUB_TOKEN
4242
process.env.GITHUB_TOKEN = process.env.RELEASE_GITHUB_TOKEN
43-
// backup original auth header
44-
const originalAuth = execSync('git config --local http.https://github.com/.extraheader')
45-
.toString()
46-
.trim()
43+
// backup original auth header if exists
44+
let originalAuth = ''
45+
try {
46+
originalAuth = execSync('git config --local http.https://github.com/.extraheader')
47+
.toString()
48+
.trim()
49+
} catch {}
50+
4751
// switch the token used
4852
const authHeader = `AUTHORIZATION: basic ${Buffer.from(`x-access-token:${process.env.RELEASE_GITHUB_TOKEN}`).toString('base64')}`
4953
execSync(`git config --local http.https://github.com/.extraheader "${authHeader}"`)
@@ -56,8 +60,12 @@ import { execSync } from 'child_process'
5660
})
5761

5862
// npm publish with OIDC
59-
// not strictly necessary to restore the header but do it incase we require it later
60-
execSync(`git config --local http.https://github.com/.extraheader "${originalAuth}"`)
63+
// not strictly necessary to restore the header but do it incase we require it later
64+
if (originalAuth) {
65+
execSync(`git config --local http.https://github.com/.extraheader "${originalAuth}"`)
66+
} else {
67+
execSync('git config --local --unset http.https://github.com/.extraheader || true')
68+
}
6169
// restore the GH token
6270
process.env.GITHUB_TOKEN = gh_token_bak
6371

0 commit comments

Comments
 (0)