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.
More on Workflow Anatomy & Execution Model
Define workflow, run, job, step, action and runner in one line each.BeginnerWhat is the minimum valid workflow file?BeginnerWhere must workflow files live, and does the file extension matter?BeginnerWhich version of the workflow file does GitHub use for a given run?IntermediateWhat does a GitHub-hosted runner give you at the start of a job?BeginnerShould you use `ubuntu-latest` or `ubuntu-24.04`?Beginner