<p>I found <a href="https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/re-running-workflows-and-jobs" rel="nofollow noreferrer">this</a> which says:</p>
<blockquote>
<p>Re-running a workflow or jobs in a workflow uses the same GITHUB_SHA (commit SHA) and GITHUB_REF</p>
</blockquote>
<p>Stands to reason that if it is stable over re-runs, it'll be stable for the life of the workflow?</p>

CC BY-SA 4.0
2024-08-22T06:03:18.853Z
2024-08-22T06:03:18.853Z
Adam A
<p>I have a workflow with multiple jobs and jobs that use: another workflow via a workflow_call. The workflows are all in the same repo that is being checked out.
If the underlying ref is modified during this workflow, will the actions/checkout in all jobs see the same head commit?</p>
<p>In actions checkout I can see <a href="https://github.com/actions/checkout/blob/96f53100ba2a5449eb71d2e6604bbcd94b9449b5/src/input-helper.ts#L60C1-L72C4" rel="nofollow noreferrer">this code</a>:</p>
<pre><code>  result.ref = core.getInput('ref')
  if (!result.ref) {
    if (isWorkflowRepository) {
      result.ref = github.context.ref
      result.commit = github.context.sha

      // Some events have an unqualifed ref. For example when a PR is merged (pull_request closed event),
      // the ref is unqualifed like &quot;main&quot; instead of &quot;refs/heads/main&quot;.
      if (result.commit &amp;&amp; result.ref &amp;&amp; !result.ref.startsWith('refs/')) {
        result.ref = `refs/heads/${result.ref}`
      }
    }
  }
</code></pre>
<p>And other source in the repo will use <code>+${commit}:...</code> as the refspec if result.commit is set, so I know that if the commit is set, then it will be used by checkout by default.</p>
<p>My question then is about <code>github.context.sha</code> - is that stable between the jobs and workflow_calls? <a href="https://github.com/actions/toolkit/blob/main/packages/github/src/context.ts#L42" rel="nofollow noreferrer">The source</a> for that value is:
<code>this.sha = process.env.GITHUB_SHA as string</code></p>
<p>But I'm not sure how to track further than that.</p>
<p>Is $GITHUB_SHA guaranteed to be stable, specifically for push and workflow_dispatch events, for the life of the workflow? If so, it makes my life a lot simpler. For push events, there is a head_commit in the event payload so I feel like that would be stable. For workflow_dispatch events there is no such field in the payload, so I'm uncertain when or how often GITHUB_SHA is re-evaluated. Once per workflow? Once per job?</p>
<p>What happens when you re-run jobs? Woudl GITHUB_SHA change?</p>
<p><em>Cross-post from <a href="https://github.com/orgs/community/discussions/136513" rel="nofollow noreferrer">https://github.com/orgs/community/discussions/136513</a> where I asked the same question.</em></p>

<github-actions>
GitHub Actions: Is $GITHUB_SHA stable for the life of a complex workflow?
Adam A
# GitHub Actions: Is $GITHUB_SHA stable for the life of a complex workflow?

(Asked by: username_0 on 2024-08-22)

I have a workflow with multiple jobs and jobs that use: another workflow via a workflow_call. The workflows are all in the same repo that is being checked out.
If the underlying ref is modified during this workflow, will the actions/checkout in all jobs see the same head commit?
In actions checkout I can see this code:
  result.ref = core.getInput('ref')
  if (!result.ref) {
    if (isWorkflowRepository) {
      result.ref = github.context.ref
      result.commit = github.context.sha

      // Some events have an unqualifed ref. For example when a PR is merged (pull_request closed event),
      // the ref is unqualifed like "main" instead of "refs/heads/main".
      if (result.commit && result.ref && !result.ref.startsWith('refs/')) {
        result.ref = `refs/heads/${result.ref}`
      }
    }
  }

And other source in the repo will use +${commit}:... as the refspec if result.commit is set, so I know that if the commit is set, then it will be used by checkout by default.
My question then is about github.context.sha - is that stable between the jobs and workflow_calls? The source for that value is:
this.sha = process.env.GITHUB_SHA as string
But I'm not sure how to track further than that.
Is $GITHUB_SHA guaranteed to be stable, specifically for push and workflow_dispatch events, for the life of the workflow? If so, it makes my life a lot simpler. For push events, there is a head_commit in the event payload so I feel like that would be stable. For workflow_dispatch events there is no such field in the payload, so I'm uncertain when or how often GITHUB_SHA is re-evaluated. Once per workflow? Once per job?
What happens when you re-run jobs? Woudl GITHUB_SHA change?
Cross-post from https://github.com/orgs/community/discussions/136513 where I asked the same question.

**Tags:** github-actions


---

## 1 answers

### Answer by username_0 on 2024-08-22. Score: 0

I found [this](https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/re-running-workflows-and-jobs) which says:

> Re-running a workflow or jobs in a workflow uses the same GITHUB\_SHA (commit SHA) and GITHUB\_REF

Stands to reason that if it is stable over re-runs, it'll be stable for the life of the workflow?


---

