Github provides secrets, whose values can be used in workflows. Unfortunately, the values of secrets is protected and we can't easily see it in the repo or debug it in the workflow as it is scrubbed.
Is there a way to define an "environment variable" in the repository that can be easily seen and debugged? My use case is for configuration that can be easily modified if the repo is forked.
You can store environment variables in an .env file like this:
FOO=bar
Then you can write code to append data from that file to $GITHUB_ENV:
name: CI
on:
workflow_dispatch:
jobs:
foo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: cat .env >> $GITHUB_ENV
- name: Use the value
run: echo $FOO
You'll need to do cat .env >> $GITHUB_ENV (and use actions/checkout) for each job where you need to access env vars from that file.
DO NOT STORE SECRETS IN .env -- use it only for storing configurations, etc.
Complete code: https://github.com/brc-dd/env-from-file
You can also change .env to something like .env.github to keep things more organized.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With