touchifyapp / vsts-changed-files

Azure DevOps pipeline task to get changed files since last succeeded build
MIT License
12 stars 6 forks source link

Doesn't work when merging branches #8

Closed pnwguy closed 3 years ago

pnwguy commented 3 years ago

This works perfectly when detecting file changes from within the same branch. However when I do pull requests from one branch to another (ie merging QA to Staging), it doesn't detect the file changes. Is this intended to work within a branch only?

If I do pull request from branch QA to Staging, the task shows:

Fetching latest succeeded build Last succeeded build found: 20210427.3-[QA] Executing git cat-file with xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

If trigger was to detect a change to a specific file, and the file changes were implement as part of 20210427.2-[QA], then the pull request to 20210427.4-[Stage] won't pick it up even though the file, upon merge completion, will be changed.

SomaticIT commented 3 years ago

Hello,

Just to be sure, do you want to detect changes on the QA branch or changes between QA and Staging branches?

This module tries to detect changes between the commit of the last successful build and the current one. It does not look if the branch differs.

We will investigate to find the best way to implement this behavior. Feel free to help by collaborating 😉

Thanks

pnwguy commented 3 years ago

Hi, I would love to help! I want to detect changes between QA and Staging. My use case - I want to determine if documentation file has changed, if so, import the new documentation file. This works great for same branch. Let me brush up on my git knowledge and see if I can provide some solutions.

mohamedelhabib commented 3 years ago

@pnwguy @SomaticIT please have a look at this PR my be it can help #13

leonardochaia commented 3 years ago

Hi guys!

@SomaticIT this is a nice tool! We wanna use it to speed up our monorepo builds. However this issue is preventing us from doing so.

This module tries to detect changes between the commit of the last successful build and the current one.

I think that statement needs to include the current branch, considering that pipelines can build more than one branch. i.e. when using Branch Policies for PRs.

https://github.com/touchifyapp/vsts-changed-files/blob/3235bb2aa4089a5e1585ab061cade4f58adf2fcb/changed-files/index.ts#L60

I think we need to include the current branch here, and filter the "last successful build" for the current branch as well as the definition id.

So, find the last successful build for the current pipeline definition and current branch being built. Is that a PR you would consider merging?

SomaticIT commented 3 years ago

Hi,

@mohamedelhabib your PR looks promising for this use case. I think, we should consider using the same branch as the refBranchName (need to remove the default value).

It will allow @pnwguy to specify a custom refBranchName on Staging and @leonardochaia could use the default behavior.

Do you agree?

leonardochaia commented 3 years ago

Hey guys, sorry I didn't really look at the PR. I just think that the default behavior should be to "find the build for this definition and this branch". That works for single and multi branch repos and is safe by default.

Personally, I ended up using the API since I wanted to get the last successful build commit to use it for another tool which does the git diff internally

mohamedelhabib commented 3 years ago

@SomaticIT sorry i just sow you comment after several tests i found another approach using https://docs.microsoft.com/en-us/rest/api/azure/devops/build/builds/get%20build%20changes?view=azure-devops-rest-6.0 and git log -m -1 --name-only --pretty='format:' <commitId> to list changed files

I am still using refBranch to detect changes between branches.

Please have a look here https://github.com/mohamedelhabib/vsts-changed-files-multibranch/blob/master/changed-files/index.ts#L64 NB : to be able to test i published a renamed version of the extension.

mohamedelhabib commented 3 years ago

@SomaticIT i just created a new PR #16

pandiello commented 3 years ago

@mohamedelhabib Just looking for the same feature, thanks!

SomaticIT commented 3 years ago

Hello everyone,

I'm very happy to announce that we released a new version v1.2.1 today. Many thanks to @mohamedelhabib for his work.

To summarize new features:

  1. when merging/rebasing branches
  2. multi-branches setup (without reference branch)
  3. multi-branches setup (with reference branch)
  4. git cherry-pick, force push, revert, etc.
  5. public repo handling
  6. hidden files detection

Can you give a try to the new version and give me your feedback?

PS: very sorry for the time.

SomaticIT commented 3 years ago

I'm closing this issue as I think it's resolved with v1.2.1. If you encounter a case that is not handled with this new feature, please open a new issue.