Skip to content

Download actions job logs from API #33858

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

Merged
merged 21 commits into from
Mar 26, 2025
Merged

Conversation

lunny
Copy link
Member

@lunny lunny commented Mar 11, 2025

Related to #33709, #31416

It's similar with https://docs.github.com/en/rest/actions/workflow-jobs?apiVersion=2022-11-28#download-job-logs-for-a-workflow-run--code-samples.

This use job_id as path parameter which is consistent with Github's APIs.

@lunny lunny added type/enhancement An improvement of existing functionality modifies/api This PR adds API routes or modifies them labels Mar 11, 2025
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 11, 2025
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label Mar 11, 2025
@lunny lunny added this to the 1.24.0 milestone Mar 11, 2025
@wxiaoguang
Copy link
Contributor

I am sure you just copied & pasted the code from somewhere without understanding what each line does.

@ChristopherHX
Copy link
Contributor

ChristopherHX commented Mar 16, 2025

Works for me.

While testing I remembered workflow_job webhook uses jobid instead of job index for api url, to have the same field to url mapping for the url field as GitHub Rest.

e.g. http://localhost:3000/api/v1/repos/test/private-repo/actions/runs/842/jobs/373 (prefix of this logs endpoint)

instead of http://localhost:3000/api/v1/repos/test/private-repo/actions/runs/842/jobs/0.

And logs is below this path.

The swagger documention tells me I can use the id that is 404.

image

This use run_id as path parameter which is consistent with other APIs but not web routers. Maybe all web routers should change from run_index to run_id to keep consistent.

I would prefer run_id and job_id in both web routers and api. However I know that this is going to break existing commit status reports

I guess workflow_job webhook is currently a good way to obtain all ids to construct this url, we might need a workflow_run/workflow_job api route to make this really usable from scripts.

EDIT

Sorry some parts are incorrect from my side...

The gh compatible api path of workflow_job is the following, in this case only a id makes sense.

http://localhost:3000/api/v1/repos/test/private-repo/actions/jobs/373

@ChristopherHX
Copy link
Contributor

We were looking at the wrong section of the gh docu.

You are implementing this endpoint https://docs.github.com/en/rest/actions/workflow-jobs?apiVersion=2022-11-28#download-job-logs-for-a-workflow-run--code-samples under a different url.

The one from GitHub has no runs part in the url and uses the jobid instead of index

@lunny
Copy link
Member Author

lunny commented Mar 16, 2025

job_id is a string which is from the workflow not the id stored in the database.
ref https://docs.github.com/en/enterprise-cloud@latest/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_id

@ChristopherHX
Copy link
Contributor

ChristopherHX commented Mar 16, 2025

job_id is a string which is from the workflow not the id stored in the database.

GitHub is good in mixing names, yes job_id in workflow yaml is a string.

job_id in workflow_job api object is a number from the database see here:

ref https://docs.github.com/en/rest/actions/workflow-jobs?apiVersion=2022-11-28#get-a-job-for-a-workflow-run

The example has a really big number, that is a global database id I guess

"id": 399444496,

GitHub Actions users have hard time to correlate a workflow execution from the runner to a workflow_job api id

@lunny lunny changed the title Download actions logs from API Download actions job logs from API Mar 17, 2025
Copy link
Contributor

@ChristopherHX ChristopherHX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, left some non functional suggestions

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 17, 2025
lunny and others added 5 commits March 17, 2025 13:05
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 26, 2025
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 26, 2025
@lunny lunny merged commit 0c6957e into go-gitea:main Mar 26, 2025
26 checks passed
@lunny lunny deleted the lunny/actions_log_api branch March 26, 2025 18:30
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 26, 2025
zjjhot added a commit to zjjhot/gitea that referenced this pull request Mar 27, 2025
* giteaofficial/main:
  [skip ci] Updated translations via Crowdin
  Download actions job logs from API (go-gitea#33858)
  Fail mirroring more gracefully (go-gitea#34002)
  Fix dropdown module accessing (go-gitea#34026)
  Polyfill WeakRef (go-gitea#34025)
  Fix dropdown delegating and some UI problems (go-gitea#34014)
var curJob *actions_model.ActionRunJob
if jobIndex >= 0 && jobIndex < int64(len(runJobs)) {
curJob = runJobs[jobIndex]
if 0 < jobIndex || jobIndex >= int64(len(runJobs)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caused #34038, It should be jobIndex < 0. Fixed in #34041

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I didn't see this, my workflow that I tested was to short.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I made this typo. But why tests didn't catch it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why tests didn't catch it?

The reason was, this test only verifies that downloading a job log with index 0 downloads successfully.

Now this "bug" only appears for the second,third,nth job.

I have commented on the fix PR a patch to the test that expands the test to check, which I cannot push with my privilege here directly into that fix.

@NikolayOG
Copy link

Hi @lunny thank you for adding this feature. How can we obtain job_id in order to call this new API for downloading the job logs?

@ChristopherHX
Copy link
Contributor

ChristopherHX commented Apr 12, 2025

@NikolayOG workflow_job webhook id field (do not trust the url yet)

Eventually /repos/{owner}/{repo}/actions/tasks id field, not tested should provide you the id

@NikolayOG
Copy link

NikolayOG commented Apr 12, 2025

@NikolayOG workflow_job webhook id field (do not trust the url yet)

Eventually /repos/{owner}/{repo}/actions/tasks id field, not tested should provide you the id

I tried that but I think there is a bug. For what I have running (1.24.0+dev-572) when I query "api/v1/repos/nikg/test/actions/tasks" neither "id" nor "run_number" are 14, however, I am able to download some logs on "api/v1/repos/nikg/test/actions/jobs/14/logs" so there is some mismatch going on.

@ChristopherHX
Copy link
Contributor

ChristopherHX commented Apr 12, 2025

@NikolayOG I can confirm a mismatch, it's odd subtract one from the id...

workflow_job webhook reports the correct id, e.g. 1 + of the id field of the tasks endpoint

Need to debug to understand why and how.

I have plans to finish a rest api for workflow_job GitHub Style, but this might not make it in 1.24
EDIT typo I didn't meant now

@ChristopherHX

This comment was marked as outdated.

@ChristopherHX
Copy link
Contributor

Ok it's a different database id, sorry cannot be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants