beacon-biosignals / job-context

Provides additional context for the currently running job
MIT License
0 stars 0 forks source link

Initial implementation #1

Closed omus closed 3 days ago

omus commented 1 month ago

Creates a new public repository for hosting a new GitHub action. This action will allow the currently running job to determine the job name and job ID allowing improved usage of the GitHub API.

A quick overview of the implementation: in order to determine the job ID we need to use the GitHub API to list jobs for a workflow run attempt. In order to determine which job from the API results is the currently running job we need some kind of alternate way of uniquely selecting the job. I looked at the GitHub Actions context information and the only overlap I found was the runner.name context which according to the docs may not be unique. Alternatively, I chose to use the job name for the selection criteria which also isn't guaranteed to be unique but typically is and it is reasonable to require users to define unique job name within a user provided workflow. Unfortunately, the job name also isn't available via contexts so to get the job name we need to perform three steps:

  1. Access the YAML workflow file which defined this currently running job
  2. Use the ${{ github.job }} which is the job YAML key in the workflow to determine the job name template (the job name as defined in YAML can contain GitHub expressions).
  3. Render any GHA expressions in the job name template

With these steps we know the name of the job and can use that information to determine the job ID. If a job name happens to not be unique we can detect that and cause the action to fail and request that the user makes the job name unique.

In the future we may choose to use runner.name as a first pass in selecting the job from the GitHub API job list. I would consider this an optimization though as we would still need to the job name as either a fallback or as part of the selection criteria.

Various issues asking for the job name or ID feature:

iamed2 commented 2 weeks ago

What's the motivation for this?

omus commented 2 weeks ago

What's the motivation for this?

Knowing the job_id as used by the GitHub API is important for the new matrix-output GHA which requires this information to ensure that the last executed job in the matrix has a complete set of outputs. For more details see this design document: https://github.com/beacon-biosignals/matrix-output/pull/1/files#diff-be587c6fc5d417e1f9d10be50292738384b9df23b4699c8852c990612d3374a6

omus commented 1 week ago

Thanks Dave. I'll merge this and make the first release on Monday!