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

GitVersion.Core library should allow bypassing shellout interop #2138

Open
gitfool opened this issue Feb 26, 2020 · 11 comments
Open

GitVersion.Core library should allow bypassing shellout interop #2138

gitfool opened this issue Feb 26, 2020 · 11 comments
Assignees
Milestone

Comments

@gitfool
Copy link
Contributor

gitfool commented Feb 26, 2020

With the advent of the common GitVersion.Core library, it would be prudent to refactor it further so that it has a nice interface for C# developers; i.e. classes and methods that can be called directly, as with any other library, thereby bypassing shellout interop - command-line input / output parsing - and all the ugliness that entails.

@gitfool
Copy link
Contributor Author

gitfool commented Feb 26, 2020

Example ugliness that I've seen, the Cake build fails with:

2020-02-21T19:29:37.4851511Z Executing: /home/runner/work/build-cake/build-cake/tools/dotnet-gitversion -output json -verbosity Debug
2020-02-21T19:29:37.9043586Z Error: One or more errors occurred. (Expecting state 'Element'.. Encountered 'Text'  with name '', namespace ''.)
2020-02-21T19:29:37.9045093Z 	Expecting state 'Element'.. Encountered 'Text'  with name '', namespace ''.

Re-run with diagnostic verbosity to find the real cause (across the interop boundary):

2020-02-21T19:44:13.2433107Z Executing: /home/runner/work/build-cake/build-cake/tools/dotnet-gitversion -output json -verbosity Debug
2020-02-21T19:44:13.7026817Z INFO [02/21/20 19:44:13:46] Applicable build agent found: 'GitHubActions'.INFO [02/21/20 19:44:13:47] Working directory: /home/runner/work/build-cake/build-cakeINFO [02/21/20 19:44:13:47] IsDynamicGitRepository: FalseINFO [02/21/20 19:44:13:48] Returning Project Root from DotGitDirectory: /home/runner/work/build-cake/build-cake/.git/ - /home/runner/work/build-cake/build-cake/INFO [02/21/20 19:44:13:48] Running on Unix.INFO [02/21/20 19:44:13:48] Applicable build agent found: 'GitHubActions'.INFO [02/21/20 19:44:13:48] Branch from build environment: gitversion-betaINFO [02/21/20 19:44:13:49] Begin: Normalizing git directory for branch 'gitversion-beta'  INFO [02/21/20 19:44:13:52] One remote found (origin -> 'https://github.com/pharos/build-cake').  INFO [02/21/20 19:44:13:52] Fetching from remote 'origin' using the following refspecs: +refs/heads/*:refs/remotes/origin/*.  INFO [02/21/20 19:44:13:63] End: Normalizing git directory for branch 'gitversion-beta' (Took: 149.01ms)  ERROR [02/21/20 19:44:13:65] An unexpected error occurred:
2020-02-21T19:44:13.7027719Z LibGit2Sharp.LibGit2SharpException: remote authentication required but no callback set
2020-02-21T19:44:13.7027967Z    at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
2020-02-21T19:44:13.7028198Z    at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result)
2020-02-21T19:44:13.7028426Z    at LibGit2Sharp.Core.Proxy.git_remote_fetch(RemoteHandle remote, IEnumerable`1 refSpecs, GitFetchOptions fetchOptions, String logMessage)
2020-02-21T19:44:13.7028687Z    at LibGit2Sharp.Commands.Fetch(Repository repository, String remote, IEnumerable`1 refspecs, FetchOptions options, String logMessage)
2020-02-21T19:44:13.7028954Z    at GitVersion.Helpers.GitRepositoryHelper.Fetch(ILog log, AuthenticationInfo authentication, Remote remote, Repository repo) in D:\a\GitVersion\GitVersion\src\GitVersionCore\Helpers\GitRepositoryHelper.cs:line 145
2020-02-21T19:44:13.7029238Z    at GitVersion.Helpers.GitRepositoryHelper.NormalizeGitDirectory(ILog log, IEnvironment environment, String gitDirectory, AuthenticationInfo authentication, Boolean noFetch, String currentBranch, Boolean isDynamicRepository) in D:\a\GitVersion\GitVersion\src\GitVersionCore\Helpers\GitRepositoryHelper.cs:line 40
2020-02-21T19:44:13.7029521Z    at GitVersion.GitPreparer.NormalizeGitDirectory(AuthenticationInfo auth, String targetBranch, String gitDirectory, Boolean isDynamicRepository) in D:\a\GitVersion\GitVersion\src\GitVersionCore\GitPreparer.cs:line 190
2020-02-21T19:44:13.7029786Z    at GitVersion.GitPreparer.Prepare(Boolean normalizeGitDirectory, String currentBranch, Boolean shouldCleanUpRemotes) in D:\a\GitVersion\GitVersion\src\GitVersionCore\GitPreparer.cs:line 65
2020-02-21T19:44:13.7030040Z    at GitVersion.GitVersionCalculator.CalculateVersionVariables() in D:\a\GitVersion\GitVersion\src\GitVersionCore\GitVersionCalculator.cs:line 51
2020-02-21T19:44:13.7030272Z    at GitVersion.ExecCommand.Execute() in D:\a\GitVersion\GitVersion\src\GitVersionExe\ExecCommand.cs:line 39
2020-02-21T19:44:13.7031622Z    at GitVersion.GitVersionExecutor.VerifyArgumentsAndRun(Arguments arguments) in D:\a\GitVersion\GitVersion\src\GitVersionExe\GitVersionExecutor.cs:line 117  INFO [02/21/20 19:44:13:65]   INFO [02/21/20 19:44:13:65] Attempting to show the current git graph (please include in issue):   INFO [02/21/20 19:44:13:65] Showing max of 100 commits  INFO [02/21/20 19:44:13:68] * 0a7740c 2 minutes ago  (HEAD -> gitversion-beta, tag: 14.1.0-pre.1, origin/gitversion-beta)
...
2020-02-21T19:44:13.7498754Z Error: System.AggregateException: One or more errors occurred. (Expecting state 'Element'.. Encountered 'Text'  with name '', namespace ''.)
2020-02-21T19:44:13.7499245Z  ---> System.Runtime.Serialization.SerializationException: Expecting state 'Element'.. Encountered 'Text'  with name '', namespace ''.
2020-02-21T19:44:13.7500469Z    at System.Runtime.Serialization.XmlObjectSerializerReadContext.HandleMemberNotFound(XmlReaderDelegator xmlReader, ExtensionDataObject extensionData, Int32 memberIndex)
2020-02-21T19:44:13.7500689Z    at System.Runtime.Serialization.Json.XmlObjectSerializerReadContextComplexJson.GetJsonMemberIndex(XmlReaderDelegator xmlReader, XmlDictionaryString[] memberNames, Int32 memberIndex, ExtensionDataObject extensionData)
2020-02-21T19:44:13.7500866Z    at ReadGitVersionFromJson(XmlReaderDelegator , XmlObjectSerializerReadContextComplexJson , XmlDictionaryString , XmlDictionaryString[] )
2020-02-21T19:44:13.7501041Z    at System.Runtime.Serialization.Json.JsonClassDataContract.ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context)
2020-02-21T19:44:13.7501208Z    at System.Runtime.Serialization.Json.JsonDataContract.ReadJsonValue(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context)
2020-02-21T19:44:13.7501375Z    at System.Runtime.Serialization.Json.XmlObjectSerializerReadContextComplexJson.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader)
2020-02-21T19:44:13.7501548Z    at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract)
2020-02-21T19:44:13.7501730Z    at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, String name, String ns)
2020-02-21T19:44:13.7501898Z    at System.Runtime.Serialization.Json.DataContractJsonSerializerImpl.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName)
2020-02-21T19:44:13.7502064Z    at System.Runtime.Serialization.XmlObjectSerializer.InternalReadObject(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
2020-02-21T19:44:13.7502242Z    at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
2020-02-21T19:44:13.7502410Z    at System.Runtime.Serialization.Json.DataContractJsonSerializerImpl.ReadObject(XmlDictionaryReader reader)
2020-02-21T19:44:13.7502552Z    at System.Runtime.Serialization.Json.DataContractJsonSerializerImpl.ReadObject(Stream stream)
2020-02-21T19:44:13.7502696Z    at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject(Stream stream)
2020-02-21T19:44:13.7502852Z    at Cake.Common.Tools.GitVersion.GitVersionRunner.Run(GitVersionSettings settings) in C:\projects\cake\src\Cake.Common\Tools\GitVersion\GitVersionRunner.cs:line 65
2020-02-21T19:44:13.7503213Z    at Cake.Common.Tools.GitVersion.GitVersionAliases.GitVersion(ICakeContext context, GitVersionSettings settings) in C:\projects\cake\src\Cake.Common\Tools\GitVersion\GitVersionAliases.cs:line 121
2020-02-21T19:44:13.7503792Z    at Submission#0.Version..ctor(BuildSystem buildSystem, ICakeContext context) in /home/runner/work/build-cake/build-cake/scripts/version.cake:line 10
2020-02-21T19:44:13.7504344Z    at Submission#0.Builder.SetVersion() in /home/runner/work/build-cake/build-cake/scripts/builder.cake:line 291
2020-02-21T19:44:13.7504794Z    at Submission#0.Builder..ctor(BuildSystem buildSystem, ICakeContext context, Action`1 runTarget) in /home/runner/work/build-cake/build-cake/scripts/builder.cake:line 9
2020-02-21T19:44:13.7505199Z    at Submission#0.<<Initialize>>d__0.MoveNext() in /home/runner/work/build-cake/build-cake/scripts/bootstrap.cake:line 20
2020-02-21T19:44:13.7505618Z --- End of stack trace from previous location where exception was thrown ---
2020-02-21T19:44:13.7505796Z    at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)
2020-02-21T19:44:13.7505991Z    at Microsoft.CodeAnalysis.Scripting.Script`1.RunSubmissionsAsync(ScriptExecutionState executionState, ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, Func`2 catchExceptionOpt, CancellationToken cancellationToken)
2020-02-21T19:44:13.7506343Z    --- End of inner exception stack trace ---
2020-02-21T19:44:13.7506485Z    at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
2020-02-21T19:44:13.7506639Z    at Cake.Scripting.Roslyn.RoslynScriptSession.Execute(Script script) in C:\projects\cake\src\Cake\Scripting\Roslyn\RoslynScriptSession.cs:line 136
2020-02-21T19:44:13.7506809Z    at Cake.Core.Scripting.ScriptRunner.Run(IScriptHost host, FilePath scriptPath, IDictionary`2 arguments) in C:\projects\cake\src\Cake.Core\Scripting\ScriptRunner.cs:line 219
2020-02-21T19:44:13.7506972Z    at Cake.Commands.BuildCommand.Execute(CakeOptions options) in C:\projects\cake\src\Cake\Commands\BuildCommand.cs:line 41
2020-02-21T19:44:13.7507127Z    at Cake.CakeApplication.Run(CakeOptions options) in C:\projects\cake\src\Cake\CakeApplication.cs:line 45
2020-02-21T19:44:13.7507314Z    at Cake.Program.Main() in C:\projects\cake\src\Cake\Program.cs:line 80

In this case "remote authentication required but no callback set".

@asbjornu
Copy link
Member

Yes, such a refactor would bring us in the direction of a complete Core without any reliance on LibGit2Sharp and an in-memory object model that will serve GitVersion's needs much better (and faster) than Git's.

@asbjornu
Copy link
Member

The code and discussion in #1243 and #1244 is worth a look.

@gitfool
Copy link
Contributor Author

gitfool commented Feb 26, 2020

@asbjornu thanks for the info! I think this is conflating the two interop boundaries though.

My thoughts with this issue are related to the "external" interop boundary; i.e. from Cake script / C# client to the GitVersion library itself, currently using command-line / shellout interop.

The "internal" interop boundary from GitVersion to LibGit2Sharp (and git) is an implementation detail and not really relevant, but happens to also use command-line / shellout interop.

@asbjornu
Copy link
Member

In a Multitier Architecture, I would agree, but since we're talking about a "Core" here, Hexagonal Architecture or Onion Architecture is imho a better way to view the application.

In that case, all concerns that aren't a part of the Core (which should be 100% dependency free and contain nothing but idiomatic C# code) are a part of the "infrastructure" or "UI" layer of the application, external to the Core. The only difference is whether we are doing an inbound (requests, input, deserialization) or outbound mapping (response, output, serialization) of the Core domain.

While I agree that inbound and outband mapping are different concerns, I don't think it's possible to implement one without the other once we delete all external dependencies from the Core.

@stale
Copy link

stale bot commented May 27, 2020

This issue has been automatically marked as stale because it has not had recent activity. After 30 days from now, it will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label May 27, 2020
@asbjornu
Copy link
Member

asbjornu commented May 27, 2020

Please see #2262 and #2275 for how we are planning to solve this over time. We probably won't achieve a dependency-free Core in 6.0.0, but over the course of version 6, we should be able to achieve it with the coming refactoring, project split and new CLI.

@stale stale bot removed the stale label May 27, 2020
@stale
Copy link

stale bot commented Aug 25, 2020

This issue has been automatically marked as stale because it has not had recent activity. After 30 days from now, it will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added stale and removed stale labels Aug 25, 2020
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. After 30 days from now, it will be closed if no further activity occurs.

@github-actions github-actions bot added the stale label Apr 13, 2023
@arturcic arturcic removed the stale label Apr 13, 2023
@arturcic arturcic added this to the 7.x milestone Apr 13, 2023
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. After 30 days from now, it will be closed if no further activity occurs.

@github-actions github-actions bot added the stale label Jul 13, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 30 days with no activity. Thank you for your contributions

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 12, 2023
@arturcic arturcic reopened this Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants