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

Add support for Directory.Packages.props file as entrypoint #7086

Merged
merged 8 commits into from Jun 26, 2023

Conversation

TobiasLaving
Copy link
Contributor

This PR will enable dependabot to use a Directory.Packages.props file as entry point, allowing the setup below:

Repo:

src/
├─ Backend/
│  ├─ Project1/
│  │  ├─ Project1.csproj
│  ├─ Project2/
│  │  ├─ Project2.csproj
│  ├─ Directory.Packages.props
├─ App/
├─ Solution.sln

dependabot.yml:


version: 2
updates:
  - package-ecosystem: "nuget"
    directory: "/src/Backend"
    schedule:
      interval: "daily"
    open-pull-requests-limit: 5
    target-branch: master

Note: I have never written ruby before and I'm a bit out of my depth
This is working locally towards our repo, but I'm guessing there is a bunch of things I am missing.
I'm happy to get any feedback

@TobiasLaving TobiasLaving requested a review from a team as a code owner April 14, 2023 14:41
@github-actions github-actions bot added the L: dotnet:nuget NuGet packages via nuget or dotnet label Apr 14, 2023
@yeikel
Copy link
Contributor

yeikel commented Apr 15, 2023

Please add tests for this change

Also, is there any issue where this was discussed? This is usually recommended before any pull request is created

@TobiasLaving
Copy link
Contributor Author

The issue is discussed in the issue: #5635

I will look into adding tests!
On another note, as seen in the PR two files have identical functions, is this intentional?
Should the function "project_files" be broken out?

@yeikel
Copy link
Contributor

yeikel commented Apr 16, 2023

The issue is discussed in the issue: #5635

I will look into adding tests!
On another note, as seen in the PR two files have identical functions, is this intentional?
Should the function "project_files" be broken out?

Refactoring it sounds reasonable to me

Thank you for pointing it out

@TobiasLaving
Copy link
Contributor Author

I now added some tests.

I used this repo to create the fixtures

The repo has drifted from what the PR originally described and looks more like this:

[tobias@tobias-expertbook nuget-directory-packages-props-example]$ tree -P "*.sln|*.csproj|Directory.Packages.props" --prune
.
├── App1
│   ├── App1.sln
│   └── src
│       └── Backend
│           ├── Project1
│           │   └── Project1.csproj
│           └── Project2
│               └── Project2.csproj
└── Directory.Packages.props

The intended dependabot.yml would look like this:

version: 2
updates:
  - package-ecosystem: "nuget"
    directory: "/"
    schedule:
      interval: "daily"
    open-pull-requests-limit: 5
    target-branch: master

The reason for the drift is entirely selfish, it is more like our private repository. Still, the repo in the PR should also work.

For testing I added

  1. Simple test for getting only directory.packages.props if it is found in the root
  2. Test to make sure the new code does not override the old logic for sln and all files are still fetched.

I wanted to do some refactoring but quickly felt out of my depth so I fell back onto doing the least work possible.
Happy to hear any feedback, in particular it would be helpful if we can figure out more tests cases.

Copy link
Member

@jeffwidman jeffwidman left a comment

Choose a reason for hiding this comment

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

👋 Thanks for putting this up!

I'm not a NuGet expert, but the code change itself looks pretty straightforward to me, so pretty sure we'll be 👍 to ship it.

Two things:

  1. I have a slight preference to land Support NuGet lockfiles #6031 first if possible, as that appears to have a lot more user impact. I don't think it'll create merge conflicts since IIUC the lockfile is unrelated but just in case I'm wrong let's see. That said, if that PR author isn't responsive, then we can ship this first.
  2. I see tests for file_fetcher but not file_parser or file_updater... can you add one for each of those? Don't need anything fancy, just a simple proof that it catches a Directory.Packages.props file so that if someone ever refactors those regexes there's no chance of regression.

@TobiasLaving
Copy link
Contributor Author

@jeffwidman
Ok, sounds good!

@jeffwidman
Copy link
Member

@TobiasLaving just to clarify, did you see 2️⃣ in my comment above? Can you add those two simple tests?

@TobiasLaving
Copy link
Contributor Author

@jeffwidman Sorry about that, I intended to make the change straight away but life got in the way

Yes, I saw it and just pushed it :)

@danquirk
Copy link

We have a ton of repos affected by this bug. Curious roughly when we would expect to be able to leverage this fix? I'm trying to avoid having to check in slngen'd .sln files to 100s of repos as a workaround.

@DkSkydancer
Copy link

@TobiasLaving What is the status on this?
@jeffwidman How long we should expect this PR to hold of for #6031

@TobiasLaving
Copy link
Contributor Author

@DkSkydancer This PR is ready in my opinion

@DkSkydancer
Copy link

@jeffwidman can we move forward with this please?

@DkSkydancer
Copy link

@TobiasLaving @jeffwidman ping. we are still waiting for this!

@TobiasLaving
Copy link
Contributor Author

Seems @jeffwidman is out (?)
Do you know the next steps @yeikel ?

@Nishnha
Copy link
Member

Nishnha commented Jun 5, 2023

Hey folks, Dependabot maintainer here - we've had a bit of a deploy freeze and have fallen behind on reviews. Sorry about that!

I took a look at the changes and I agree that this PR is in a good state. We should be able to take a look at merging it some time this week.

In the meantime, would you be able to bring it up-to-date with the base branch @TobiasLaving? The CI tests should be able to run now

@DkSkydancer
Copy link

@TobiasLaving Can you the update as requested above pl?

@TobiasLaving
Copy link
Contributor Author

@DkSkydancer @Nishnha
PR is now rebased and all checks has passed 👍

@DkSkydancer
Copy link

@Nishnha the PR should be ready now

@DkSkydancer
Copy link

@Nishnha @jeffwidman Can we get a maintainer review please?

@DkSkydancer
Copy link

@TobiasLaving it looks like this branch is out of date again I'm afraid :(

@@ -70,7 +70,7 @@ def project_file_parser
end

def project_files
dependency_files.select { |df| df.name.match?(/\.[a-z]{2}proj$/) }
dependency_files.select { |df| df.name.match?(/\.[a-z]{2}proj$|[Dd]irectory.[Pp]ackages.props/) }
Copy link
Member

Choose a reason for hiding this comment

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

Could we split this regex into two different captures and try to match against both?

Something like

Suggested change
dependency_files.select { |df| df.name.match?(/\.[a-z]{2}proj$|[Dd]irectory.[Pp]ackages.props/) }
projfile = /\.[a-z]{2}proj$/
packageprops = /[Dd]irectory.[Pp]ackages.props/
dependency_files.select { |df|
df.name.match?(projfile) ||
df.name.match?(packageprops)
}

and do the same in the file updater?

)
end

it "fetches the files the packages props file" do
Copy link
Member

Choose a reason for hiding this comment

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

typo

Suggested change
it "fetches the files the packages props file" do
it "fetches the packages props file" do

@@ -0,0 +1,19 @@
{
"name": "Directory.Packages.props",
Copy link
Member

Choose a reason for hiding this comment

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

@Nishnha
Copy link
Member

Nishnha commented Jun 15, 2023

Thank you for this contribution! I left a comment on the regex capture that I would like to see addressed before approving.

We can bring this PR up-to-date before we merge it, so it's fine that it has become out-of-date with the base branch.

@jeffwidman should we fork https://github.com/TobiasLaving/nuget-directory-packages-props-example into the dependabot org since it's referenced in the specs?

@TobiasLaving
Copy link
Contributor Author

Good points, I have made the changes locally sadly the dev container seems to be broken for nuget atm so I cannot run it locally: #7438

Will push once I can validate locally

@TobiasLaving
Copy link
Contributor Author

@Nishnha

Fixed your comments, thanks for finding and fixing the docker issue!

Copy link
Member

@Nishnha Nishnha left a comment

Choose a reason for hiding this comment

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

The linter is complaining about one issue but once that's fixed the rest LGTM!

@TobiasLaving
Copy link
Contributor Author

@Nishnha There, the linter is now happy 👍

Struggeled a little bit with running the lint script in the dev container, sorry about the delay

@TobiasLaving
Copy link
Contributor Author

TobiasLaving commented Jun 26, 2023

@Nishnha
For my understanding, is anything expected of my right now? Who will press "Merge to master"? :)

@Nishnha Nishnha merged commit 89526c2 into dependabot:main Jun 26, 2023
83 checks passed
@Nishnha
Copy link
Member

Nishnha commented Jun 26, 2023

We have a deploy-then-merge process so it's not as straightforward as pressing the merge button. That said, this PR has been merged now 😄

Thank you for the contribution!

hjgraca added a commit to aws-powertools/powertools-lambda-dotnet that referenced this pull request Sep 14, 2023
After looking into dependabot/dependabot-core#7086 this maybe possible

Signed-off-by: Henrique Graca <999396+hjgraca@users.noreply.github.com>
brettfo pushed a commit to brettfo/dependabot-core that referenced this pull request Oct 11, 2023
Add support for Directory.Packages.props file as entrypoint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L: dotnet:nuget NuGet packages via nuget or dotnet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants