Skip to content

Commit

Permalink
Fix auth in publish to npm
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Nov 20, 2024
1 parent 614497e commit 15eae25
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 2 additions & 0 deletions tag_publish/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ def _handle_docker_publish(
success = True
docker_config = config.get("docker", {})
if docker_config:
sys.stdout.flush()
sys.stderr.flush()
if docker_config.get("auto_login", tag_publish.configuration.DOCKER_AUTO_LOGIN_DEFAULT):
subprocess.run(
[
Expand Down
5 changes: 2 additions & 3 deletions tag_publish/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,17 @@ def node(
is_github = repo_config["server"] == "npm.pkg.github.com"
old_npmrc = None
npmrc_filename = os.path.expanduser("~/.npmrc")
env = {**os.environ}
if is_github:
old_npmrc = None
if os.path.exists(npmrc_filename):
with open(npmrc_filename, encoding="utf-8") as open_file:
old_npmrc = open_file.read()
with open(npmrc_filename, "w", encoding="utf-8") as open_file:
open_file.write(f"//npm.pkg.github.com/:_authToken={os.environ['GITHUB_TOKEN']}\n")
open_file.write(f"registry=https://{repo_config['server']}\n")
open_file.write("always-auth=true\n")
env["NODE_AUTH_TOKEN"] = os.environ["GITHUB_TOKEN"]

subprocess.run(["npm", "publish", *([] if publish else ["--dry-run"])], cwd=cwd, check=True, env=env)
subprocess.run(["npm", "publish", *([] if publish else ["--dry-run"])], cwd=cwd, check=True)

if is_github:
if old_npmrc is None:
Expand Down

0 comments on commit 15eae25

Please sign in to comment.