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

feat: add job_name to github context #3489

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

qoomon
Copy link

@qoomon qoomon commented Oct 4, 2024

By providing the real/effective job name (as in the github api response of jobs), we are able to determine and request the current job by using list-jobs-for-a-workflow-run-attempt API endpoint and find the actual job by its name.

const currentJob = await octokit.paginate(octokit.rest.actions.listJobsForWorkflowRunAttempt, {
  owner: 'qoomon',
  repo: 'sandbox',
  run_id: parseInt(process.env.GITHUB_RUN_ID),
  attempt_number: parseInt(process.env.GITHUB_RUN_ATTEMPT),
}).then((jobs) => jobs.find((job) => job.name === process.env.GITHUB_JOB_NAME))

This would solve a lot of community requests.

Currently the is no system variable that contains a job id value that can be used to request the github api for a job.
system.jobIdcontains a UUID and there for is useless for job API endpoint

@qoomon qoomon requested a review from a team as a code owner October 4, 2024 11:45
@Felixoid
Copy link

Felixoid commented Oct 4, 2024

Hi, thanks for the patch. I am really looking forward to have it merged!

By the way, what do you think about including the job ID? It would help with a bridge from https://api.github.com/repos/ClickHouse/ClickHouse/actions/runs/8363985040/jobs?per_page=1&page=13 to https://api.github.com/repos/ClickHouse/ClickHouse/actions/jobs/22961931602 in no additional actions

@qoomon
Copy link
Author

qoomon commented Oct 4, 2024

@Felixoid unfortunately the job id needed for the api is not present, the system.jobId variable is set to a GUID see below

System Variables
 {
    "system.isScheduled": {
      "value": "False"
    },
    "system.servertype": {
      "value": "Hosted"
    },
    "system.culture": {
      "value": ""
    },
    "system.pipelineStartTime": {
      "value": "2024-10-04 11:28:22+00:00"
    },
    "system.runner.lowdiskspacethreshold": {
      "value": "100"
    },
    "DistributedTask.NewActionMetadata": {
      "value": "true"
    },
    "DistributedTask.EnableCompositeActions": {
      "value": "true"
    },
    "DistributedTask.EnhancedAnnotations": {
      "value": "true"
    },
    "DistributedTask.UploadStepSummary": {
      "value": "true"
    },
    "DistributedTask.ForceGithubJavascriptActionsToNode16": {
      "value": "true"
    },
    "DistributedTask.ForceGithubJavascriptActionsToNode20": {
      "value": "true"
    },
    "DistributedTask.AddWarningToNode12Action": {
      "value": "true"
    },
    "DistributedTask.AddWarningToNode16Action": {
      "value": "true"
    },
    "DistributedTask.LogTemplateErrorsAsDebugMessages": {
      "value": "true"
    },
    "DistributedTask.AllowRunnerContainerHooks": {
      "value": "true"
    },
    "DistributedTask.DeprecateStepOutputCommands": {
      "value": "true"
    },
    "DistributedTask.UseWhich2": {
      "value": "true"
    },
    "DistributedTask.DetailUntarFailure": {
      "value": "true"
    },
    "DistributedTask.UseActionArchiveCache": {
      "value": "true"
    },
    "DistributedTask.EnableJobServerQueueTelemetry": {
      "value": "true"
    },
    "DistributedTask.MarkJobAsFailedOnWorkerCrash": {
      "value": "true"
    },
    "Actions.EnableHttpRedirects": {
      "value": "true"
    },
    "system.teamProjectId": {
      "value": "00000000-0000-0000-0000-000000000000"
    },
    "build.buildId": {
      "value": "666"
    },
    "build.containerId": {
      "value": "18431423"
    },
    "system.workflowFilePath": {
      "value": ".github/workflows/example.yaml"
    },
    "system.phaseDisplayName": {
      "value": "build"
    },
    "system.phaseId": {
      "value": "08529e53-a864-5e57-8255-b4ac74128910"
    },
    "system.phaseName": {
      "value": "build"
    },
    "system.phaseAttempt": {
      "value": "1"
    },
    "system.jobIdentifier": {
      "value": "build-with-reusable-workflow-with-matrix._20_x.build.__default"
    },
    "system.jobAttempt": {
      "value": "1"
    },
    "System.JobPositionInPhase": {
      "value": "1"
    },
    "System.TotalJobsInPhase": {
      "value": "1"
    },
    "system.github.job": {
      "value": "build"
    },
    "system.jobDisplayName": {
      "value": "build-with-reusable-workflow-with-matrix (20.x) / build"
    },
    "system.jobId": {
      "value": "0315e721-8f55-564f-db13-292a0596e43b"
    },
    "system.jobName": {
      "value": "__default"
    },
    "system.github.token.permissions": {
      "value": "{\"Contents\":\"read\",\"Metadata\":\"read\",\"Packages\":\"read\"}"
    },
    "system.workflowFileFullPath": {
      "value": "qoomon/actions--context/.github/workflows/example-reusable.yml"
    },
    "system.github.token": {
      "value": "***",
      "isSecret": true
    },
    "system.github.results_endpoint": {
      "value": "https://results-receiver.actions.githubusercontent.com/"
    },
    "system.github.results_upload_with_sdk": {
      "value": "True"
    },
    "system.workflowFileRef": {
      "value": "refs/heads/main"
    },
    "system.workflowFileSha": {
      "value": "d2fec0f6c3c70eea6c8124a0a9458c7aea4565f4"
    },
    "system.runnerEnvironment": {
      "value": "github-hosted"
    },
    "system.orchestrationId": {
      "value": "595b9a62-e373-4b13-ba58-2f92a6c39f3a.build-with-reusable-workflow-with-matrix._20_x.build.__default"
    },
    "system.runnerGroupName": {
      "value": "GitHub Actions"
    }
  }

@Felixoid
Copy link

Felixoid commented Oct 4, 2024

I see.

Even a correct jobDisplayName is already a solid solution for the job ID resolving. So, many kudos to you

@Felixoid
Copy link

Felixoid commented Oct 4, 2024

Oh, wait. What about a defined env variable for this value?

@qoomon
Copy link
Author

qoomon commented Oct 4, 2024

@Felixoid No unfortunately not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants