changed-files icon indicating copy to clipboard operation
changed-files copied to clipboard

Add support for dotnet solution filter files (monorepo support)

Open rocklan opened this issue 6 months ago • 1 comments

This PR adds support for being able to specify a list of dotnet solution filter files, and for those files to be parsed and converted to Yaml file patterns.

What this means in english is that if we have a solution filter file in our repo that looks like this:

MyApplication.slnf

{
  "solution": {
    "path": "MyApplication.sln",
    "projects": [
      "MyApplication.Web\\MyApplication.Web.csproj",
      "MyApplication.Logic\\MyApplication.Logic.csproj",
      "MyApplication.Tests\\MyApplication.Tests.csproj"
    ]
  }
}

and we supply it as an input parameter to this action:

      - name: Get changed files
        id: changed-files
        uses: rome2rio/changed-files@lachlan/solutionfilters
        with:
          solution_filters: "MyApplication.slnf"

it will be treated like a configuration yaml file that looks like so:

myapplication:
  - MyApplication.Web/**
  - MyApplication.Logic/**
  - MyApplication.Tests/**

This is great because it means our changed_files.yaml file doesn't need to be manually kept in sync with our solution filters. If we add a new project to a solution or delete/rename a project it will automatically be picked up by changed-files. This may seem like a trivial request but the larger the repo the bigger this problem becomes, and adding this feature would simplify a lot of things. Currently we are generating this file as a separate step (and caching it) but it all becomes a lot simpler if it's just done inside this action.

The way it works is by parsing the slnf file specified, looking for the projects array inside the file, then looking for .csproj file references, and then filtering out the project file but keeping the path. Once we have the path, we append /** to the end of it and we have our filePattern. The key added is the name of the solution filter file converted to lowercase (and dots converted to dashes).

This also provides great support for monorepos, because if you specify multiple solution filters, they will also be added to the configuration:

myapplication:
  - MyApplication.Web/**
  - MyApplication.Logic/**
  - MyApplication.Tests/**
myotherapplication:  
  - subdir/MyOtherApplication.Console/**

Plus, if you have extra files that are outside of the project directory, you can specify them in a yaml file and they will be appended:

project-files.yml

# Do not add any project directories to this file as they are added automatically by changed-files
myapplication:
  - some-other-directory
myotherapplication:
  - README.md

which will end up giving us:

myapplication:
  - some-other-directory
  - MyApplication.Web/**
  - MyApplication.Logic/**
  - MyApplication.Tests/**
myotherapplication:  
  - README.md
  - subdir/MyOtherApplication.Console/**

The code submitted is definitely not awesome, all reviews extremely welcome :) I suspect this feature would be really helpful to a lot of .NET devs.

rocklan avatar Jun 04 '25 01:06 rocklan