Tiryoh/gha-jobid-action

V1 Breaks Functionality

p0fi opened this issue ยท 16 comments

p0fi commented

๐Ÿ“– Description

After the update from version 0.1.2 to 1.0.0 the action does not work anymore. The action fails with the message

parse error, job_id is null. job name might be wrong. See https://github.com/Tiryoh/gha-jobid-action

The job name is correct and working without any changes if I use version 0.1.2 of this action.

Tiryoh commented

Hi @p0fi,

Thanks for raising this issue.
Could you provide a sample link or a job_name that causes an error?
Unfortunately I was not able to reproduce the error.
https://github.com/Tiryoh/gha-jobid-action/actions/runs/7030811544

p0fi commented

Unfortunately, I can't provide you with a link as those are company internal jobs. But the name of the job is Get Current Job URL which I think is not the problem. But the problem might be that this workflow is called via workflow_call?

As I said, if I pin the version to 0.1.2 it works, everything newer breaks.

Hello, @Tiryoh

I met the same error when using Tiryoh/gha-jobid-action@v1. In my workflow, I use a stragety matrix to traverse from CMake version 3.0~3.29 and master. However in these runs with as many as 30 strategies, there are always 1 or 2 runs that encounter this error when acquiring the job id.

And I found that this error happens randomly. Sometimes it happened in 3.9; sometimes it happened in 3.7, sometimes it happened in master...etc.

I cannot publish the repo I'm working now, but I can provide its debug logging messages when rerunning it. Can you see what might be the cause of this error?

Click to expand the log with debug logging
##[debug]Evaluating condition for step: 'Get the Current Job's ID'
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: Get the Current Job's ID
##[debug]Loading inputs
##[debug]Evaluating: steps.ggat.outputs.token
##[debug]Evaluating Index:
##[debug]..Evaluating Index:
##[debug]....Evaluating Index:
##[debug]......Evaluating steps:
##[debug]......=> Object
##[debug]......Evaluating String:
##[debug]......=> 'ggat'
##[debug]....=> Object
##[debug]....Evaluating String:
##[debug]....=> 'outputs'
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'token'
##[debug]=> '***'
##[debug]Result: '***'
##[debug]Evaluating: format('{0} / {1}', inputs.CALLER_JOB, github.job)
##[debug]Evaluating format:
##[debug]..Evaluating String:
##[debug]..=> '{0} / {1}'
##[debug]..Evaluating Index:
##[debug]....Evaluating inputs:
##[debug]....=> Object
##[debug]....Evaluating String:
##[debug]....=> 'CALLER_JOB'
##[debug]..=> 'schedule (3.9)'
##[debug]..Evaluating Index:
##[debug]....Evaluating github:
##[debug]....=> Object
##[debug]....Evaluating String:
##[debug]....=> 'job'
##[debug]..=> 'sphinx-update'
##[debug]=> 'schedule (3.9) / sphinx-update'
##[debug]Result: 'schedule (3.9) / sphinx-update'
##[debug]Loading env
Run Tiryoh/gha-jobid-action@v1
##[debug]Evaluating: inputs.github_token
##[debug]Evaluating Index:
##[debug]..Evaluating inputs:
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'github_token'
##[debug]=> '***'
##[debug]Result: '***'
##[debug]Evaluating: inputs.repository
##[debug]Evaluating Index:
##[debug]..Evaluating inputs:
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'repository'
##[debug]=> ''
##[debug]Result: ''
##[debug]Evaluating: inputs.run_id
##[debug]Evaluating Index:
##[debug]..Evaluating inputs:
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'run_id'
##[debug]=> ''
##[debug]Result: ''
##[debug]Evaluating: inputs.job_name
##[debug]Evaluating Index:
##[debug]..Evaluating inputs:
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'job_name'
##[debug]=> 'schedule (3.9) / sphinx-update'
##[debug]Result: 'schedule (3.9) / sphinx-update'
##[debug]Evaluating: inputs.per_page
##[debug]Evaluating Index:
##[debug]..Evaluating inputs:
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'per_page'
##[debug]=> ''
##[debug]Result: ''
##[debug]Evaluating: github.api_url
##[debug]Evaluating Index:
##[debug]..Evaluating github:
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'api_url'
##[debug]=> 'https://api.github.com'
##[debug]Result: 'https://api.github.com'
##[debug]Evaluating condition for step: 'run'
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: run
##[debug]Loading inputs
##[debug]Loading env
Run GITHUB_API="/repos/${INPUT_REPOSITORY:-${GITHUB_REPOSITORY}}/actions/runs/${INPUT_RUN_ID:-${GITHUB_RUN_ID}}/jobs"
  GITHUB_API="/repos/${INPUT_REPOSITORY:-${GITHUB_REPOSITORY}}/actions/runs/${INPUT_RUN_ID:-${GITHUB_RUN_ID}}/jobs"
  JOBINFO="$(curl --get -Ss -H "Authorization: ***" -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: [2](https://github.com/hwhsu1231/cmake-docs-l10n-draft1/actions/runs/8184410347/job/22379643251#step:16:2)022-11-28" "${GITHUB_BASEURL}${GITHUB_API}?per_page=${INPUT_PER_PAGE:-[3](https://github.com/hwhsu1231/cmake-docs-l10n-draft1/actions/runs/8184410347/job/22379643251#step:16:3)0}")"
  echo "${JOBINFO}" | grep "Resource not accessible by integration" &&  exit 1
  eval "$(echo ${JOBINFO} | jq -r --arg job_name "${INPUT_JOB_NAME}" '.jobs | map(select(.name == $job_name)) | .[0] | @sh "job_id=\(.id) html_url=\(.html_url)"')"
  echo ${job_id} | grep "null" > /dev/null && echo "parse error, job_id is ${job_id}. job name might be wrong. See https://github.com/Tiryoh/gha-jobid-action" && exit 1
  echo "job_id=${job_id}" >> $GITHUB_OUTPUT
  echo "html_url=${html_url}" >> $GITHUB_OUTPUT
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    INPUT_GITHUB_TOKEN: ***
    INPUT_REPOSITORY: 
    INPUT_RUN_ID: 
    INPUT_JOB_NAME: schedule (3.9) / sphinx-update
    INPUT_PER_PAGE: 
    GITHUB_BASEURL: https://api.github.com
##[debug]/usr/bin/bash --noprofile --norc -e -o pipefail /home/runner/work/_temp/23dee120-e867-[4](https://github.com/hwhsu1231/cmake-docs-l10n-draft1/actions/runs/8184410347/job/22379643251#step:16:4)831-8c[6](https://github.com/hwhsu1231/cmake-docs-l10n-draft1/actions/runs/8184410347/job/22379643251#step:16:6)a-14bef83a[7](https://github.com/hwhsu1231/cmake-docs-l10n-draft1/actions/runs/8184410347/job/22379643251#step:16:7)cfb.sh
parse error, job_id is null. job name might be wrong. See https://github.com/Tiryoh/gha-jobid-action
Error: Process completed with exit code 1.
##[debug]Finished: run
##[debug]Evaluating: steps.request.outputs.job_id
##[debug]Evaluating Index:
##[debug]..Evaluating Index:
##[debug]....Evaluating Index:
##[debug]......Evaluating steps:
##[debug]......=> Object
##[debug]......Evaluating String:
##[debug]......=> 'request'
##[debug]....=> Object
##[debug]....Evaluating String:
##[debug]....=> 'outputs'
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'job_id'
##[debug]=> null
##[debug]Result: null
##[debug]Evaluating: steps.request.outputs.html_url
##[debug]Evaluating Index:
##[debug]..Evaluating Index:
##[debug]....Evaluating Index:
##[debug]......Evaluating steps:
##[debug]......=> Object
##[debug]......Evaluating String:
##[debug]......=> 'request'
##[debug]....=> Object
##[debug]....Evaluating String:
##[debug]....=> 'outputs'
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'html_url'
##[debug]=> null
##[debug]Result: null
##[debug]Finishing: Get the Current Job's ID

@hwhsu1231:

However in these runs with as many as 30 strategies, there are always 1 or 2 runs that encounter this error when acquiring the job id.

This sounds a lot like #1. Note that when making the request to the GitHub REST API, only the first page (page=1) is requested by gha-jobid-action, and by default per_page=30. This means that once you have 31 jobs and all query their job ID, it's very likely that some job will not be on this first page limited to 30 results.

So please make sure that adding the per_page: 100 setting to Tiryoh/gha-jobid-action doesn't fix the problem for you, see e.g. kaitai-io/ci_targets@87a5b95 for inspiration.

@generalmimon

So please make sure that adding the per_page: 100 setting to Tiryoh/gha-jobid-action doesn't fix the problem for you, see e.g. kaitai-io/ci_targets@87a5b95 for inspiration.

After setting per_page: 100 and trying several times, it seems that this error won't happen for now.

- name: Get the Current Job's ID
  uses: Tiryoh/gha-jobid-action@v1
  id: gcji
  with:
    github_token: ${{ steps.ggat.outputs.token }}
    job_name: '${{ inputs.CALLER_JOB }} / ${{ github.job }}'
    per_page: 100

@hwhsu1231 Thanks for pointing this out
@generalmimon Thanks for your help

I'll update the error message to check the per_page param

@p0fi There are 2 fixes after v1.0.0 release. Could you try v1 again?

  • Update API URI (#36)
  • Update per_page param error message (#40)

@p0fi There are 2 fixes after v1.0.0 release. Could you try v1 again?

Our problem is fixed with that release! Thanks!

@p0fi Great! Thanks for your feedback๐Ÿ˜†

p0fi commented

Sadly I have to reopen the issue, as it appears that it is still not fixed in my particular case. My test initially worked but our regular deploy now failed again because of the action not being able to get the job ID. It seems that there is a difference in the context if the job in question is triggered via a direct push or via a workflow_call event. Our release pipeline uses a workflow_dispatch event. With this context the current action (1.2.0) does not work while 0.1.2 still works.

@p0fi:

It seems that there is a difference in the context if the job in question is triggered via a direct push or via a workflow_call event. Our release pipeline uses a workflow_dispatch event. With this context the current action (1.2.0) does not work while 0.1.2 still works.

Can you check that the job_name is correct, i.e. that the job_name that your workflow provides to Tiryoh/gha-jobid-action matches the job name displayed on the GitHub web interface?

p0fi commented

It is correct, it does work with version 0.1.2 of the action.

@p0fi Could you check with the latest version 1.3.0? I think there's a good chance that it fixes the problem you were reporting (i.e. worked in 0.1.2, didn't work in 1.2.0).

@p0fi Any updates?

I thought I had this problem - a workflow called via both workflow_dispatch and workflow_call, where the job had a .name property. I originally had to generate the job name because a workflow_call will embed the name. For example:

- name: Compute Job Name
        id: job-name
        run: |
          if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
            echo "job-name=Start Deployment" >>$GITHUB_OUTPUT
          else
            echo "job-name=Deploy to ${{ inputs.environment }} / Start Deployment" >>$GITHUB_OUTPUT
          fi
      - name: Find Github Actions Job ID
        uses: Tiryoh/gha-jobid-action@v1
        id: job
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          job_name: ${{ steps.job-name.outputs.job-name }}

I originally had the following:

# extra single-quotes around the name
echo "job-name='Start Deployment'" >>$GITHUB_OUTPUT

That added extra quotes, which broke workflow_dispatch calls. Removing them fixed the workflow_dispatch (I also originally had them around the computed one as well, and removed those and it works.

p0fi commented

Hi sorry for the delay, I just tested it with version 1.4 and it still breaks. I'm getting the following error this time...

parse error, job_id is null and total_count is 8. 'job_name' or 'per_page' might be wrong. See https://github.com/Tiryoh/gha-jobid-action/blob/main/README.md#inputs