I need to extract the application version from pyproject.toml 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
Write the variable assignment to the workflow environment file. Variables added this way are available in subsequent steps: `echo "APP_VERSION=$(awk -F'"' '/^version[[:space:]]*=/ {print $2; exit}' pyproject.toml)" >> "$GITHUB_ENV"`. Then a later step can use `echo "The app version is: $APP_VERSION"`. If the file cannot be found, check the step's working directory or use the correct relative path to `pyproject.toml`.
If your project uses Poetry or uv, their built-in version commands may be more reliable than parsing the TOML file with awk. For example, `poetry version -s` or `uv version --short` can return the project version, which you can then append to the workflow environment file in the same way.
Those are command-line tools rather than workflow actions, so they need to be installed or already available in the runner before you call them.

The command runs from the repository workspace by default, so a path issue usually means pyproject.toml is in a subdirectory. Print the current directory and list files, or reference the file explicitly, such as `path/to/pyproject.toml`.