leonardochaia / dotnet-affected-action

.NET tool for determining which projects are affected by a set of changes. Useful for large projects or monorepos.
https://github.com/leonardochaia/dotnet-affected
MIT License
15 stars 3 forks source link

Couldn't find Git Commit or Branch with name main #257

Open LordLyng opened 3 hours ago

LordLyng commented 3 hours ago

I'm unsure what I'm doing wrong here.

I more or less copied the example from the For building PRs section of the README. the only exception is that I use v4 of the checkout action and v4 of the setup dotnet action.

When I run the dotnet-affected action i get the following error: Unhandled exception: System.InvalidOperationException: Couldn't find Git Commit or Branch with name main in repository /home/runner/work/itm_sursen4-backend/itm_sursen4-backend/.git/ at DotnetAffected.Core.GitChangesProvider.GetCommitOrThrow(Repository repo, String name) in /_/src/DotnetAffected.Core/GitChangesProvider.cs:line 152 at DotnetAffected.Core.GitChangesProvider.GetCommitOrHead(Repository repository, String name) in /_/src/DotnetAffected.Core/GitChangesProvider.cs:line [13](https://github.com/it-minds/itm_sursen4-backend/actions/runs/11343124706/job/31545025965#step:5:14)5 at DotnetAffected.Core.GitChangesProvider.ParseRevisionRanges(Repository repository, String from, String to) in /_/src/DotnetAffected.Core/GitChangesProvider.cs:line 82 at DotnetAffected.Core.GitChangesProvider.GetChangesForRange[T](Repository repository, String from, String to) in /_/src/DotnetAffected.Core/GitChangesProvider.cs:line 101 at DotnetAffected.Core.GitChangesProvider.GetChangedFiles(String directory, String from, String to) in /_/src/DotnetAffected.Core/GitChangesProvider.cs:line 24 at DotnetAffected.Core.Processor.AffectedProcessorBase.DiscoverChangedFiles(AffectedProcessorContext context) in /_/src/DotnetAffected.Core/Processor/AffectedProcessorBase.cs:line 57 at DotnetAffected.Core.Processor.AffectedProcessorBase.Process(AffectedProcessorContext context) in /_/src/DotnetAffected.Core/Processor/AffectedProcessorBase.cs:line 22 at DotnetAffected.Core.AffectedExecutor.Execute() in /_/src/DotnetAffected.Core/AffectedExecutor.cs:line 41 at Affected.Cli.Commands.InvocationContextExtensions.ExecuteAffectedExecutor(InvocationContext ctx) in /_/src/dotnet-affected/Commands/Binding/InvocationContextExtensions.cs:line 38 at Affected.Cli.Commands.AffectedRootCommand.<>c.<<-ctor>b__4_0>d.MoveNext() in /_/src/dotnet-affected/Commands/AffectedRootCommand.cs:line 38 --- End of stack trace from previous location --- at System.CommandLine.Invocation.AnonymousCommandHandler.InvokeAsync(InvocationContext context) at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass17_0.<<UseParseErrorReporting>b__0>d.MoveNext() --- End of stack trace from previous location --- at Affected.Cli.ErrorHandlingMiddleware.<>c__DisplayClass0_0.<<UseRenderingErrorHandler>b__0>d.MoveNext() in /_/src/dotnet-affected/CommandLine/ErrorHandlingMiddleware.cs:line 26 --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass12_0.<<UseHelp>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseVersionOption>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass19_0.<<UseTypoCorrections>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__18_0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass[16](https://github.com/it-minds/itm_sursen4-backend/actions/runs/11343124706/job/31545025965#step:5:17)_0.<<UseParseDirective>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__5_0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass8_0.<<UseExceptionHandler>b__0>d.MoveNext()

I tried copying the command executed during my workflow and ran it lcoally with no issues.

My workflow can be seen here

name: PR Disaptcher

on:
  pull_request:
    branches: main

jobs:
  pr-dispatch:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Setup .NET
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: |
            8.0.x

      - uses: leonardochaia/dotnet-affected-action@v1
        id: dotnet_affected
        with:
          from: ${{ github.head_ref }}
          to: ${{ github.base_ref }}

      - run: echo ${{ steps.dotnet_affected.outputs.affected }}
LordLyng commented 3 hours ago

worth noting i get an error when testing this in a PR. The command executed by the actions is /usr/share/dotnet/dotnet affected -f text traversal --from custom/workflow-dispatcher --to main

LordLyng commented 3 hours ago

I did some more research and found out that if i prefix both the to and from with origin/ it seems to work.

So the problem most likely comes from either checkout not checking out the base and head ref as heads during pr checkout, or the way LibGit2Sharp handles populating remote urls.

working workflow example, not sure if it's ideal though

name: PR Disaptcher

on:
  pull_request:
    branches: main

jobs:
  pr-dispatch:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Setup .NET
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: |
            8.0.x

      - uses: leonardochaia/dotnet-affected-action@v1
        id: dotnet_affected
        with:
          from: origin/${{ github.head_ref }}
          to: origin/${{ github.base_ref }}

      - run: echo ${{ steps.dotnet_affected.outputs.affected }}
leonardochaia commented 49 minutes ago

hi @LordLyng ,I think we may need to review the example you've linked in order to make it work properly. Not sure if something changed in the tool that caused the breaking change, or if it is something else that changed. Leo.