Skip to content

Build/continuous deployment #237

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

Merged
merged 9 commits into from
Mar 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
version: 1.0.{build}
image: Visual Studio 2017

install:
- cmd: choco install dotnet.script

build_script:
- ps: >-
cd .\build\
- cmd: >-
cd build

.\install-dotnet-script.ps1
- cmd:
dotnet .\dotnet-script\dotnet-script.dll build.csx
refreshenv

dotnet script build.csx

test: off
artifacts:
- path: /**/Dotnet.Script*.nupkg
- path: build\Artifacts\Chocolatey\*.nupkg
name: Chocolatey Packages
# Uncomment this to enable deploy on repo tagging
# deploy:
# provider: Chocolatey
# api_key:
# secure: [Your API key goes here]
# skip_symbols: false
# artifact: /.*\.nupkg/
# on:
# appveyor_repo_tag: true

- path: build\Artifacts\NuGet\*.nupkg
name: NuGet Packages

- path: build\Artifacts\GitHub\*.zip
name: GitHub

test: off
environment:
IS_SECURE_BUILDENVIRONMENT:
secure: xU2zj54rFEPVqg/UuGU/DA==
GITHUB_REPO_TOKEN:
secure: AzNlvlKMzcoPNzawN3Hv48N6dzPa0N57HdFfAXP2cELBp9uiwJxtLdKWuDhZyf21
NUGET_APIKEY:
secure: 81vsB74sZV0IlV1Ru/qKPbaDS47lQ80aeOLWCPmlvak7O/RA9EqqFqWVxZFS0ora
CHOCO_APIKEY:
secure: scd8oB50KqKDRvt/+TSgUJavZzY39iqqa+1AZmj1CGue1/vjWJn6vIO4sMhN+d2l
64 changes: 40 additions & 24 deletions build/Build.csx
Original file line number Diff line number Diff line change
@@ -1,33 +1,49 @@
#! "netcoreapp2.0"
#r "nuget:NetStandard.Library,2.0.0"
#r "nuget:Microsoft.DotNet.PlatformAbstractions, 2.0.3"
#load "DotNet.csx"
#load "nuget:Dotnet.Build, 0.2.8"
#load "nuget:github-changelog, 0.1.4"
#load "Choco.csx"
#load "NuGet.csx"
#load "FileUtils.csx"
#load "BuildContext.csx"

using System.Runtime.InteropServices;


var currentFolder = Path.GetDirectoryName(GetScriptPath());
var root = Path.GetFullPath(Path.Combine(currentFolder, ".."));


DotNet.Build(Path.Combine(root, "src","Dotnet.Script"));

DotNet.Test($"{root}/src/Dotnet.Script.Tests");
using static ReleaseManagement;
using static ChangeLog;
using static FileUtils;

DotNet.Build(DotnetScriptProjectFolder);
DotNet.Test(TestProjectFolder);
DotNet.Publish(DotnetScriptProjectFolder, PublishArtifactsFolder);

// We only publish packages from Windows/AppVeyor
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (BuildEnvironment.IsWindows)
{
string packagesOutputFolder = Path.Combine(root, "build", "NuGet");
DotNet.Pack(Path.Combine(root, "src" , "Dotnet.Script"), packagesOutputFolder);
DotNet.Pack(Path.Combine(root, "src" , "Dotnet.Script.Core"), packagesOutputFolder);
DotNet.Pack(Path.Combine(root, "src" , "Dotnet.Script.DependencyModel"), packagesOutputFolder);
DotNet.Pack(Path.Combine(root, "src" , "Dotnet.Script.DependencyModel.NuGet"), packagesOutputFolder);
DotNet.Publish($"{root}/src/Dotnet.Script");
Choco.Pack($"{root}/src/Dotnet.Script","Chocolatey");
DotNet.Pack(DotnetScriptProjectFolder, NuGetArtifactsFolder);
DotNet.Pack(DotnetScriptCoreProjectFolder, NuGetArtifactsFolder);
DotNet.Pack(DotnetScriptDependencyModelProjectFolder, NuGetArtifactsFolder);
DotNet.Pack(DotnetScriptDependencyModelNuGetProjectFolder, NuGetArtifactsFolder);
Choco.Pack(DotnetScriptProjectFolder, PublishArtifactsFolder, ChocolateyArtifactsFolder);
Zip(PublishArchiveFolder, PathToGitHubReleaseAsset);


if (BuildEnvironment.IsSecure)
{
await CreateReleaseNotes();

if (Git.Default.IsTagCommit())
{
Git.Default.RequreCleanWorkingTree();
await ReleaseManagerFor(Owner,ProjectName,BuildEnvironment.GitHubAccessToken)
.CreateRelease(Git.Default.GetLatestTag(), PathToReleaseNotes, new [] { new ZipReleaseAsset(PathToGitHubReleaseAsset) });
NuGet.TryPush(NuGetArtifactsFolder);
}
}
}


private async Task CreateReleaseNotes()
{
Logger.Log("Creating release notes");
var generator = ChangeLogFrom(Owner, ProjectName, BuildEnvironment.GitHubAccessToken).SinceLatestTag();
if (!Git.Default.IsTagCommit())
{
generator = generator.IncludeUnreleased();
}
await generator.Generate(PathToReleaseNotes);
}
78 changes: 78 additions & 0 deletions build/BuildContext.csx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#load "nuget:Dotnet.Build, 0.2.8"
using static FileUtils;
using System.Xml.Linq;

string Version;

string GitHubArtifactsFolder;

string GitHubReleaseAsset;

string GitHubReleaseNoteAsset;

string NuGetArtifactsFolder;

string ChocolateyArtifactsFolder;

string PublishArtifactsFolder;

string PublishArchiveFolder;

string DotnetScriptProjectFolder;

string DotnetScriptCoreProjectFolder;

string DotnetScriptDependencyModelProjectFolder;

string DotnetScriptDependencyModelNuGetProjectFolder;

string Root;

string TestProjectFolder;

string PathToReleaseNotes;

string PathToGitHubReleaseAsset;

string Owner;

string ProjectName;

Owner = "filipw";
ProjectName = "dotnet-script";
Root = FileUtils.GetScriptFolder();

DotnetScriptProjectFolder = Path.Combine(Root, "..", "src", "Dotnet.Script");
DotnetScriptCoreProjectFolder = Path.Combine(Root, "..", "src", "Dotnet.Script.Core");
DotnetScriptDependencyModelProjectFolder = Path.Combine(Root, "..", "src", "Dotnet.Script.DependencyModel");
DotnetScriptDependencyModelNuGetProjectFolder = Path.Combine(Root, "..", "src", "Dotnet.Script.DependencyModel.NuGet");
TestProjectFolder = Path.Combine(Root, "..", "src", "Dotnet.Script.Tests");

var artifactsFolder = CreateDirectory(Root, "Artifacts");
GitHubArtifactsFolder = CreateDirectory(artifactsFolder, "GitHub");
NuGetArtifactsFolder = CreateDirectory(artifactsFolder, "NuGet");
ChocolateyArtifactsFolder = CreateDirectory(artifactsFolder, "Chocolatey");
PublishArtifactsFolder = CreateDirectory(artifactsFolder, "Publish", ProjectName);
PublishArchiveFolder = Path.Combine(PublishArtifactsFolder, "..");

PathToReleaseNotes = Path.Combine(GitHubArtifactsFolder, "ReleaseNotes.md");

Version = ReadVersion();

PathToGitHubReleaseAsset = Path.Combine(GitHubArtifactsFolder, $"{ProjectName}.{Version}.zip");

string ReadVersion()
{
var projectFile = XDocument.Load(Directory.GetFiles(DotnetScriptProjectFolder, "*.csproj").Single());
var versionPrefix = projectFile.Descendants("VersionPrefix").SingleOrDefault()?.Value;
var versionSuffix = projectFile.Descendants("VersionSuffix").SingleOrDefault()?.Value;

if (versionSuffix != null)
{
return $"{versionPrefix}-{versionSuffix}";
}
else
{
return versionPrefix;
}
}
31 changes: 17 additions & 14 deletions build/Choco.csx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#load "FileUtils.csx"
#load "DotNet.csx"
#load "Command.csx"
#load "nuget:Dotnet.Build, 0.2.5"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏆


using System.Xml.Linq;

Expand All @@ -11,18 +9,24 @@ public static class Choco
/// </summary>
/// <param name="pathToProjectFolder">The path to the project folder.</param>
/// <param name="outputFolder">The path to the output folder (*.nupkg)</param>
public static void Pack(string pathToProjectFolder, string outputFolder)
{
DotNet.Publish(pathToProjectFolder);
Directory.CreateDirectory(outputFolder);
var pathToPublishFolder = FileUtils.FindDirectory(Path.Combine(pathToProjectFolder, @"bin\Release"),"publish");
public static void Pack(string pathToProjectFolder, string pathToBinaries, string outputFolder)
{
File.Copy(Path.Combine(pathToProjectFolder, "../../LICENSE"), Path.Combine("Chocolatey","tools","LICENSE.TXT"), true);
string pathToProjectFile = FileUtils.FindFile(pathToProjectFolder, "*.csproj");
CreateSpecificationFromProject(pathToProjectFile, pathToPublishFolder);
string pathToProjectFile = Directory.GetFiles(pathToProjectFolder, "*.csproj").Single();
CreateSpecificationFromProject(pathToProjectFile, pathToBinaries);
Command.Execute("choco.exe", $@"pack Chocolatey\chocolatey.nuspec --outputdirectory {outputFolder}");
}

private static void CreateSpecificationFromProject(string pathToProjectFile, string pathToPublishFolder)
public static void Push(string packagesFolder, string apiKey, string source = "https://push.chocolatey.org/")
{
var packageFiles = Directory.GetFiles(packagesFolder, "*.nupkg");
foreach(var packageFile in packageFiles)
{
Command.Execute("choco.exe", $"push {packageFile} --source {source} --key {apiKey}");
}
}

private static void CreateSpecificationFromProject(string pathToProjectFile, string pathToBinaries)
{
var projectFile = XDocument.Load(pathToProjectFile);
var authors = projectFile.Descendants("Authors").SingleOrDefault()?.Value;
Expand Down Expand Up @@ -65,9 +69,8 @@ public static class Choco
packageElement.Add(filesElement);

// Add the tools folder that contains "ChocolateyInstall.ps1"
filesElement.Add(CreateFileElement(@"tools\*.*",@"Dotnet.Script\tools"));
var srcFolder = Path.Combine("../",pathToPublishFolder).WithWindowsSlashes();
var srcGlobPattern = $@"{srcFolder}\**\*";
filesElement.Add(CreateFileElement(@"tools\*.*",$@"{packageId}\tools"));
var srcGlobPattern = $@"{pathToBinaries}\**\*";
filesElement.Add(CreateFileElement(srcGlobPattern,packageId));

using (var fileStream = new FileStream("Chocolatey/chocolatey.nuspec",FileMode.Create))
Expand Down
47 changes: 0 additions & 47 deletions build/Command.csx

This file was deleted.

37 changes: 0 additions & 37 deletions build/DotNet.csx

This file was deleted.

Loading