I need to read the application version from my pyproject.toml file using this awk command: awk -F'"' '/^version[[:space:]]*=/ {print $2; exit}' pyproject.toml. What is the correct way to assign that command's output to an environment variable so I can use it in later workflow steps?
2 Answers
If the project uses Poetry or uv, their built-in version commands may be more reliable than parsing pyproject.toml with awk. For example, `poetry version -s` or `uv version --short` can print the version, and that output can be assigned with the same `$GITHUB_ENV` approach. These are command-line tools, not GitHub Actions themselves, so the corresponding tool must be installed and available on the runner.
Write the variable assignment to GitHub Actions' special environment file. Variables written to $GITHUB_ENV become available in subsequent steps, not later commands in the same step:
- name: Read app version
run: echo "APP_VERSION=$(awk -F'"' '/^version[[:space:]]*=/ {print $2; exit}' pyproject.toml)" >> "$GITHUB_ENV"
- name: Use app version
run: echo "The app version is $APP_VERSION"
If the file cannot be found, check the runner's current directory and repository layout. By default, the workflow runs from the checked-out repository root, so make sure a checkout step runs first and provide the relative path if pyproject.toml is in a subdirectory.
The file-not-found error may be caused by the repository not being checked out yet or by pyproject.toml being in a different directory. I’ll verify the checkout step and update the command with the correct relative path.

So those are CLI commands rather than actions, and I would need to install or configure Poetry or uv before using them in the workflow?