Merge pull request #378 from krwq/ci_build_add_packaging

Step 1 to enable automatic nuget package upload
This commit is contained in:
Piotr Puszkiewicz 2015-12-07 10:04:30 -08:00
commit 88806eb7de
7 changed files with 58 additions and 16 deletions

View file

@ -1,3 +1,18 @@
# Copyright (c) .NET Foundation and contributors. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
param(
[string]$toolsDir = $(throw "Specify the full path to the directory which has dotnet tool"),
[string]$versionSuffix = ""
)
# unify trailing backslash
$toolsDir = $toolsDir.TrimEnd('\')
$versionArg = ""
if ($versionSuffix -ne "") {
$versionArg = "--version-suffix $VersionSuffix"
}
. "$PSScriptRoot\..\..\scripts\_common.ps1" . "$PSScriptRoot\..\..\scripts\_common.ps1"
$IntermediatePackagesDir = "$RepoRoot\artifacts\packages\intermediate" $IntermediatePackagesDir = "$RepoRoot\artifacts\packages\intermediate"
@ -15,14 +30,14 @@ $Projects = @(
foreach ($ProjectName in $Projects) { foreach ($ProjectName in $Projects) {
$ProjectFile = "$RepoRoot\src\$ProjectName\project.json" $ProjectFile = "$RepoRoot\src\$ProjectName\project.json"
& dotnet restore "$ProjectFile" & $toolsDir\dotnet restore "$ProjectFile"
if (!$?) { if (!$?) {
Write-Host "dotnet restore failed for: $ProjectFile" Write-Host "$toolsDir\dotnet restore failed for: $ProjectFile"
Exit 1 Exit 1
} }
& dotnet pack "$ProjectFile" --output "$IntermediatePackagesDir" & $toolsDir\dotnet pack "$ProjectFile" --output "$IntermediatePackagesDir" $versionArg
if (!$?) { if (!$?) {
Write-Host "dotnet pack failed for: $ProjectFile" Write-Host "$toolsDir\dotnet pack failed for: $ProjectFile"
Exit 1 Exit 1
} }
} }

View file

@ -18,6 +18,7 @@ if (!(Test-Path $env:DOTNET_INSTALL_DIR))
} }
$env:PATH = "$env:DOTNET_INSTALL_DIR\cli\bin;$env:PATH" $env:PATH = "$env:DOTNET_INSTALL_DIR\cli\bin;$env:PATH"
$VersionSuffix = ""
if (!$env:DOTNET_BUILD_VERSION) { if (!$env:DOTNET_BUILD_VERSION) {
# Get the timestamp of the most recent commit # Get the timestamp of the most recent commit
$timestamp = git log -1 --format=%ct $timestamp = git log -1 --format=%ct
@ -27,8 +28,10 @@ if (!$env:DOTNET_BUILD_VERSION) {
$minorVersion = 0 $minorVersion = 0
$buildnumber = $commitTime.Days $buildnumber = $commitTime.Days
$revnumber = $commitTime.TotalSeconds $revnumber = $commitTime.TotalSeconds
$VersionSuffix = "$buildnumber.$revnumber"
$env:DOTNET_BUILD_VERSION = "$majorVersion.$minorVersion.$buildnumber.$revnumber" $env:DOTNET_BUILD_VERSION = "$majorVersion.$minorVersion.$VersionSuffix"
} }
Write-Host -ForegroundColor Green "*** Building dotnet tools version $($env:DOTNET_BUILD_VERSION) - $Configuration ***" Write-Host -ForegroundColor Green "*** Building dotnet tools version $($env:DOTNET_BUILD_VERSION) - $Configuration ***"
@ -52,3 +55,11 @@ if (!$?) {
Write-Host "Generating dotnet MSI finished with errors." Write-Host "Generating dotnet MSI finished with errors."
Exit 1 Exit 1
} }
Write-Host -ForegroundColor Green "*** Generating NuGet packages ***"
& "$RepoRoot\packaging\nuget\package.ps1" $Stage2Dir\bin $VersionSuffix
if (!$?) {
Write-Host "Generating NuGet packages finished with errors."
Exit 1
}

View file

@ -1,4 +1,5 @@
{ {
"version": "1.0.0-*",
"dependencies": { "dependencies": {
"Microsoft.DotNet.ProjectModel": "1.0.0-*", "Microsoft.DotNet.ProjectModel": "1.0.0-*",
"Microsoft.CodeAnalysis.CSharp.Workspaces": "1.1.0-*" "Microsoft.CodeAnalysis.CSharp.Workspaces": "1.1.0-*"

View file

@ -83,13 +83,13 @@ namespace Microsoft.DotNet.ProjectModel
/// <summary> /// <summary>
/// Creates a project context for each framework located in the project at <paramref name="projectPath"/> /// Creates a project context for each framework located in the project at <paramref name="projectPath"/>
/// </summary> /// </summary>
public static IEnumerable<ProjectContext> CreateContextForEachFramework(string projectPath) public static IEnumerable<ProjectContext> CreateContextForEachFramework(string projectPath, ProjectReader.Settings settings = null)
{ {
if (!projectPath.EndsWith(Project.FileName)) if (!projectPath.EndsWith(Project.FileName))
{ {
projectPath = Path.Combine(projectPath, Project.FileName); projectPath = Path.Combine(projectPath, Project.FileName);
} }
var project = ProjectReader.GetProject(projectPath); var project = ProjectReader.GetProject(projectPath, settings);
foreach (var framework in project.GetTargetFrameworks()) foreach (var framework in project.GetTargetFrameworks())
{ {

View file

@ -16,6 +16,11 @@ namespace Microsoft.DotNet.ProjectModel
{ {
public class ProjectReader public class ProjectReader
{ {
public class Settings
{
public string VersionSuffix = null;
}
public static bool TryGetProject(string path, out Project project, ICollection<DiagnosticMessage> diagnostics = null) public static bool TryGetProject(string path, out Project project, ICollection<DiagnosticMessage> diagnostics = null)
{ {
project = null; project = null;
@ -61,22 +66,23 @@ namespace Microsoft.DotNet.ProjectModel
return true; return true;
} }
public static Project GetProject(string projectFile) public static Project GetProject(string projectFile, Settings settings = null)
{ {
return GetProject(projectFile, new List<DiagnosticMessage>()); return GetProject(projectFile, new List<DiagnosticMessage>(), settings);
} }
public static Project GetProject(string projectFile, ICollection<DiagnosticMessage> diagnostics) public static Project GetProject(string projectFile, ICollection<DiagnosticMessage> diagnostics, Settings settings = null)
{ {
var name = Path.GetFileName(Path.GetDirectoryName(projectFile)); var name = Path.GetFileName(Path.GetDirectoryName(projectFile));
using (var stream = new FileStream(projectFile, FileMode.Open, FileAccess.Read, FileShare.Read)) using (var stream = new FileStream(projectFile, FileMode.Open, FileAccess.Read, FileShare.Read))
{ {
return new ProjectReader().ReadProject(stream, name, projectFile, diagnostics); return new ProjectReader().ReadProject(stream, name, projectFile, diagnostics, settings);
} }
} }
public Project ReadProject(Stream stream, string projectName, string projectPath, ICollection<DiagnosticMessage> diagnostics) public Project ReadProject(Stream stream, string projectName, string projectPath, ICollection<DiagnosticMessage> diagnostics, Settings settings = null)
{ {
settings = settings ?? new Settings();
var project = new Project(); var project = new Project();
var reader = new StreamReader(stream); var reader = new StreamReader(stream);
@ -101,7 +107,7 @@ namespace Microsoft.DotNet.ProjectModel
{ {
try try
{ {
var buildVersion = Environment.GetEnvironmentVariable("DOTNET_BUILD_VERSION"); var buildVersion = settings.VersionSuffix ?? Environment.GetEnvironmentVariable("DOTNET_BUILD_VERSION");
project.Version = SpecifySnapshot(version, buildVersion); project.Version = SpecifySnapshot(version, buildVersion);
} }
catch (Exception ex) catch (Exception ex)

View file

@ -1,4 +1,5 @@
{ {
"version": "1.0.0-*",
"compilationOptions": { "compilationOptions": {
"emitEntryPoint": true "emitEntryPoint": true
}, },

View file

@ -37,6 +37,7 @@ namespace Microsoft.DotNet.Tools.Compiler
var output = app.Option("-o|--output <OUTPUT_DIR>", "Directory in which to place outputs", CommandOptionType.SingleValue); var output = app.Option("-o|--output <OUTPUT_DIR>", "Directory in which to place outputs", CommandOptionType.SingleValue);
var intermediateOutput = app.Option("-t|--temp-output <OUTPUT_DIR>", "Directory in which to place temporary outputs", CommandOptionType.SingleValue); var intermediateOutput = app.Option("-t|--temp-output <OUTPUT_DIR>", "Directory in which to place temporary outputs", CommandOptionType.SingleValue);
var configuration = app.Option("-c|--configuration <CONFIGURATION>", "Configuration under which to build", CommandOptionType.SingleValue); var configuration = app.Option("-c|--configuration <CONFIGURATION>", "Configuration under which to build", CommandOptionType.SingleValue);
var versionSuffix = app.Option("--version-suffix <VERSION_SUFFIX>", "Defines what `*` should be replaced with in version field in project.json", CommandOptionType.SingleValue);
var project = app.Argument("<PROJECT>", "The project to compile, defaults to the current directory. Can be a path to a project.json or a project directory"); var project = app.Argument("<PROJECT>", "The project to compile, defaults to the current directory. Can be a path to a project.json or a project directory");
app.OnExecute(() => app.OnExecute(() =>
@ -59,10 +60,17 @@ namespace Microsoft.DotNet.Tools.Compiler
return 1; return 1;
} }
ProjectReader.Settings settings = null;
if (versionSuffix.HasValue())
{
settings = new ProjectReader.Settings();
settings.VersionSuffix = versionSuffix.Value();
}
var configValue = configuration.Value() ?? Cli.Utils.Constants.DefaultConfiguration; var configValue = configuration.Value() ?? Cli.Utils.Constants.DefaultConfiguration;
var outputValue = output.Value(); var outputValue = output.Value();
return TryBuildPackage(path, configValue, outputValue, intermediateOutput.Value()) ? 0 : 1; return TryBuildPackage(path, configValue, outputValue, intermediateOutput.Value(), settings) ? 0 : 1;
}); });
try try
@ -80,9 +88,9 @@ namespace Microsoft.DotNet.Tools.Compiler
} }
} }
private static bool TryBuildPackage(string path, string configuration, string outputValue, string intermediateOutputValue) private static bool TryBuildPackage(string path, string configuration, string outputValue, string intermediateOutputValue, ProjectReader.Settings settings = null)
{ {
var contexts = ProjectContext.CreateContextForEachFramework(path); var contexts = ProjectContext.CreateContextForEachFramework(path, settings);
var project = contexts.First().ProjectFile; var project = contexts.First().ProjectFile;
if (project.Files.SourceFiles.Any()) if (project.Files.SourceFiles.Any())