I'm using React and firebase. I have a .env
file with my secrets stored at the root of my project.
How can I access the .env
file in the GitHub workflow yml file.
How should I proceed as best practice?
I'm using React and firebase. I have a .env
file with my secrets stored at the root of my project.
How can I access the .env
file in the GitHub workflow yml file.
How should I proceed as best practice?
Checking that into your GitHub project is a super bad idea. Added emphasis there because once keys are in your git repository you're basically in huge trouble and it is a massive hassle to undo. You never, ever want to commit keys to your repository. Just don't.1
Instead what you need to do is make use of GitHub Secrets either at your organization/personal level, where they can apply to your projects by default, or per-project. These can be used within GitHub actions as things like:
${{ secrets.SECRET_NAME }}
Where those will be substituted based on the secret value.
GitHub Secrets are like a secure2 version of your .env
file variables.
1 You may think having a private repository protects you here, but it may not. Other team members may download this and inadvertently push it somewhere else. You may open-source it later without realizing. Mistakes happen because you assumed you'd never expose these keys.
2 Of course these are only as secure as GitHub is, and they could be exposed by someone with a sufficiently high level of access even if GitHub makes it difficult to see them casually.
You should never commit a .env files with secret key.
For this, you can use GitHub encrypted secrets.