-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
feat(actions): add job summaries (GITHUB_STEP_SUMMARY) #37500
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
Draft
bircni
wants to merge
2
commits into
go-gitea:main
Choose a base branch
from
bircni:feature/job-summary
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| // Copyright 2026 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package actions | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
|
|
||
| "code.gitea.io/gitea/models/db" | ||
| "code.gitea.io/gitea/modules/timeutil" | ||
| "code.gitea.io/gitea/modules/util" | ||
| ) | ||
|
|
||
| const ( | ||
| // JobSummaryCapability is the runner-declare capability string for job summaries. | ||
| JobSummaryCapability = "job-summary" | ||
|
|
||
| // JobSummaryContentTypeMarkdown is the only accepted content type for job summaries. | ||
| JobSummaryContentTypeMarkdown = "text/markdown" | ||
|
|
||
| // MaxJobSummarySize is the maximum accepted summary payload size in bytes. | ||
| // This is intentionally conservative to avoid DB bloat and UI abuse. | ||
| MaxJobSummarySize = 1024 * 1024 // 1 MiB | ||
| ) | ||
|
|
||
| // ActionRunJobSummary stores the raw job summary markdown uploaded by the runner. | ||
| // It is internal state (not a downloadable artifact). | ||
| type ActionRunJobSummary struct { | ||
| ID int64 `xorm:"pk autoincr"` | ||
|
|
||
| RepoID int64 `xorm:"UNIQUE(summary_key) INDEX"` | ||
| RunID int64 `xorm:"UNIQUE(summary_key) INDEX"` | ||
| RunAttemptID int64 `xorm:"UNIQUE(summary_key) NOT NULL DEFAULT 0 INDEX"` | ||
| JobID int64 `xorm:"UNIQUE(summary_key) INDEX"` | ||
|
|
||
| Content string `xorm:"LONGTEXT"` | ||
| ContentType string `xorm:"VARCHAR(255) NOT NULL DEFAULT 'text/markdown'"` | ||
|
|
||
| Created timeutil.TimeStamp `xorm:"created"` | ||
| Updated timeutil.TimeStamp `xorm:"updated"` | ||
| } | ||
|
|
||
| func init() { | ||
| db.RegisterModel(new(ActionRunJobSummary)) | ||
| } | ||
|
|
||
| func GetActionRunJobSummary(ctx context.Context, repoID, runID, runAttemptID, jobID int64) (*ActionRunJobSummary, error) { | ||
| var s ActionRunJobSummary | ||
| has, err := db.GetEngine(ctx). | ||
| Where("repo_id=? AND run_id=? AND run_attempt_id=? AND job_id=?", repoID, runID, runAttemptID, jobID). | ||
| Get(&s) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if !has { | ||
| return nil, util.ErrNotExist | ||
| } | ||
| return &s, nil | ||
| } | ||
|
|
||
| func UpsertActionRunJobSummary(ctx context.Context, repoID, runID, runAttemptID, jobID int64, contentType string, content []byte) error { | ||
| if runID <= 0 || jobID <= 0 || repoID <= 0 { | ||
| return util.ErrInvalidArgument | ||
| } | ||
| if len(content) == 0 { | ||
| // Treat empty summaries as no-op; runner may create SUMMARY.md but never write to it. | ||
| return nil | ||
| } | ||
| if len(content) > MaxJobSummarySize { | ||
| return util.ErrInvalidArgument | ||
| } | ||
| if contentType == "" { | ||
| contentType = JobSummaryContentTypeMarkdown | ||
| } | ||
| if contentType != JobSummaryContentTypeMarkdown { | ||
| return util.ErrInvalidArgument | ||
| } | ||
|
|
||
| engine := db.GetEngine(ctx) | ||
|
|
||
| existing, err := GetActionRunJobSummary(ctx, repoID, runID, runAttemptID, jobID) | ||
| if err != nil && !errors.Is(err, util.ErrNotExist) { | ||
| return err | ||
| } | ||
|
|
||
| if existing == nil { | ||
| _, err := engine.Insert(&ActionRunJobSummary{ | ||
| RepoID: repoID, | ||
| RunID: runID, | ||
| RunAttemptID: runAttemptID, | ||
| JobID: jobID, | ||
| Content: string(content), | ||
| ContentType: contentType, | ||
| }) | ||
| return err | ||
| } | ||
|
|
||
| existing.Content = string(content) | ||
| existing.ContentType = contentType | ||
| _, err = engine.ID(existing.ID).Cols("content", "content_type").Update(existing) | ||
| return err | ||
| } | ||
|
|
||
| func ListActionRunJobSummariesByRunAttempt(ctx context.Context, repoID, runID, runAttemptID int64) ([]*ActionRunJobSummary, error) { | ||
| var summaries []*ActionRunJobSummary | ||
| if err := db.GetEngine(ctx). | ||
| Where("repo_id=? AND run_id=? AND run_attempt_id=?", repoID, runID, runAttemptID). | ||
| OrderBy("job_id ASC"). | ||
| Find(&summaries); err != nil { | ||
| return nil, err | ||
| } | ||
| return summaries, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Copyright 2026 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package v1_27 | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "code.gitea.io/gitea/models/actions" | ||
|
|
||
| "xorm.io/xorm" | ||
| ) | ||
|
|
||
| func AddActionRunJobSummaryTable(ctx context.Context, x *xorm.Engine) error { | ||
| return x.Sync(new(actions.ActionRunJobSummary)) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| // Copyright 2026 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package actions | ||
|
|
||
| import ( | ||
| "errors" | ||
| "io" | ||
| "mime" | ||
| "net/http" | ||
| "strconv" | ||
|
|
||
| actions_model "code.gitea.io/gitea/models/actions" | ||
| "code.gitea.io/gitea/modules/log" | ||
| "code.gitea.io/gitea/modules/util" | ||
| ) | ||
|
|
||
| const jobSummaryRouteBase = "/_apis/pipelines/workflows/{run_id}/jobs/{job_id}/summary" | ||
|
|
||
| func uploadJobSummary(ctx *ArtifactContext) { | ||
| task, runID, ok := validateRunID(ctx) | ||
| if !ok { | ||
| return | ||
| } | ||
|
|
||
| jobID := ctx.PathParamInt64("job_id") | ||
| if jobID <= 0 { | ||
| ctx.HTTPError(http.StatusBadRequest, "invalid job_id") | ||
| return | ||
| } | ||
|
|
||
| if task == nil || task.Job == nil { | ||
| ctx.HTTPError(http.StatusInternalServerError, "task/job not loaded") | ||
| return | ||
| } | ||
| if task.Job.ID != jobID { | ||
| ctx.HTTPError(http.StatusBadRequest, "job_id mismatch") | ||
| return | ||
| } | ||
| if task.Job.RunID != runID { | ||
| ctx.HTTPError(http.StatusBadRequest, "run_id mismatch") | ||
| return | ||
| } | ||
|
|
||
| body, err := io.ReadAll(io.LimitReader(ctx.Req.Body, actions_model.MaxJobSummarySize+1)) | ||
| if err != nil { | ||
|
bircni marked this conversation as resolved.
|
||
| log.Error("Error reading job summary request body: %v", err) | ||
| ctx.HTTPError(http.StatusInternalServerError, "read request body") | ||
| return | ||
| } | ||
| if len(body) == 0 { | ||
| ctx.JSON(http.StatusOK, map[string]string{"message": "empty"}) | ||
| return | ||
| } | ||
|
|
||
| contentType, ok := normalizeJobSummaryContentType(ctx.Req.Header.Get("Content-Type")) | ||
| if !ok { | ||
| ctx.HTTPError(http.StatusBadRequest, "invalid summary content type") | ||
| return | ||
| } | ||
|
|
||
| if err := actions_model.UpsertActionRunJobSummary(ctx, task.Job.RepoID, task.Job.RunID, task.Job.RunAttemptID, task.Job.ID, contentType, body); err != nil { | ||
| if errorsIsInvalidArg(err) { | ||
| ctx.HTTPError(http.StatusBadRequest, "invalid summary") | ||
| return | ||
| } | ||
| log.Error("Error upsert job summary: %v", err) | ||
| ctx.HTTPError(http.StatusInternalServerError, "Error upsert job summary") | ||
| return | ||
| } | ||
|
|
||
| ctx.JSON(http.StatusOK, map[string]string{ | ||
| "message": "success", | ||
| "sizeBytes": strconv.Itoa(len(body)), | ||
| "runAttempt": strconv.FormatInt(task.Job.RunAttemptID, 10), | ||
| }) | ||
| } | ||
|
|
||
| func errorsIsInvalidArg(err error) bool { | ||
| return errors.Is(err, util.ErrInvalidArgument) | ||
| } | ||
|
|
||
| func normalizeJobSummaryContentType(contentType string) (string, bool) { | ||
| if contentType == "" || contentType == "application/octet-stream" { | ||
| return actions_model.JobSummaryContentTypeMarkdown, true | ||
| } | ||
|
|
||
| mediaType, _, err := mime.ParseMediaType(contentType) | ||
| if err != nil { | ||
| return "", false | ||
| } | ||
| if mediaType != actions_model.JobSummaryContentTypeMarkdown { | ||
| return "", false | ||
| } | ||
| return actions_model.JobSummaryContentTypeMarkdown, true | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.