8000 Use run-name and evaluate workflow variables by badhezi · Pull Request #34301 · go-gitea/gitea · GitHub
[go: up one dir, main page]

Skip to content

Use run-name and evaluate workflow variables #34301

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

Open
wants to merge 35 commits into
base: main
Choose a base branch
from

Conversation

badhezi
Copy link
Contributor
@badhezi badhezi commented Apr 28, 2025

This addresses #34247
depends on https://gitea.com/gitea/act/pulls/137

I couldn't find any previous implementation for run-name support on workflows so I created one.

Key points:
All dispatched workflows, scheduled workflows and detected workflows (from different hooks) will use and evaluate run-name if exists, with the corresponding gitea context and variables. This will be used as the Action run title and replace the default commit message being used today.

Had to change act package jobparser (see link above)
and create two helpers

func (s *ActionSchedule) ToActionRun() *ActionRun {

and
func (g *GiteaContext) ToGitHubContext() *model.GithubContext {

to pass the correct types to GenerateGiteaContext and WithGitContext respectively.

Screenshot 2025-04-28 at 17 13 01

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 28, 2025
@github-actions github-actions bot added modifies/go Pull requests that update Go code modifies/frontend labels Apr 28, 2025
@badhezi badhezi changed the title Dev/hezi/fix run name Use run-name and evaluate workflow variables Apr 28, 2025
@TheFox0x7
Copy link
Contributor

Shouldn't this go to jobparser?

@badhezi
Copy link
Contributor Author
badhezi commented Apr 29, 2025

@TheFox0x7
Created https://gitea.com/gitea/act/pulls/136 to move most of the logic to jobparser

@badhezi badhezi force-pushed the dev/hezi/fix-run-name branch from cca335d to 9408c76 Compare April 29, 2025 12:17
@badhezi
Copy link
Contributor Author
badhezi commented May 12, 2025

Hey @lunny you think I can get someone to review https://gitea.com/gitea/act/pulls/137 so we can push this forward?
Thanks.

@lunny
Copy link
Member
lunny commented May 12, 2025

Hey @lunny you think I can get someone to review https://gitea.com/gitea/act/pulls/137 so we can push this forward? Thanks.

That PR merged.

@badhezi
Copy link
Contributor Author
badhezi commented May 12, 2025

Hey @lunny you think I can get someone to review https://gitea.com/gitea/act/pulls/137 so we can push this forward? Thanks.

That PR merged.

Thanks @lunny
Should I want for a new tag release of gitea/act or is there anything else to do?

@lunny
Copy link
Member
lunny commented May 12, 2025

Hey @lunny you think I can get someone to review https://gitea.com/gitea/act/pulls/137 so we can push this forward? Thanks.

That PR merged.

Thanks @lunny Should I want for a new tag release of gitea/act or is there anything else to do?

v0.261.6 tagged.

@badhezi badhezi force-pushed the dev/hezi/fix-run-name branch from 9633e1d to 7a52cac Compare May 12, 2025 18:19
chhe pushed a commit to chhe/act that referenced this pull request May 13, 2025
To support go-gitea/gitea#34301

Reviewed-on: https://gitea.com/gitea/act/pulls/137
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: badhezi <zlilaharon@gmail.com>
Co-committed-by: badhezi <zlilaharon@gmail.com>
@badhezi
Copy link
Contributor Author
badhezi commented May 13, 2025

Can this PR please be reviewed?
@wxiaoguang @lunny
Thanks

@lunny lunny added this to the 1.25.0 milestone May 13, 2025
@badhezi badhezi requested a review from Zettat123 May 16, 2025 22:03
if err != nil {
log.Error("jobparser.Parse: %v", err)
continue
}

if len(jobs) > 0 && jobs[0].RunName != "" {
Copy link
Member

Choose a reason for hiding this comment

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

According to the yaml file, the run-name is the top level key but not belongs to any jobs in that workflow file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey, yes I agree.
We discussed this briefly before https://gitea.com/gitea/act/pulls/136#issuecomment-1002837

you requested i consolidate the logic into jobparser.Parse()
which actually returns a list of SingleWorkflow, it called "job" because that was the original terminology in the code and i kept that the same.

There is no way for me to return just the interpolated top-level key when need it to exist inside Parse(), which also returns all the individual workflow jobs, so I attach the run name to every workflow (which is not necessarily wrong), and extract just one of them when building the ActionRun / ActionSchedule.

If you would like a different approach I have no problem implementing that.

log.Error("ToGitHubContext.json.Marshal: %v", err)
}

err = json.Unmarshal(gitCtxRaw, ghCtx)
Copy link
Contributor

Choose a reason for hiding this comment

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

It is quite fragile by using Marshal+Unmarshal, it's unclear what value a field would get.

To make it stable, I think we should assign the fields one by one explicitly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/dependencies modifies/go Pull requests that update Go code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0