Skip to content

Commit 54a883b

Browse files
authored
Merge pull request dotnet-script#237 from filipw/build/continuous-deployment
Build/continuous deployment
2 parents 664f320 + 8da36ae commit 54a883b

File tree

9 files changed

+162
-308
lines changed

9 files changed

+162
-308
lines changed

appveyor.yml

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
11
version: 1.0.{build}
22
image: Visual Studio 2017
3+
4+
install:
5+
- cmd: choco install dotnet.script
6+
37
build_script:
4-
- ps: >-
5-
cd .\build\
8+
- cmd: >-
9+
cd build
610
7-
.\install-dotnet-script.ps1
8-
- cmd:
9-
dotnet .\dotnet-script\dotnet-script.dll build.csx
11+
refreshenv
12+
13+
dotnet script build.csx
1014
11-
test: off
1215
artifacts:
13-
- path: /**/Dotnet.Script*.nupkg
16+
- path: build\Artifacts\Chocolatey\*.nupkg
1417
name: Chocolatey Packages
15-
# Uncomment this to enable deploy on repo tagging
16-
# deploy:
17-
# provider: Chocolatey
18-
# api_key:
19-
# secure: [Your API key goes here]
20-
# skip_symbols: false
21-
# artifact: /.*\.nupkg/
22-
# on:
23-
# appveyor_repo_tag: true
18+
19+
- path: build\Artifacts\NuGet\*.nupkg
20+
name: NuGet Packages
21+
22+
- path: build\Artifacts\GitHub\*.zip
23+
name: GitHub
24+
25+
test: off
26+
environment:
27+
IS_SECURE_BUILDENVIRONMENT:
28+
secure: xU2zj54rFEPVqg/UuGU/DA==
29+
GITHUB_REPO_TOKEN:
30+
secure: AzNlvlKMzcoPNzawN3Hv48N6dzPa0N57HdFfAXP2cELBp9uiwJxtLdKWuDhZyf21
31+
NUGET_APIKEY:
32+
secure: 81vsB74sZV0IlV1Ru/qKPbaDS47lQ80aeOLWCPmlvak7O/RA9EqqFqWVxZFS0ora
33+
CHOCO_APIKEY:
34+
secure: scd8oB50KqKDRvt/+TSgUJavZzY39iqqa+1AZmj1CGue1/vjWJn6vIO4sMhN+d2l

build/Build.csx

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,49 @@
11
#! "netcoreapp2.0"
2-
#r "nuget:NetStandard.Library,2.0.0"
3-
#r "nuget:Microsoft.DotNet.PlatformAbstractions, 2.0.3"
4-
#load "DotNet.csx"
2+
#load "nuget:Dotnet.Build, 0.2.8"
3+
#load "nuget:github-changelog, 0.1.4"
54
#load "Choco.csx"
6-
#load "NuGet.csx"
7-
#load "FileUtils.csx"
5+
#load "BuildContext.csx"
86

9-
using System.Runtime.InteropServices;
10-
11-
12-
var currentFolder = Path.GetDirectoryName(GetScriptPath());
13-
var root = Path.GetFullPath(Path.Combine(currentFolder, ".."));
14-
15-
16-
DotNet.Build(Path.Combine(root, "src","Dotnet.Script"));
17-
18-
DotNet.Test($"{root}/src/Dotnet.Script.Tests");
7+
using static ReleaseManagement;
8+
using static ChangeLog;
9+
using static FileUtils;
1910

11+
DotNet.Build(DotnetScriptProjectFolder);
12+
DotNet.Test(TestProjectFolder);
13+
DotNet.Publish(DotnetScriptProjectFolder, PublishArtifactsFolder);
2014

2115
// We only publish packages from Windows/AppVeyor
22-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
16+
if (BuildEnvironment.IsWindows)
2317
{
24-
string packagesOutputFolder = Path.Combine(root, "build", "NuGet");
25-
DotNet.Pack(Path.Combine(root, "src" , "Dotnet.Script"), packagesOutputFolder);
26-
DotNet.Pack(Path.Combine(root, "src" , "Dotnet.Script.Core"), packagesOutputFolder);
27-
DotNet.Pack(Path.Combine(root, "src" , "Dotnet.Script.DependencyModel"), packagesOutputFolder);
28-
DotNet.Pack(Path.Combine(root, "src" , "Dotnet.Script.DependencyModel.NuGet"), packagesOutputFolder);
29-
DotNet.Publish($"{root}/src/Dotnet.Script");
30-
Choco.Pack($"{root}/src/Dotnet.Script","Chocolatey");
18+
DotNet.Pack(DotnetScriptProjectFolder, NuGetArtifactsFolder);
19+
DotNet.Pack(DotnetScriptCoreProjectFolder, NuGetArtifactsFolder);
20+
DotNet.Pack(DotnetScriptDependencyModelProjectFolder, NuGetArtifactsFolder);
21+
DotNet.Pack(DotnetScriptDependencyModelNuGetProjectFolder, NuGetArtifactsFolder);
22+
Choco.Pack(DotnetScriptProjectFolder, PublishArtifactsFolder, ChocolateyArtifactsFolder);
23+
Zip(PublishArchiveFolder, PathToGitHubReleaseAsset);
24+
25+
26+
if (BuildEnvironment.IsSecure)
27+
{
28+
await CreateReleaseNotes();
29+
30+
if (Git.Default.IsTagCommit())
31+
{
32+
Git.Default.RequreCleanWorkingTree();
33+
await ReleaseManagerFor(Owner,ProjectName,BuildEnvironment.GitHubAccessToken)
34+
.CreateRelease(Git.Default.GetLatestTag(), PathToReleaseNotes, new [] { new ZipReleaseAsset(PathToGitHubReleaseAsset) });
35+
NuGet.TryPush(NuGetArtifactsFolder);
36+
}
37+
}
3138
}
3239

33-
40+
private async Task CreateReleaseNotes()
41+
{
42+
Logger.Log("Creating release notes");
43+
var generator = ChangeLogFrom(Owner, ProjectName, BuildEnvironment.GitHubAccessToken).SinceLatestTag();
44+
if (!Git.Default.IsTagCommit())
45+
{
46+
generator = generator.IncludeUnreleased();
47+
}
48+
await generator.Generate(PathToReleaseNotes);
49+
}

build/BuildContext.csx

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#load "nuget:Dotnet.Build, 0.2.8"
2+
using static FileUtils;
3+
using System.Xml.Linq;
4+
5+
string Version;
6+
7+
string GitHubArtifactsFolder;
8+
9+
string GitHubReleaseAsset;
10+
11+
string GitHubReleaseNoteAsset;
12+
13+
string NuGetArtifactsFolder;
14+
15+
string ChocolateyArtifactsFolder;
16+
17+
string PublishArtifactsFolder;
18+
19+
string PublishArchiveFolder;
20+
21+
string DotnetScriptProjectFolder;
22+
23+
string DotnetScriptCoreProjectFolder;
24+
25+
string DotnetScriptDependencyModelProjectFolder;
26+
27+
string DotnetScriptDependencyModelNuGetProjectFolder;
28+
29+
string Root;
30+
31+
string TestProjectFolder;
32+
33+
string PathToReleaseNotes;
34+
35+
string PathToGitHubReleaseAsset;
36+
37+
string Owner;
38+
39+
string ProjectName;
40+
41+
Owner = "filipw";
42+
ProjectName = "dotnet-script";
43+
Root = FileUtils.GetScriptFolder();
44+
45+
DotnetScriptProjectFolder = Path.Combine(Root, "..", "src", "Dotnet.Script");
46+
DotnetScriptCoreProjectFolder = Path.Combine(Root, "..", "src", "Dotnet.Script.Core");
47+
DotnetScriptDependencyModelProjectFolder = Path.Combine(Root, "..", "src", "Dotnet.Script.DependencyModel");
48+
DotnetScriptDependencyModelNuGetProjectFolder = Path.Combine(Root, "..", "src", "Dotnet.Script.DependencyModel.NuGet");
49+
TestProjectFolder = Path.Combine(Root, "..", "src", "Dotnet.Script.Tests");
50+
51+
var artifactsFolder = CreateDirectory(Root, "Artifacts");
52+
GitHubArtifactsFolder = CreateDirectory(artifactsFolder, "GitHub");
53+
NuGetArtifactsFolder = CreateDirectory(artifactsFolder, "NuGet");
54+
ChocolateyArtifactsFolder = CreateDirectory(artifactsFolder, "Chocolatey");
55+
PublishArtifactsFolder = CreateDirectory(artifactsFolder, "Publish", ProjectName);
56+
PublishArchiveFolder = Path.Combine(PublishArtifactsFolder, "..");
57+
58+
PathToReleaseNotes = Path.Combine(GitHubArtifactsFolder, "ReleaseNotes.md");
59+
60+
Version = ReadVersion();
61+
62+
PathToGitHubReleaseAsset = Path.Combine(GitHubArtifactsFolder, $"{ProjectName}.{Version}.zip");
63+
64+
string ReadVersion()
65+
{
66+
var projectFile = XDocument.Load(Directory.GetFiles(DotnetScriptProjectFolder, "*.csproj").Single());
67+
var versionPrefix = projectFile.Descendants("VersionPrefix").SingleOrDefault()?.Value;
68+
var versionSuffix = projectFile.Descendants("VersionSuffix").SingleOrDefault()?.Value;
69+
70+
if (versionSuffix != null)
71+
{
72+
return $"{versionPrefix}-{versionSuffix}";
73+
}
74+
else
75+
{
76+
return versionPrefix;
77+
}
78+
}

build/Choco.csx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#load "FileUtils.csx"
2-
#load "DotNet.csx"
3-
#load "Command.csx"
1+
#load "nuget:Dotnet.Build, 0.2.5"
42

53
using System.Xml.Linq;
64

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

25-
private static void CreateSpecificationFromProject(string pathToProjectFile, string pathToPublishFolder)
20+
public static void Push(string packagesFolder, string apiKey, string source = "https://push.chocolatey.org/")
21+
{
22+
var packageFiles = Directory.GetFiles(packagesFolder, "*.nupkg");
23+
foreach(var packageFile in packageFiles)
24+
{
25+
Command.Execute("choco.exe", $"push {packageFile} --source {source} --key {apiKey}");
26+
}
27+
}
28+
29+
private static void CreateSpecificationFromProject(string pathToProjectFile, string pathToBinaries)
2630
{
2731
var projectFile = XDocument.Load(pathToProjectFile);
2832
var authors = projectFile.Descendants("Authors").SingleOrDefault()?.Value;
@@ -65,9 +69,8 @@ public static class Choco
6569
packageElement.Add(filesElement);
6670

6771
// Add the tools folder that contains "ChocolateyInstall.ps1"
68-
filesElement.Add(CreateFileElement(@"tools\*.*",@"Dotnet.Script\tools"));
69-
var srcFolder = Path.Combine("../",pathToPublishFolder).WithWindowsSlashes();
70-
var srcGlobPattern = $@"{srcFolder}\**\*";
72+
filesElement.Add(CreateFileElement(@"tools\*.*",$@"{packageId}\tools"));
73+
var srcGlobPattern = $@"{pathToBinaries}\**\*";
7174
filesElement.Add(CreateFileElement(srcGlobPattern,packageId));
7275

7376
using (var fileStream = new FileStream("Chocolatey/chocolatey.nuspec",FileMode.Create))

build/Command.csx

Lines changed: 0 additions & 47 deletions
This file was deleted.

build/DotNet.csx

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)