actions / setup-dotnet

Set up your GitHub Actions workflow with a specific version of the .NET core sdk
MIT License
922 stars 454 forks source link

Matrix example in README doesn't work in v3 #351

Closed erikdesj closed 1 year ago

erikdesj commented 1 year ago

Description: The readme has an example that looks like it runs a build using .NET Core 2.1, 3.2, and 5. It actually runs all three matrix builds using .NET 7, because it happens to be installed.

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        dotnet: [ '2.1.x', '3.1.x', '5.0.x' ]
    name: Dotnet ${{ matrix.dotnet }} sample
    steps:
      - uses: actions/checkout@v3
      - name: Setup dotnet
        uses: actions/setup-dotnet@v3
        with:
          dotnet-version: ${{ matrix.dotnet }}
      - run: dotnet build <my project>

Task version: v3

Platform:

Runner type:

Repro steps:
See the workflow defined in https://github.com/erikdesj/setup-dotnet-test/blob/main/.github/workflows/ci.yml. It is almost exactly the same as the readme, but it just logs the .NET version.

When running each job, they don't end up using the specified .NET version, but instead all use .NET 7, because, incidentally, GitHub happens to build runner images with .NET 7 already installed. https://github.com/erikdesj/setup-dotnet-test/actions/runs/3550078279

image

Expected behavior: When the user writes the following,

- uses: actions/setup-dotnet@v3
  with:
    dotnet-version: 5.0.x

the default dotnet SDK version is set to .NET 5.0.x, since that is what the user requested.

Actual behavior: The default dotnet SDK version is rolled forward to the latest SDK version that's already installed.


I assume you're not actually going to change the v3 behavior, despite it being inconsistent with other (maybe all?) actions/setup-* actions, but the readme examples should be updated to work with the new behavior.

(For instance, both setup-node and setup-java will override the default to the version the user specifies, regardless of what's already installed. This is important to have a reliable CI process, because your tooling shouldn't suddenly change when the runner image is updated. Especially in GitHub Actions, where most users are not managing their own CI environments, they just get whatever tools GitHub happens to put in the latest image build. But I digress.)

IvanZosimov commented 1 year ago

Hi, @erikdesj 👋 Thanks for the issue! The behaviour of the setup-dotnet v3 now is completely aligned with the actual behaviour of the dotnet tool. The dotnet tool uses the latest installed version of SDK as a default. If you have more than 1 installed SDKs, to set the default one you need to use the global.json file, please check MS documentation. If you want to achieve the behaviour that you stated as expected, you may assign the environment variable DOTNET_INSTALL_DIR to some folder different from the default folder with preinstalled SDKs on the image. In that case, the requested SDK version will be the only one in the folder and dotnet by default will use it.

GreenAirplane commented 1 year ago

I think at this point, it would be very difficult to change the behavior because some people might rely on it. As a result, I would say the main issue here is not the behavior but the documentation. It is just not obvious that it will just install and nothing else.

Most developers have experience e.g. with setup-node and when they would see the matrix example, they would think that it is the way how you can build on different versions. But it is not the case here.

At least, this was my original understanding and I'm sure @erikdesj thought the same.

Maybe we can add a "note" to the Matrix section similar to one in the Usage section?

IvanZosimov commented 1 year ago

@GreenAirplane, thanks for the comment! You're right, we will definitely think about adding some clarification to the documentation.

IvanZosimov commented 1 year ago

Hi, @erikdesj 👋 PR with documentation update was just merged: https://github.com/actions/setup-dotnet/pull/359 Thank you for this issue one more time, I'm going to close it. If you have any additional questions feel free to ping us.