Skip to content

Commit 1e16e9e

Browse files
authored
Merge branch 'main' into fix-br-display-package
2 parents 632bfba + 22fec16 commit 1e16e9e

File tree

3 files changed

+176
-35
lines changed

3 files changed

+176
-35
lines changed

modules/actions/workflows.go

+107-35
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/gobwas/glob"
1717
"github.com/nektos/act/pkg/jobparser"
1818
"github.com/nektos/act/pkg/model"
19+
"github.com/nektos/act/pkg/workflowpattern"
1920
)
2021

2122
func ListWorkflows(commit *git.Commit) (git.Entries, error) {
@@ -152,40 +153,94 @@ func matchPushEvent(commit *git.Commit, pushPayload *api.PushPayload, evt *jobpa
152153
}
153154

154155
matchTimes := 0
156+
hasBranchFilter := false
157+
hasTagFilter := false
158+
refName := git.RefName(pushPayload.Ref)
155159
// all acts conditions should be satisfied
156160
for cond, vals := range evt.Acts {
157161
switch cond {
158-
case "branches", "tags":
159-
refShortName := git.RefName(pushPayload.Ref).ShortName()
160-
for _, val := range vals {
161-
if glob.MustCompile(val, '/').Match(refShortName) {
162-
matchTimes++
162+
case "branches":
163+
hasBranchFilter = true
164+
if !refName.IsBranch() {
165+
break
166+
}
167+
patterns, err := workflowpattern.CompilePatterns(vals...)
168+
if err != nil {
169+
break
170+
}
171+
if !workflowpattern.Skip(patterns, []string{refName.ShortName()}, &workflowpattern.EmptyTraceWriter{}) {
172+
matchTimes++
173+
}
174+
case "branches-ignore":
175+
hasBranchFilter = true
176+
if !refName.IsBranch() {
177+
break
178+
}
179+
patterns, err := workflowpattern.CompilePatterns(vals...)
180+
if err != nil {
181+
break
182+
}
183+
if !workflowpattern.Filter(patterns, []string{refName.ShortName()}, &workflowpattern.EmptyTraceWriter{}) {
184+
matchTimes++
185+
}
186+
case "tags":
187+
hasTagFilter = true
188+
if !refName.IsTag() {
189+
break
190+
}
191+
patterns, err := workflowpattern.CompilePatterns(vals...)
192+
if err != nil {
193+
break
194+
}
195+
if !workflowpattern.Skip(patterns, []string{refName.ShortName()}, &workflowpattern.EmptyTraceWriter{}) {
196+
matchTimes++
197+
}
198+
case "tags-ignore":
199+
hasTagFilter = true
200+
if !refName.IsTag() {
201+
break
202+
}
203+
patterns, err := workflowpattern.CompilePatterns(vals...)
204+
if err != nil {
205+
break
206+
}
207+
if !workflowpattern.Filter(patterns, []string{refName.ShortName()}, &workflowpattern.EmptyTraceWriter{}) {
208+
matchTimes++
209+
}
210+
case "paths":
211+
filesChanged, err := commit.GetFilesChangedSinceCommit(pushPayload.Before)
212+
if err != nil {
213+
log.Error("GetFilesChangedSinceCommit [commit_sha1: %s]: %v", commit.ID.String(), err)
214+
} else {
215+
patterns, err := workflowpattern.CompilePatterns(vals...)
216+
if err != nil {
163217
break
164218
}
219+
if !workflowpattern.Skip(patterns, filesChanged, &workflowpattern.EmptyTraceWriter{}) {
220+
matchTimes++
221+
}
165222
}
166-
case "paths":
223+
case "paths-ignore":
167224
filesChanged, err := commit.GetFilesChangedSinceCommit(pushPayload.Before)
168225
if err != nil {
169226
log.Error("GetFilesChangedSinceCommit [commit_sha1: %s]: %v", commit.ID.String(), err)
170227
} else {
171-
for _, val := range vals {
172-
matched := false
173-
for _, file := range filesChanged {
174-
if glob.MustCompile(val, '/').Match(file) {
175-
matched = true
176-
break
177-
}
178-
}
179-
if matched {
180-
matchTimes++
181-
break
182-
}
228+
patterns, err := workflowpattern.CompilePatterns(vals...)
229+
if err != nil {
230+
break
231+
}
232+
if !workflowpattern.Filter(patterns, filesChanged, &workflowpattern.EmptyTraceWriter{}) {
233+
matchTimes++
183234
}
184235
}
185236
default:
186237
log.Warn("push event unsupported condition %q", cond)
187238
}
188239
}
240+
// if both branch and tag filter are defined in the workflow only one needs to match
241+
if hasBranchFilter && hasTagFilter {
242+
matchTimes++
243+
}
189244
return matchTimes == len(evt.Acts)
190245
}
191246

@@ -237,30 +292,47 @@ func matchPullRequestEvent(commit *git.Commit, prPayload *api.PullRequestPayload
237292
}
238293
}
239294
case "branches":
240-
refShortName := git.RefName(prPayload.PullRequest.Base.Ref).ShortName()
241-
for _, val := range vals {
242-
if glob.MustCompile(val, '/').Match(refShortName) {
243-
matchTimes++
295+
refName := git.RefName(prPayload.PullRequest.Base.Ref)
296+
patterns, err := workflowpattern.CompilePatterns(vals...)
297+
if err != nil {
298+
break
299+
}
300+
if !workflowpattern.Skip(patterns, []string{refName.ShortName()}, &workflowpattern.EmptyTraceWriter{}) {
301+
matchTimes++
302+
}
303+
case "branches-ignore":
304+
refName := git.RefName(prPayload.PullRequest.Base.Ref)
305+
patterns, err := workflowpattern.CompilePatterns(vals...)
306+
if err != nil {
307+
break
308+
}
309+
if !workflowpattern.Filter(patterns, []string{refName.ShortName()}, &workflowpattern.EmptyTraceWriter{}) {
310+
matchTimes++
311+
}
312+
case "paths":
313+
filesChanged, err := commit.GetFilesChangedSinceCommit(prPayload.PullRequest.Base.Ref)
314+
if err != nil {
315+
log.Error("GetFilesChangedSinceCommit [commit_sha1: %s]: %v", commit.ID.String(), err)
316+
} else {
317+
patterns, err := workflowpattern.CompilePatterns(vals...)
318+
if err != nil {
244319
break
245320
}
321+
if !workflowpattern.Skip(patterns, filesChanged, &workflowpattern.EmptyTraceWriter{}) {
322+
matchTimes++
323+
}
246324
}
247-
case "paths":
325+
case "paths-ignore":
248326
filesChanged, err := commit.GetFilesChangedSinceCommit(prPayload.PullRequest.Base.Ref)
249327
if err != nil {
250328
log.Error("GetFilesChangedSinceCommit [commit_sha1: %s]: %v", commit.ID.String(), err)
251329
} else {
252-
for _, val := range vals {
253-
matched := false
254-
for _, file := range filesChanged {
255-
if glob.MustCompile(val, '/').Match(file) {
256-
matched = true
257-
break
258-
}
259-
}
260-
if matched {
261-
matchTimes++
262-
break
263-
}
330+
patterns, err := workflowpattern.CompilePatterns(vals...)
331+
if err != nil {
332+
break
333+
}
334+
if !workflowpattern.Filter(patterns, filesChanged, &workflowpattern.EmptyTraceWriter{}) {
335+
matchTimes++
264336
}
265337
}
266338
default:

routers/web/repo/actions/view.go

+42
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"code.gitea.io/gitea/models/db"
1515
"code.gitea.io/gitea/models/unit"
1616
"code.gitea.io/gitea/modules/actions"
17+
"code.gitea.io/gitea/modules/base"
1718
context_module "code.gitea.io/gitea/modules/context"
1819
"code.gitea.io/gitea/modules/log"
1920
"code.gitea.io/gitea/modules/timeutil"
@@ -57,6 +58,7 @@ type ViewResponse struct {
5758
CanApprove bool `json:"canApprove"` // the run needs an approval and the doer has permission to approve
5859
Done bool `json:"done"`
5960
Jobs []*ViewJob `json:"jobs"`
61+
Commit ViewCommit `json:"commit"`
6062
} `json:"run"`
6163
CurrentJob struct {
6264
Title string `json:"title"`
@@ -76,6 +78,25 @@ type ViewJob struct {
7678
CanRerun bool `json:"canRerun"`
7779
}
7880

81+
type ViewCommit struct {
82+
LocaleCommit string `json:"localeCommit"`
83+
LocalePushedBy string `json:"localePushedBy"`
84+
ShortSha string `json:"shortSHA"`
85+
Link string `json:"link"`
86+
Pusher ViewUser `json:"pusher"`
87+
Branch ViewBranch `json:"branch"`
88+
}
89+
90+
type ViewUser struct {
91+
DisplayName string `json:"displayName"`
92+
Link string `json:"link"`
93+
}
94+
95+
type ViewBranch struct {
96+
Name string `json:"name"`
97+
Link string `json:"link"`
98+
}
99+
79100
type ViewJobStep struct {
80101
Summary string `json:"summary"`
81102
Duration string `json:"duration"`
@@ -104,6 +125,10 @@ func ViewPost(ctx *context_module.Context) {
104125
return
105126
}
106127
run := current.Run
128+
if err := run.LoadAttributes(ctx); err != nil {
129+
ctx.Error(http.StatusInternalServerError, err.Error())
130+
return
131+
}
107132

108133
resp := &ViewResponse{}
109134

@@ -123,6 +148,23 @@ func ViewPost(ctx *context_module.Context) {
123148
})
124149
}
125150

151+
pusher := ViewUser{
152+
DisplayName: run.TriggerUser.GetDisplayName(),
153+
Link: run.TriggerUser.HomeLink(),
154+
}
155+
branch := ViewBranch{
156+
Name: run.PrettyRef(),
157+
Link: run.RefLink(),
158+
}
159+
resp.State.Run.Commit = ViewCommit{
160+
LocaleCommit: ctx.Tr("actions.runs.commit"),
161+
LocalePushedBy: ctx.Tr("actions.runs.pushed_by"),
162+
ShortSha: base.ShortSha(run.CommitSHA),
163+
Link: fmt.Sprintf("%s/commit/%s", run.Repo.Link(), run.CommitSHA),
164+
Pusher: pusher,
165+
Branch: branch,
166+
}
167+
126168
var task *actions_model.ActionTask
127169
if current.TaskID > 0 {
128170
var err error

web_src/js/components/RepoActionView.vue

+27
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
<i class="stop circle outline icon"/>
1414
</button>
1515
</div>
16+
<div class="action-commit-summary">
17+
{{ run.commit.localeCommit }}
18+
<a :href="run.commit.link">{{ run.commit.shortSHA }}</a>
19+
&nbsp;<span class="ui label">
20+
<a :href="run.commit.branch.link">{{ run.commit.branch.name }}</a>
21+
</span>
22+
&nbsp;{{ run.commit.localePushedBy }}
23+
<a :href="run.commit.pusher.link">{{ run.commit.pusher.displayName }}</a>
24+
</div>
1625
</div>
1726
<div class="action-view-body">
1827
<div class="action-view-left">
@@ -105,6 +114,20 @@ const sfc = {
105114
// canRerun: false,
106115
// },
107116
],
117+
commit: {
118+
localeCommit: '',
119+
localePushedBy: '',
120+
shortSHA: '',
121+
link: '',
122+
pusher: {
123+
displayName: '',
124+
link: '',
125+
},
126+
branch: {
127+
name: '',
128+
link: '',
129+
},
130+
}
108131
},
109132
currentJob: {
110133
title: '',
@@ -332,6 +355,10 @@ export function initRepositoryActionView() {
332355
padding: 0 5px;
333356
}
334357
358+
.action-commit-summary {
359+
padding: 10px 10px;
360+
}
361+
335362
/* ================ */
336363
/* action view left */
337364

0 commit comments

Comments
 (0)