Interview Prep/GitHub Actions/Workflow Anatomy & Execution Model

Why is there both `${{ github.sha }}` and `$GITHUB_SHA`, and when do you prefer each?

IntermediateConceptWorkflow Anatomy & Execution Model
Answer

${{ github.sha }} is expanded by GitHub before the script reaches the runner, so it works anywhere in YAML (if, with, runs-on, concurrency). $GITHUB_SHA is an environment variable read by the shell at runtime. Inside run: scripts prefer environment variables: they are not subject to script injection and they keep the script readable. For non-default contexts (github.event.pull_request.title), map them through env: first.

All GitHub Actions questions Roadmap: GitHub Actions

More on Workflow Anatomy & Execution Model