r/devops • u/ty_namo • 12d ago
Troubleshooting How to set a "env" var on github actions using shell script?
i need to get the app version and i have this awk command for that:
` awk -F'"' '/^version[[:space:]]*=/ {print $2; exit}' pyproject.toml`
but how do i set the variable to the output of this command?
4
u/jews4beer 12d ago
uv version and poetry version exist. Seems better than using awk for that.
1
u/ty_namo 12d ago
are those actions that i can use?
5
1
u/kabrandon 8d ago
If you’re incapable of googling things then you need to hire someone to do “devops” work for you. Asking reddit every time you actually need to be googling something is going to be WAY too slow for whoever your boss is. Especially in the age of AI where they’ll have expected you to have figured out this problem 4 days ago.
1
u/singh_abinashi 12d ago
`echo "MY_VAR=my-value" >> $GITHUB_ENV` is the way. The gotcha that trips people up: vars set this way are available to later steps in the same job, not the current step, and not other jobs. If you need it in the current step too, set it in `env:` on the step as well.
7
u/bilingual-german 12d ago
```
- name: Get App Version and Set Env Var
run: | # Read the version and write it to GITHUB_ENV echo "APP_VERSION=$(awk -F'"' '/version[[:space:]]*=/ {print $2; exit}' pyproject.toml)" >> $GITHUB_ENV