Interview Prep/GitHub Actions/Contexts, Expressions, Env & Outputs

How do `$GITHUB_ENV` and `$GITHUB_PATH` work, and when does a value become visible?

BeginnerConceptContexts, Expressions, Env & Outputs
Answer

Lines appended to $GITHUB_ENV become environment variables in subsequent steps of the same job, not the current step. Lines appended to $GITHUB_PATH are prepended to PATH for subsequent steps.

echo "IMAGE_TAG=sha-${GITHUB_SHA::7}" >> "$GITHUB_ENV"
echo "$HOME/.local/bin" >> "$GITHUB_PATH"

In the same step, also export IMAGE_TAG=... if you need it right away. Never write untrusted data to GITHUB_ENV: a newline lets an attacker set arbitrary variables.

All GitHub Actions questions Roadmap: GitHub Actions

More on Contexts, Expressions, Env & Outputs