Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show gpg output in server/client in publish (fix #387) #2059

Merged
merged 3 commits into from
Oct 8, 2022

Conversation

lolgab
Copy link
Member

@lolgab lolgab commented Oct 7, 2022

Avoid using os.Inherit which is known to break the output in server/client mode.

Fixes #387
Checked manually and the errors now appear with and without -i.

Avoid using `os.Inherit` which is known to break the output in
server/client mode.
@lolgab lolgab marked this pull request as ready for review October 7, 2022 20:54
Copy link
Member

@lefou lefou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch. This change makes sense. One thing though...

@@ -174,8 +175,7 @@ class SonatypePublisher(
val fileName = file.toString
val command = "gpg" +: args :+ fileName

os.proc(command.map(v => v: Shellable))
.call(stdin = os.Inherit, stdout = os.Inherit, stderr = os.Inherit)
Jvm.runSubprocess(command, Map.empty[String, String], workingDir = null)
Copy link
Member

@lefou lefou Oct 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you setting workingDir explicitly to null? (The current implementation is handling it as os.pwd.) Besides being ugly and non-idiomatic Scala, it may not always be the right location. I think using T.workspace is the better option here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure the current implementation is handling as os.pwd?
My understanding is that we are calling os.proc() which by default uses null as cwd
https://github.com/com-lihaoyi/os-lib/blob/main/os/src-jvm/ProcessOps.scala#L53

To better match the current behavior I need to pass sys.env as the env instead of an empty Map.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think so.

https://github.com/com-lihaoyi/os-lib/blob/6b31f388799743b1410110e474a47ac372aa4be4/os/src-jvm/ProcessOps.scala#L120

But it's an undocumented (I think) implementation detail, so I'd prefer to make it explicit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the current env should come via T.env, as sys.env might be stale in server-mode, and this whole PR is about improving server-mode, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right!
When cwd is null it fallbacks to os.pwd:

@ os.proc("pwd").call(cwd = null).out.text
res1: String = """/Users/lorenzo
"""

@ os.proc("pwd").call(cwd = os.pwd).out.text
res2: String = """/Users/lorenzo
"""

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, SonatypePublisher doesn't know Ctx and can't access T.workspace or T.env. Should I deprecate the APIs and define new ones that receive implicit ctx: Ctx? It's a bit of work though

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the class was already receiving a Logger explicitly via T.log, I added another two parameters, workspace and env and I'm passing T.workspace and T.env. In the deprecated constructor, I'm using sys.env and os.pwd instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only issue I see with this approach is, that there is a chance the created instance is used when the context is no longer valid. Should be no issue for Ctx.workspace or Ctx.log (although misleading) , but Ctx.dest of Ctx.env could be already invalid.

As a compromise, we can keep it this way for now, but schedule a rework of the Publisher API to the next major release. I already have a tracker ticket for that:

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the issue.
Currently, we create a fresh instance of SonatypePublisher every time so it's not an issue internally. But we can change the API when we are in the next breaking window (0.11.x)

- Deprecate old constructor and provide previous behavior via sys.env
  and os.pwd
@lolgab lolgab requested a review from lefou October 8, 2022 09:12
@lefou lefou changed the title Fix #387 Show gpg output in server/client in publish Show gpg output in server/client in publish (fix #387) Oct 8, 2022
Copy link
Member

@lefou lefou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thank you!

@lefou lefou merged commit c985ef8 into main Oct 8, 2022
@lefou lefou deleted the fix-387-avoid-os-inherit branch October 8, 2022 13:25
@lefou lefou added this to the 0.10.8 milestone Oct 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The publish task should display an error message when the user does not have a gpg secret key
2 participants