Home > Software engineering >  How do I change values in a file after publishing to GitHub?
How do I change values in a file after publishing to GitHub?

Time:07-02

I have a Python project that I am looking to publish on GitHub. This project has a couple of variables in one of the files that needs to have their values obfuscated. Ie: API Key, user/password, etc.

My test code has those variables filled with my own data, but I want to boilerplate them when I push changes, for obvious reasons.

Would I be on the right track looking at a GitHub action to accomplish this? If so, any pointers towards what kind of action I should be looking for that is most appropriate for this kind of task?

CodePudding user response:

You should look into dotenv, which allows you to have a .env file or to have OS environment vars set to pull those private information to use in your code without have it set directly. One good tool for this is pydantic BaseSettings, which you should install via:

pip install pydantic[dotenv]

One nice thing I like about pydantic is that you can either have a .env or have environment variables, it will work.

If you have Continuous Integration (CI), you can add GitHub Secrets, which can be pulled in for your test runs with private API keys. You'll need to properly call them with GitHub contexts.

CodePudding user response:

Don't put those values in your code. Read them from an environment variable or from a file instead. Then whoever wants to use your projects only needs to provide said env vars or said file. Check Keep specific git branch offline.
GitHub actions seems overcomplicated imo. Keep in mind that if you already made a commit with those to-be-obfuscated variables, then they will be visible by going to those commits

  • Related