Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property job_workflow_sha in context github is not available #2417

Open
mbeckh opened this issue Feb 5, 2023 · 8 comments
Open

Property job_workflow_sha in context github is not available #2417

mbeckh opened this issue Feb 5, 2023 · 8 comments
Labels
bug Something isn't working

Comments

@mbeckh
Copy link

mbeckh commented Feb 5, 2023

Describe the bug
The property github.job_workflow_sha is not set in a job using a reusable workflow.
Documentation at https://docs.github.com/en/actions/learn-github-actions/contexts#github-context states that "For jobs using a reusable workflow, the commit SHA for the reusable workflow file.".

To Reproduce
.github/workflows/test.yml:

name: Test
on:
  push:
jobs:
  test:
    uses: ./.github/workflows/reuse.yml

.github/workflows/reuse.yml:

name: Reuse
on:
  workflow_call:
jobs:
  reuse:
    runs-on: ubuntu-latest
    steps:
    - shell: bash
      run: echo 'github: ${{toJSON(github)}}'

The context github is printed, but there is no key job_workflow_sha. The output of ${{github.job_workflow_sha}} is empty.

The behavior is the same whether reuse.yml is in the same repository as test.yml or in a different repository.

Expected behavior
There is a key job_workflow_sha matching the commit SHA of the reusable workflow file as displayed in the job log under "Set up job" as "Uses: <owner>/<repository>/.github/workflows/reuse.yml@refs/heads/<branchname> (<SHA>)".

Runner Version and Platform

Runner version: 2.301.1
Platform: Ubuntu 22.04.1 LTS
Runner Image: ubuntu-22.04 20230129.2

What's not working?

The property job_workflow_sha is not available in the context github of the reusable workflow although the documentation states it should be there.

@mbeckh mbeckh added the bug Something isn't working label Feb 5, 2023
mbeckh added a commit to mbeckh/cmake-utils that referenced this issue Feb 5, 2023
mbeckh added a commit to mbeckh/cmake-utils that referenced this issue Feb 7, 2023
@roulettedares
Copy link

as a side note, I cannot find any context in which github.job_workflow_sha acutally works. ex: from the caller workflow

name: pr
on:
  pull_request:
    branches: [main]

env:
  WORKFLOW_REF_ROOT_ENV: ${{ github.job_workflow_sha }}

jobs:
  pullrequest:
    uses: ./.github/workflows/pullrequest.yml
    secrets: inherit
    with:
      workflow-ref: ${{ github.job_workflow_sha }}

results in blank inputs and missing ${{ env.WORKFLOW_REF_ROOT_ENV }}

Inputs
    workflow-ref:

@kkurczewski
Copy link

I checked documentation source code, seems this property is subject of some condition (contrary to other ones):

{%- ifversion actions-oidc-custom-claims %}
| `github.job_workflow_sha` | `string` | {% data reusables.actions.job-workflow-sha-description %} |
{%- endif %}

Can I kindly ask authors of this commit about a little more context about what this condition is about? How I can enable it?

cc: @jc-clark @lucascosti

@lucascosti
Copy link
Contributor

lucascosti commented Jul 4, 2023

Hi @kkurczewski, I don't work at GitHub anymore, so I'll let @jc-clark answer your question. 🙂 (👋 Hi Joe 😁)

@axherrm
Copy link

axherrm commented Jul 14, 2023

There is still no solution for this, is it?

@johnandersen777
Copy link

johnandersen777 commented Sep 13, 2023

Still hitting this: https://github.com/pdxjohnny/scitt-api-emulator/actions/runs/6178211970/job/16771062928#step:9:17

##[debug]Evaluating: github.job_workflow_sha
##[debug]Evaluating Index:
##[debug]..Evaluating github:
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'job_workflow_sha'
##[debug]=> null
##[debug]Result: null
Operating System
  Ubuntu
  22.04.3
  LTS
Runner Image
  Image: ubuntu-22.04
  Version: 20230911.1.0
  Included Software: https://github.com/actions/runner-images/blob/ubuntu22/20230911.1/images/linux/Ubuntu2204-Readme.md
  Image Release: https://github.com/actions/runner-images/releases/tag/ubuntu22%2F20230911.1

johnandersen777 pushed a commit to johnandersen777/scitt-api-emulator that referenced this issue Sep 13, 2023
Related: actions/runner#2417 (comment)
Signed-off-by: John Andersen <johnandersenpdx@gmail.com>
johnandersen777 pushed a commit to johnandersen777/scitt-api-emulator that referenced this issue Sep 13, 2023
Related: actions/runner#2417 (comment)
Signed-off-by: John Andersen <johnandersenpdx@gmail.com>
johnandersen777 pushed a commit to johnandersen777/scitt-api-emulator that referenced this issue Sep 13, 2023
Related: actions/runner#2417 (comment)
Signed-off-by: John Andersen <johnandersenpdx@gmail.com>
johnandersen777 pushed a commit to johnandersen777/scitt-api-emulator that referenced this issue Sep 13, 2023
Related: actions/runner#2417 (comment)
Signed-off-by: John Andersen <johnandersenpdx@gmail.com>
johnandersen777 pushed a commit to johnandersen777/scitt-api-emulator that referenced this issue Sep 14, 2023
Related: actions/runner#2417 (comment)
Signed-off-by: John Andersen <johnandersenpdx@gmail.com>
johnandersen777 pushed a commit to johnandersen777/scitt-api-emulator that referenced this issue Sep 14, 2023
Related: actions/runner#2417 (comment)
Signed-off-by: John Andersen <johnandersenpdx@gmail.com>
johnandersen777 pushed a commit to johnandersen777/scitt-api-emulator that referenced this issue Sep 14, 2023
Related: actions/runner#2417 (comment)
Signed-off-by: John Andersen <johnandersenpdx@gmail.com>
johnandersen777 pushed a commit to johnandersen777/scitt-api-emulator that referenced this issue Sep 14, 2023
Related: actions/runner#2417 (comment)
Signed-off-by: John Andersen <johnandersenpdx@gmail.com>
johnandersen777 pushed a commit to johnandersen777/scitt-api-emulator that referenced this issue Sep 14, 2023
Related: actions/runner#2417 (comment)
Signed-off-by: John Andersen <johnandersenpdx@gmail.com>
@ericsciple
Copy link
Collaborator

Apologies this is a documentation bug and job_workflow_sha is only supported as an OIDC claim. A PR to correct the documentation is in progress.

I would recommend the community feedback discussions as a place to request any missing product feature. Good to focus on the scenario, since would not only help prioritize but also may help determine a different solution.

@johnandersen777
Copy link

I found a workaround by requesting the token and extracting the claim. However, this only works on jobs which run within the repo’s context, not pull requests for example.

SteveLasker pushed a commit to scitt-community/scitt-api-emulator that referenced this issue Oct 18, 2023
* Add plugin helper entrypoint_style_load() to assist with loading auth middleware
* Add server CLI arg for Flask middleware loaded via entrypoint style load plugin helper
* OIDC auth middleware plugin
* Refactor test Service expose url with bound port to Flask app
* In preperation for use by flask test app used as OIDC endpoints
* Tests for OIDC based auth middleware
* Update pip, setuptools, wheel to avoid deprecation warning on dependency install.
* Example CI job for GitHub Actions OIDC authenticated notary
* Token is not available within pull_request context.
* Document OIDC authentication middleware usage with GitHub Actions
* Validation of OIDC claims via JSON schema validator

Related: slsa-framework/slsa-github-generator#131
Related: slsa-framework/slsa-github-generator#358
Related: actions/runner#2417 (comment)

Signed-off-by: John Andersen <johnandersenpdx@gmail.com>
johnandersen777 pushed a commit to johnandersen777/scitt-api-emulator that referenced this issue Nov 23, 2023
…unity#31)

* Add plugin helper entrypoint_style_load() to assist with loading auth middleware
* Add server CLI arg for Flask middleware loaded via entrypoint style load plugin helper
* OIDC auth middleware plugin
* Refactor test Service expose url with bound port to Flask app
* In preperation for use by flask test app used as OIDC endpoints
* Tests for OIDC based auth middleware
* Update pip, setuptools, wheel to avoid deprecation warning on dependency install.
* Example CI job for GitHub Actions OIDC authenticated notary
* Token is not available within pull_request context.
* Document OIDC authentication middleware usage with GitHub Actions
* Validation of OIDC claims via JSON schema validator

Related: slsa-framework/slsa-github-generator#131
Related: slsa-framework/slsa-github-generator#358
Related: actions/runner#2417 (comment)

Signed-off-by: John Andersen <johnandersenpdx@gmail.com>
@randallt21
Copy link

randallt21 commented Sep 10, 2024

Working solution here using this action ~ dariocurr/checkout-called
actions/toolkit#1264 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants