I would like to upload .env file to a build in Github Actions. Is there any way I can do it?
1 Answer
It would be easier to store secrets in either secrets or specific environments in the repo:
Secrets:
https://github.com/**account_name**/**repo_name**/settings/secrets/actions
Environments:
https://github.com/**account_name**/**repo_name**/settings/environments
You can then access the secrets directly or generate an .env file when the GitHub actions runs.
In the workflow file access secrets with ${{ secrets.TOKEN }}
or generate an .env file and save secrets in there:
- name: do some stuff
run: |
touch .env
echo TOKEN='${{ secrets.TOKEN }}' >> .env
...etc
If using environments to store secrets, don't forget to declare which environment is being used by that job! (documentation)