posener / goreadme

Generate readme file from Go doc. Now available as a Github action!
MIT License
213 stars 31 forks source link

Do not make assumptions about environment (CI - Github Actions) #120

Open chrisgoffinet opened 2 years ago

chrisgoffinet commented 2 years ago

I can understand you were trying to make things more automatic but please replace the the check for at:

https://github.com/posener/goreadme/blob/master/cmd/goreadme/main.go#L120

To require this to be a flag instead of assuming CI is an environment variable being set by Github actions. This tripped me up because I didn't want to use your action because it tries to commit the changes. I opt'd out of using the action to run the tool directly, but my workflow was failing due to this CI assumption. I managed to get around this by overriding the env of CI to false but I would hate for others to run into this and get stuck.

I would suggest updating your github action to have an input for CI mode and the ability to skip commiting the updated README.

posener commented 2 years ago

Hey, sorry for the late reply. Can you explain in which environment you had CI=true? This is how Github Actions tells programs that they are running as Github Actions. See this doc

chrisgoffinet commented 2 years ago

Correct, I was aware. I was just mentioning it would be helpful to not assume things like CI, and instead put it behind a flag. The use case was that I am running goreadme in Github actions but I don't want to have this portion of the code ran:

https://github.com/posener/goreadme/blob/master/cmd/goreadme/main.go#L124

Coming back to this, I think it would be okay to assume CI but have a flag to disable the above if desired. I had to set CI: false to skip this.

yoanm commented 1 year ago

Hello 👋

First, thanks for you work, it's really helpful 👌

But indeed, assuming that CI=true means running the command under GHAction context is not accurate. See there for instance, travis uses the same env variable.

The following default environment variables are available to all builds.

CI=true

IMO, it would be great to separate the CLI command from the github action (=move what you are specifically doing for GHAction context inside a dedicated repo, or move the CLI command outside of this repo and keep only code not related to GHAction context, up to you) It's a bit scary to figure out by reading the code that command is actually relying on stuff named GITHUB_TOKEN, which are really sensitive values 😬 That being said, by default, github token is not available inside env variables, but it's anyway scary to read that in what seems to be a standalone CLI command

Meanwhile, I use CI: false, like mentioned above