actions / setup-dotnet

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

Refactor installer #432

Closed nikolai-laevskii closed 1 year ago

nikolai-laevskii commented 1 year ago

Description:

Refactoring was conducted only for installer.ts module. The most significant changes are in DotnetCoreInstaller class:

  1. Logic related to the install dir was separated and moved to simple static DotnetInstallDir class
  2. Logic related to the install script was moved to DotnetInstallScript class, which now allows to invoke install-script multiple times and conditionally apply script arguments.

Example of DotnetInstallScript class usage (just an example code, not how it is actually set here)

// Conditionally invoke install script
if (IS_WINDOWS) {
    // initialize DotnetInstallScriptClass
    const installScript: Promise<exec.ExecOutput> = await new DotnetInstallScript()
          // arguments can be inserted via this method
          .useArguments('-Runtime', 'dotnet')
          // version can be set via this method, it's just a syntactic sugar over useArguments that will insert arguments based on version provided
          .useVersion({ type: '-Channel', value: '6.0', qualityFlag: false })
          // useVersion and useArguments methods are chainable
          // script then can be then executed with execute method
          .execute();

    if (installScript.exitCode) { /* handle error */ }
}

const {exitCode, stderr} = await new DotnetInstallScript()
    // arguments do not convert automatically due the ambiguity in casing between some (such as -JSonFile and --jsonfile)
    .useArguments(IS_WINDOWS ? '-Version' : '--version', '6.0.100')
    .execute()

The script preparation is conducted upon calling the constructor and all platform-specific arguments are inserted by default

Related issue: Related but does not solve https://github.com/actions/setup-dotnet/issues/387, just conducts necessary preparations for further fix. Should be treated as general refactoring.

Check list: