Skip to content

Link to executed workflow #31906

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 13 commits into
base: main
Choose a base branch
from

Conversation

william-allspice
Copy link
Contributor

This Pull Request adds a link in the action run details page that allows a user to quickly access the exact version of the workflow file that was run for the given action. This was requested by users who were actively iterating/debugging actions and needed to see which version of the workflow caused the results they are looking at.

This behavior matches similar behavior in github.

Screenshot 2024-08-22 at 9 47 35 PM Screenshot 2024-08-22 at 9 47 09 PM

Two challenges implementing this feature were:

  1. The workflow reference on an ActionRun (WorkflowId) is just the name of the workflow file at the time it was run. This file can be renamed.
  2. The ListWorkflows function implements a "winner takes all" approach where the first matching workflow repo becomes the only visible workflow repo. This path can change over time, for instance if you migrate from .github/workflows to .gitea/workflows.

To solve this, we take the commit from when the action was run, find the appropriate workflow entry, then traverse up the git tree to determine its relative path at the time the commit was made.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Aug 23, 2024
@github-actions github-actions bot added modifies/translation modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files modifies/js labels Aug 23, 2024
@william-allspice william-allspice marked this pull request as ready for review August 26, 2024 14:01
Copy link
Contributor

@kdumontnu kdumontnu left a comment

Choose a reason for hiding this comment

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

Nice, very helpful to have the link to the workflow file.

You've created a generic function to return relative path for a tree object, which we can use in other instances. I think this is a good solution.

I guess the alternative (for this particular case) would be to save the entire relative path to the workflow file in the actions table. I think that's more complex than needed, and this avoids the migration at the moment.

I think this could use either unit test or integration test. Otherwise LGTM!

@GiteaBot GiteaBot added lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Aug 28, 2024
@@ -179,3 +181,30 @@ func (tes Entries) Sort() {
func (tes Entries) CustomSort(cmp func(s1, s2 string) bool) {
sort.Sort(customSortableEntries{cmp, tes})
}

Copy link
Member

Choose a reason for hiding this comment

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

Adding a note for other reviewers: this file doesn't differentiate between go-git and non-go-git impl, so it won't need multiple implementations based on which backend is used.

Copy link
Contributor

Choose a reason for hiding this comment

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

Total side-tangent, but does anyone use go-git?

Copy link
Member

Choose a reason for hiding this comment

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

go-git version has been used in almost all Windows users.

@delvh delvh changed the title Allspice/workflow link Link to executed workflow Sep 1, 2024
Comment on lines +194 to +207
for current != nil && current.ptree != nil {
entries, err := current.ptree.ListEntries()
if err != nil {
log.Error("Failed to climb git tree %v", err)
return ""
}
for _, entry := range entries {
if entry.ID.String() == current.ID.String() {
path = entry.Name() + "/" + path
break
}
}
current = current.ptree
}
Copy link
Member

Choose a reason for hiding this comment

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

This looks like a really inefficient way to gather the full path of a file.
However, I know that this function is drastically needed, also for other functionality (see for example #28835 which got stalled exactly as I wasn't sure how to implement this)._
Thus, I'll allow it for now as long as we get it merged.
We can still improve its performance in the future with a precalculated path.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I think a TreeEntry should have its absolute path. But, felt out of scope for this requested feature.

Copy link
Contributor

Choose a reason for hiding this comment

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

I also agree with delvh, we can't do so. #31906 (comment)

@delvh delvh requested a review from kdumontnu September 1, 2024 11:40
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged labels Sep 3, 2024
"io"
"strings"

actions_model "code.gitea.io/gitea/models/actions"
Copy link
Member

Choose a reason for hiding this comment

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

modules is the wrong place for this.
Go does not allow import cycles.
Please do not add any imports to models from modules.

Copy link
Contributor Author

@william-allspice william-allspice Sep 4, 2024

Choose a reason for hiding this comment

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

modules is the wrong place for this.

@delvh can you expand on what you are asking for?
It sounds like you are asking to move this function and the ListWorkflows function to models? In my humble opinion, I don't think this makes sense because there is no existing concept of a workflow in the database which to me is the equivalent of the models. Happy to hear a different opinion.

I could refactor a lot of the workflow logic, including ListWorkflows, to live in a new file called models/actions/workflows. But it feels odd since there is no database table for a workflow and would violate this principle:

models: Contains the data structures used by xorm to construct database tables. It also contains functions to query and update the database. Dependencies to other Gitea code should be avoided. You can make exceptions in cases such as logging.

Outlined here: https://docs.gitea.com/contributing/guidelines-backend

This module is already dependent on the actions model here: https://github.com/go-gitea/gitea/blob/main/modules/actions/task_state.go#L7

Copy link
Member

Choose a reason for hiding this comment

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

This module is already dependent on the actions model here: https://github.com/go-gitea/gitea/blob/main/modules/actions/task_state.go#L7

🤮 Okay, that is one of the places we didn't fix yet.
We are still working on removing all the historically grown errors.
For the time being, I think it is better not to introduce any already known technical debt.

As to where to add it, I would have added it as a type method on actions_model.ActionRun which is defined in models/actions/run.go

@GiteaBot GiteaBot added lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged and removed lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. labels Sep 4, 2024
return ""
}

return fmt.Sprintf("%s/src/commit/%s/%s", run.Repo.Link(), run.CommitSHA, workflowFilePath)
Copy link
Contributor

Choose a reason for hiding this comment

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

It needs proper escaping, otherwise the link might be invalid

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, we can't influence the workflow file

@@ -179,3 +181,30 @@ func (tes Entries) Sort() {
func (tes Entries) CustomSort(cmp func(s1, s2 string) bool) {
sort.Sort(customSortableEntries{cmp, tes})
}

// GetPathInRepo returns the relative path in the tree to this entry
func (te *TreeEntry) GetPathInRepo() string {
Copy link
Contributor

@wxiaoguang wxiaoguang Sep 5, 2024

Choose a reason for hiding this comment

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

This file was organized by this:

TreeEntry code
Entries code

But now it becomes:

TreeEntry code
Entries code
TreeEntry code

The newly added code should be in the existing "TreeEntry code" section.

@wxiaoguang
Copy link
Contributor

Stale?

@wxiaoguang wxiaoguang added the issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail label Nov 10, 2024
return ""
}

entries, err := ListWorkflows(commit)
Copy link
Contributor

Choose a reason for hiding this comment

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

OK, I think I could understand the problem now.

The proper approach should be like this: add a "WorkflowFilePath" column into the "Actions" model and just use it.

It shouldn't call ListWorkflows for viewing action workflows, otherwise there will be a performance problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged modifies/go Pull requests that update Go code modifies/js modifies/templates This PR modifies the template files modifies/translation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants