Skip to content
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

Workflow with on.push.paths triggers only on second push #26270

Closed
nblock opened this issue Aug 1, 2023 · 2 comments · Fixed by #26290
Closed

Workflow with on.push.paths triggers only on second push #26270

nblock opened this issue Aug 1, 2023 · 2 comments · Fixed by #26290
Labels
topic/gitea-actions related to the actions of Gitea type/bug
Milestone

Comments

@nblock
Copy link

nblock commented Aug 1, 2023

Description

The following workflow configuration file should trigger on push events to any branch where files anywhere below dir2/ got changed.

---
name: Run only on changes within dir2

on:
  push:
    paths:
      - dir2/**

jobs:
  dir2:
    runs-on: playground
    steps:
      - name: Step for files in dir2
        run: |
          echo 'something changed'

With Gitea 1.20.2 and act runner 0.2.4 this works when pushing a commit that modifies files in dir2/ and the branch already exists on the remote (e.g. the branch main).

It does not work when a new commit that modifies files in dir2/ is pushed to a new branch on the remote. The event is silently ignored. However, the workflow triggers when pushing a second commit to the same branch.

Gitea Version

1.20.2

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

git version 2.39.2

Operating System

Debian 12

How are you running Gitea?

Official release supervised by systemd.

Database

PostgreSQL

@nblock nblock added the type/bug label Aug 1, 2023
@techknowlogick techknowlogick added the topic/gitea-actions related to the actions of Gitea label Aug 1, 2023
@CaiCandong
Copy link
Member

I was able to reproduce your problem and I'm trying to locate the bug.

@CaiCandong
Copy link
Member

CaiCandong commented Aug 2, 2023

I found out why this problem occurs, when you push a new branch, OldCommitID is a null value.

image

Where the error occurred:

}
case "paths":
filesChanged, err := commit.GetFilesChangedSinceCommit(pushPayload.Before)
if err != nil {
log.Error("GetFilesChangedSinceCommit [commit_sha1: %s]: %v", commit.ID.String(), err)

It seems that OldCommitID for new branches is a null value that seems to be designed.

} else { // is new tag
newCommit, err := gitRepo.GetCommit(opts.NewCommitID)
if err != nil {
return fmt.Errorf("gitRepo.GetCommit(%s) in %s/%s[%d]: %w", opts.NewCommitID, repo.OwnerName, repo.Name, repo.ID, err)
}
commits := repo_module.NewPushCommits()
commits.HeadCommit = repo_module.CommitToPushCommit(newCommit)
commits.CompareURL = repo.ComposeCompareURL(git.EmptySHA, opts.NewCommitID)
notification.NotifyPushCommits(
ctx, pusher, repo,
&repo_module.PushUpdateOptions{
RefFullName: opts.RefFullName,
OldCommitID: git.EmptySHA,
NewCommitID: opts.NewCommitID,
}, commits)

@lunny lunny added this to the 1.20.3 milestone Aug 2, 2023
lunny pushed a commit that referenced this issue Aug 4, 2023
Fixes #26270.

Co-Author: @wxiaoguang 

Thanks @lunny for providing this solution

As
#26270 (comment)
said, at present we cannot get the names of changed files correctly when
the `OldCommitID` is `EmptySHA`. In this PR, the `GetCommitFilesChanged`
method is added and will be used to get the changed files by commit ID.

References:
- https://stackoverflow.com/a/424142

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
GiteaBot pushed a commit to GiteaBot/gitea that referenced this issue Aug 4, 2023
…26290)

Fixes go-gitea#26270.

Co-Author: @wxiaoguang 

Thanks @lunny for providing this solution

As
go-gitea#26270 (comment)
said, at present we cannot get the names of changed files correctly when
the `OldCommitID` is `EmptySHA`. In this PR, the `GetCommitFilesChanged`
method is added and will be used to get the changed files by commit ID.

References:
- https://stackoverflow.com/a/424142

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
lunny pushed a commit that referenced this issue Aug 4, 2023
…26316)

Backport #26290 by @Zettat123

Fixes #26270.

Co-Author: @wxiaoguang 

Thanks @lunny for providing this solution

As
#26270 (comment)
said, at present we cannot get the names of changed files correctly when
the `OldCommitID` is `EmptySHA`. In this PR, the `GetCommitFilesChanged`
method is added and will be used to get the changed files by commit ID.

References:
- https://stackoverflow.com/a/424142

Co-authored-by: Zettat123 <zettat123@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic/gitea-actions related to the actions of Gitea type/bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants