Skip to content

Commit

Permalink
docs(changeset): fix pypi publishing with token
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiechayes committed Oct 10, 2023
1 parent 88e8280 commit 2928426
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
5 changes: 5 additions & 0 deletions generator/konfig-dash/.changeset/great-rings-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'konfig-cli': patch
---

fix pypi publishing with token
22 changes: 12 additions & 10 deletions generator/konfig-dash/packages/konfig-cli/src/commands/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,20 @@ const publishScripts = {
token,
version,
gitlabRepositoryId,
skipTag,
}: {
test?: boolean
token?: string
version: string
gitlabRepositoryId?: string
skipTag?: boolean
}) => {
const repository = test ? '-r testpypi ' : ''
const credentials = token !== undefined ? `-u __token__ -p ${token} ` : ''
const gitTagCommands = generateGitTagCommands({
version,
generator: 'python',
skipTag,
})
const useGitlab = gitlabRepositoryId !== undefined
const gitlabAuth = useGitlab
Expand Down Expand Up @@ -543,8 +546,10 @@ export default class Publish extends Command {
generatorConfig.generator === 'python')
) {
const pythonConfig = python.parse(generatorConfig)
const usesToken =
pythonConfig.pypiApiTokenEnvironmentVariable !== undefined
const testPyPI = flags.test || pythonConfig.testPyPI
if (testPyPI) {
if (testPyPI && !usesToken) {
if (!process.env.TEST_TWINE_USERNAME)
CliUx.ux.error(
'Set TEST_TWINE_USERNAME environment variable to publish to PyPI (see https://twine.readthedocs.io/en/stable/index.html#environment-variables)'
Expand All @@ -556,7 +561,7 @@ export default class Publish extends Command {
// Override TWINE_USERNAME / PASWORD
process.env.TWINE_USERNAME = process.env.TEST_TWINE_USERNAME
process.env.TWINE_PASSWORD = process.env.TEST_TWINE_PASSWORD
} else {
} else if (!usesToken) {
if (!process.env.TWINE_USERNAME)
CliUx.ux.error(
'Set TWINE_USERNAME environment variable to publish to PyPI (see https://twine.readthedocs.io/en/stable/index.html#environment-variables)'
Expand All @@ -566,14 +571,10 @@ export default class Publish extends Command {
'Set TWINE_PASSWORD environment variable to publish to PyPI (see https://twine.readthedocs.io/en/stable/index.html#environment-variables)'
)
}
const token =
pythonConfig.pypiApiTokenEnvironmentVariable === undefined
? undefined
: process.env[pythonConfig.pypiApiTokenEnvironmentVariable]
if (
pythonConfig.pypiApiTokenEnvironmentVariable !== undefined &&
token === undefined
)
const token = usesToken
? process.env[pythonConfig.pypiApiTokenEnvironmentVariable as string]
: undefined
if (usesToken && token === undefined)
throw Error(
`Set ${pythonConfig.pypiApiTokenEnvironmentVariable} environment variable to publish to PyPI`
)
Expand All @@ -594,6 +595,7 @@ export default class Publish extends Command {
token,
version: pythonConfig.version,
gitlabRepositoryId: pythonConfig.gitlabRepositoryId,
skipTag: flags.skipTag,
}),
})
}
Expand Down

0 comments on commit 2928426

Please sign in to comment.