-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickstart.ps1
More file actions
222 lines (188 loc) · 9.57 KB
/
quickstart.ps1
File metadata and controls
222 lines (188 loc) · 9.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
Param(
[Parameter(HelpMessage = "The name of the repository owner")]
[string]$repoOwner,
[Parameter(HelpMessage = "The name of the repository to create")]
[ValidateNotNullorEmpty()]
[string]$repo,
[Parameter(HelpMessage = "A description of the repository")]
[string]$repoDescription,
[Parameter(HelpMessage = "Name of the Bot account used to publish documentation")]
[string]$documentBotName,
[Parameter(HelpMessage = "Should a basic VS project be set up or not")]
[bool]$initProject,
[Parameter(HelpMessage = "Name of organization if account is not for a user")]
[bool]$forOrganization
);
if(!$repo)
{
Write-Error "Repo name is required";
return;
}
$executionDir = Get-Location
# Initialize a new repository
Write-Host "Initializing Git repo...";
git init $repo;
Set-Location $repo;
# Add NineTail Labs VisualStudio .gitignore
Write-Host "Grabbing VisualStudio .gitignore...";
Invoke-WebRequest https://raw.githubusercontent.com/NinetailLabs/CakeScripts/master/templates/ninetaillabs.gitignore -OutFile .gitignore;
# Add Cake bootstrap script
Write-Host "Grabbing Cake bootstrap script...";
Invoke-WebRequest https://raw.githubusercontent.com/NinetailLabs/CakeScripts/master/templates/build.ps1 -OutFile build.ps1
# Add CakeScripts as a Submodule
Write-Host "Adding CakeScripts as Git submodule...";
git submodule add -b master https://github.com/NinetailLabs/CakeScripts.git;
# Copy template.build.cake to root
Write-Host "Copying build.cake to repo root...";
Copy-Item -Path ".\CakeScripts\templates\template.build.cake" -Destination "build.cake";
if($initProject)
{
Write-Host "Initializing DotNetCore library";
# Create solution file
dotnet new sln
# Copy the NineTailLabs ReSharper setting for file layouts
Copy-Item -Path ".\CakeScripts\visualstudio\NineTailLabs.DotSettings" -Destination "NineTailLabs.DotSettings";
# Create the ClassLibrary project for NetStandard2.0 and add it to the solution
dotnet new classlib -f netstandard2.0 -o $repo
dotnet sln "$repo.sln" add ".\$repo\$repo.csproj"
# Add base Nuget packages
dotnet add ".\$repo\$repo.csproj" package SemVer.Git.MSBuild -v 1.3.0
dotnet add ".\$repo\$repo.csproj" package Microsoft.SourceLink.GitHub -v 1.0.0
# Copy empty nuspec file to the project directory
Copy-Item -Path ".\CakeScripts\visualstudio\Empty.nuspec" -Destination ".\$repo\$repo.nuspec";
# Copt the SemVer.Git.MSBuild .props file we use as the one from the pacakge is not copied (and details are different)
Copy-Item -Path ".\CakeScripts\visualstudio\SemVer.MSBuild.props" -Destination ".\$repo\SemVer.MSBuild.props";
# Create the test project and add it to the solution
dotnet new classlib -f net5.0 -o "$repo.Tests"
dotnet sln "$repo.sln" add ".\$repo.Tests\$repo.Tests.csproj"
# Add test Nuget packages
dotnet add ".\$repo.Tests\$repo.Tests.csproj" package Microsoft.NET.Test.Sdk
dotnet add ".\$repo.Tests\$repo.Tests.csproj" package xunit
dotnet add ".\$repo.Tests\$repo.Tests.csproj" package xunit.runner.visualstudio
dotnet add ".\$repo.Tests\$repo.Tests.csproj" package FluentAssertions
dotnet add ".\$repo.Tests\$repo.Tests.csproj" package Moq
dotnet add ".\$repo.Tests\$repo.Tests.csproj" Appveyor.TestLogger
dotnet add ".\$repo.Tests\$repo.Tests.csproj" altcover
# Do package restore
dotnet restore
# Copy appveyor.yml template to the project root
Copy-Item -Path ".\CakeScripts\templates\appveyor.yml" -Destination "appveyor.yml";
# Do not continue if the user did not provide a token file
if (!(Test-Path "$executionDir\Tokens.json"))
{
Write-Host "Could not find Tokens.json - Automated repository creation will not execute";
return;
}
# Read the tokens from the Tokens.json file
$tokens = Get-Content -Raw -Path $executionDir\Tokens.json | ConvertFrom-Json
if($tokens.githubToken)
{
Write-Host "Creating GitHub repository...";
. .\CakeScripts\scripts\GitHubRepo.ps1
if($forOrganization)
{
New-GitHubRepository -Name $repo -Description $repoDescription -UserToken $tokens.githubToken -Organization $repoOwner
}
else
{
New-GitHubRepository -Name $repo -Description $repoDescription -UserToken $tokens.githubToken
}
git remote add origin "git@github.com:$repoOwner/$repo.git"
if($documentBotName)
{
Write-Host "Setting up document publishing bot link";
.\CakeScripts\scripts\GitHubCollaborator.ps1 -repoOwner $repoOwner -repo $repo -collaboratorName $documentBotName -githubToken $tokens.githubToken
}
}
else
{
Write-Host "No Github token could be found - No service setup will be done" -ForegroundColor Yellow;
return;
}
if($tokens.coverallsToken)
{
Write-Host "Creating Coveralls repo...";
.\CakeScripts\scripts\CreateCoverallsRepo.ps1 -repoOwner $repoOwner -repo $repo -coverallstoken $tokens.coverallsToken
}
Write-Host "Repository setup completed";
Write-Host "";
Write-Host "User interaction is required to complete setup of AppVeyor.yml" -ForegroundColor Green;
Write-Host "Please open the appveyor.yml file then press any key to continue" -ForegroundColor Green;
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
# Guide user to get Nuget token, encrypt it and copy it into the appveyor.yml file
Write-Host "---";
Write-Host "To publish your project to Nuget an access token is required";
Write-Host "If you already have a valid, encrypted token you can add it to appveyor.yml and skip this step.";
Write-Host "Do you need a token (y/n)" -ForegroundColor Green;
$key = Read-Host;
if($key -eq "y")
{
Write-Host "---";
Write-Host "The Nuget access token page will be opened as well as the AppVeyor page to encrypt data.";
Write-Host "Copy your access token from Nuget, then encrypt it on the AppVeyor page and paste it into appveyor.yml in the place of EncryptedNugetKeyGoesHere";
Write-Host "Press any key to open the pages" -ForegroundColor Green;
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
Start-Process "https://ci.appveyor.com/tools/encrypt";
Start-Process "https://www.nuget.org/account/apikeys";
Write-Host "Press any key to continue" -ForegroundColor Green;
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
}
# Guide user to get Coveralls token, encrypt it and copy it into the appveyor.yml file
Write-Host "---";
Write-Host "To be able to push coverage results to Coveralls an access token is required, this token was created when the Coveralls project was set up";
Write-Host "The Coveralls project page will be opened. Please copy the token, encrypt it on the AppVeyor page and paste it into appveyor.yml in the place of EncryptedCoverallsRepoTokenGoesHere";
Write-Host "Press any key to open the Coverall project page" -ForegroundColor Green;
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
Start-Process "https://coveralls.io/github/$repoOwner/$repo";
Write-Host "Press any key to continue" -ForegroundColor Green;
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
# Guide user to get token for publishing documentation to gh-pages
Write-host "---"
Write-Host "To be able to publish documentation a token is required for the user that can publish the documentation.";
Write-Host "If you already have an encrypted token for publishing you can add it to appvyor.yml and skip this step";
Write-Host "Do you need a token (y/n)" -ForegroundColor Green;
$key = Read-Host;
if($key -eq "y")
{
Write-Host "The GitHub personal access token page will be opened";
Write-Host "Create a new token with the public_repo claim, encrypt it on the AppVeyor page and paste it into appveyor.yml in the place of EncryptedBotTokenGoesHere";
Write-Host "Press any key to continue" -ForegroundColor Green;
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
}
# Ask user to close and save appveyor.yml
Write-Host "---";
Write-Host "Please save and close appveyor.yml";
Write-Host "Press any key to continue" -ForegroundColor Green;
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
# Ask user if new repository should be pushed to GitHub
Write-Host "---";
Write-Host "Push the repository to GitHub (y/n)" -ForegroundColor Green;
$key = Read-Host;
if($key -eq "y")
{
Write-Host "Before the repository can be pushed to GitHub the build.cake script has to be completed";
Write-Host "Please complete the script, then press any key to continue" -ForegroundColor Green;
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
git add .
git commit -a -m "Initial commit"
# Create Git tag so that SemVer.Git.MSBuild has a valid starting point
git tag 1.0.0.0
git push --set-upstream origin master --tags
Write-Host "Set up gh-pages for this repository (y/n)" -ForegroundColor Green;
$key = Read-Host;
if($key -eq "y")
{
.\CakeScripts\scripts\GithubPagesInit.ps1
}
}
else
{
Write-Host "Repository will not be pushed to GitHub";
}
if($tokens.appVeyortoken)
{
Write-host "Creating AppVeyor project...";
.\CakeScripts\scripts\CreateAppVeyorRepo.ps1 -repoOwner $repoOwner -repo $repo -appveyortoken $tokens.appVeyortoken
}
}
Write-Host "Repository quickstart done";