예제 #1
0
    def pack(self, path, output_dir, nuget_path, unitypackage_path,
             configuration, unity_project_path,
             unitypackage_root_path_relative):
        """
        Packs NuGet Package.
        :param path: Path to the .csproj or .nuspec, or a directory containing either
        :param output_dir: Output directory - this is where .nupkg file will be built
        :param nuget_path: Path to the NuGet executable
        :param unitypackage_path: Path to the .unitypackge
        :param configuration: Configuration - Debug/Release
        :return: Exit code of the NuGet Pack command
        """
        # Locate nuget executable
        nuget_path = self._locate_nuget_path(nuget_path)
        nuget_runner = NuGetRunner(nuget_path, self.debug)

        # Locate project name and version
        csproj_file_path = CsProj.get_csproj_at_path(path)
        if csproj_file_path is not None:
            csproj = CsProj(path, self.debug)
            package_id = csproj.get_assembly_name()
            version = csproj.get_assembly_version()
        else:
            nuspec_file_path = NuSpec.get_nuspec_at_path(path)
            if nuspec_file_path is not None:
                nuspec = NuSpec(path, self.debug)
                package_id = nuspec.get_package_id()
                version = nuspec.get_package_version()
            else:
                raise click.UsageError(
                    "Path must be a valid path to .nuspec, .csproj, or directory containing either"
                )

        if not package_id:
            raise click.UsageError("Failed to identify package id.")
        if not version:
            raise click.UsageError("Failed to identify package version.")

        if not unitypackage_path:
            unitypackage_name = utils.get_unitypackage_filename(
                package_id, version, configuration)
            unitypackage_path = os.path.join(output_dir, unitypackage_name)

        if not unitypackage_root_path_relative:
            unitypackage_root_path_relative = package_id

        unitypackage_export_root = self._get_unity_package_export_root(
            unity_project_path, unitypackage_root_path_relative)

        return nuget_runner.pack(path, output_dir, configuration,
                                 unitypackage_path, unitypackage_export_root)
예제 #2
0
 def push(self, path, output_dir, feed, nuget_path, api_key):
     """
     Pushes NuGet package on to the NuGet feed.
     :param path: Path to the NuGet Package
     :param output_dir: Output directory in which NuGet package will be searched, if it's not explicitly provided.
     :param feed: NuGet feed URI
     :param nuget_path: Path to the NuGet executable
     :param api_key: NuGet Api Key
     :return: Exit code of the NuGet push command
     """
     nupkg_path = self._locate_nupkg_at_path(path, output_dir)
     nuget_path = self._locate_nuget_path(nuget_path)
     nuget = NuGetRunner(nuget_path, self.debug)
     return nuget.push(nupkg_path, feed, api_key)
예제 #3
0
    def test_nuget_runner_push(self, mock_popen):
        """Test NuGetRunner.push"""
        mock_process = MagicMock()
        mock_process.wait.return_value = 0
        mock_popen.return_value = mock_process

        expected_command_str = "nuget.exe push Test.nupkg -Verbosity normal " \
                               "-Source http://test.com/nuget " \
                               "-ApiKey myapikey7"

        nuget_runner = NuGetRunner("nuget.exe")
        assert nuget_runner.push("Test.nupkg", "http://test.com/nuget",
                                 "myapikey7") == 0
        mock_popen.assert_called_with(expected_command_str, shell=True)
예제 #4
0
    def test_nuget_runner_pack(self, mock_popen):
        """Test NuGetRunner.pack """
        mock_process = MagicMock()
        mock_process.wait.return_value = 0
        mock_popen.return_value = mock_process

        expected_command_str = "nuget.exe pack TestProject.csproj -OutputDirectory Output " \
                               "-Verbosity normal " \
                               "-Properties \"unityPackagePath=TestProject.1.0.0.unitypackage;unityPackageExportRoot=Some/Path;Configuration=Debug\"" \

        nuget_runner = NuGetRunner("nuget.exe")
        assert nuget_runner.pack("TestProject.csproj", "Output", "Debug",
                                 "TestProject.1.0.0.unitypackage",
                                 "Some/Path") == 0
        mock_popen.assert_called_with(expected_command_str, shell=True)