Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit b0ffd07

Browse files
refactored build script
1 parent 77f3781 commit b0ffd07

2 files changed

Lines changed: 109 additions & 91 deletions

File tree

Dockerfile

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
FROM microsoft/dotnet:2.1.500-sdk-alpine3.7 AS build
22
ARG MYGET_API_KEY
3-
ARG MINVERBUILDMETADATA
43

54
RUN apk add --no-cache \
65
nodejs \
76
yarn \
87
libcurl
98

10-
WORKDIR /src
9+
WORKDIR /app/src
1110

1211
COPY ./src/*.sln ./
1312
COPY ./src/*/*.csproj ./
@@ -19,31 +18,30 @@ RUN dotnet restore --runtime=alpine.3.7-x64
1918

2019
COPY ./src .
2120

22-
WORKDIR /docs
21+
WORKDIR /app/docs
2322

2423
COPY ./docs/package.json ./docs/yarn.lock ./
2524

26-
WORKDIR /.git
25+
WORKDIR /app/.git
2726

2827
COPY ./.git .
2928

30-
WORKDIR /build
29+
WORKDIR /app/build
3130

3231
COPY ./build/build.csproj .
3332

3433
RUN dotnet restore
3534

3635
COPY ./build .
3736

38-
WORKDIR /
37+
WORKDIR /app
3938

40-
RUN MINVERBUILDMETADATA=$MINVERBUILDMETADATA \
41-
MYGET_API_KEY=$MYGET_API_KEY \
39+
RUN MYGET_API_KEY=$MYGET_API_KEY \
4240
dotnet run --project build/build.csproj
4341

4442
FROM microsoft/dotnet:2.1.6-runtime-deps-alpine3.7 AS runtime
4543

4644
WORKDIR /app
47-
COPY --from=build /publish ./
45+
COPY --from=build /app/publish ./
4846

4947
ENTRYPOINT ["/app/SqlStreamStore.HAL.DevServer"]

build/Program.cs

Lines changed: 102 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.IO;
33
using System.Linq;
44
using System.Runtime.InteropServices;
5+
using System.Threading.Tasks;
56
using static Bullseye.Targets;
67
using static SimpleExec.Command;
78

@@ -10,112 +11,131 @@ static class Program
1011
private const string ArtifactsDir = "artifacts";
1112
private const string PublishDir = "publish";
1213

13-
private const string Clean = nameof(Clean);
14-
private const string Init = nameof(Init);
15-
private const string GenerateDocumentation = nameof(GenerateDocumentation);
16-
private const string Build = nameof(Build);
17-
private const string RunTests = nameof(RunTests);
18-
private const string Pack = nameof(Pack);
19-
private const string Publish = nameof(Publish);
20-
private const string Push = nameof(Push);
14+
private static readonly string MYGET_API_KEY = Environment.GetEnvironmentVariable(nameof(MYGET_API_KEY));
2115

2216
public static void Main(string[] args)
2317
{
24-
var apiKey = Environment.GetEnvironmentVariable("MYGET_API_KEY");
25-
var srcDirectory = new DirectoryInfo("./src");
18+
const string clean = nameof(Clean);
19+
const string init = nameof(Init);
20+
const string generateDocumentation = nameof(GenerateDocumentation);
21+
const string build = nameof(Build);
22+
const string runTests = nameof(RunTests);
23+
const string pack = nameof(Pack);
24+
const string publish = nameof(Publish);
25+
const string push = nameof(Push);
2626

27-
Target(Clean, () =>
28-
{
29-
if (Directory.Exists(ArtifactsDir))
30-
{
31-
Directory.Delete(ArtifactsDir, true);
32-
}
27+
var srcDirectory = new DirectoryInfo("./src");
3328

34-
if (Directory.Exists(PublishDir))
35-
{
36-
Directory.Delete(PublishDir, true);
37-
}
38-
});
29+
Target(
30+
clean,
31+
Clean);
3932

4033
Target(
41-
Init,
42-
() =>
43-
{
44-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
45-
{
46-
Run("cmd", "/c yarn", "docs");
47-
}
48-
else
49-
{
50-
Run("yarn", string.Empty, "docs");
51-
}
52-
});
34+
init,
35+
Init);
5336

5437
Target(
55-
GenerateDocumentation,
56-
DependsOn(Init),
38+
generateDocumentation,
39+
DependsOn(init),
5740
ForEach(SchemaDirectories(srcDirectory)),
58-
schemaDirectory =>
59-
RunAsync(
60-
"node",
61-
$"node_modules/@adobe/jsonschema2md/cli.js -n --input {schemaDirectory} --out {schemaDirectory} --schema-out=-",
62-
"docs"));
41+
GenerateDocumentation);
6342

6443
Target(
65-
Build,
66-
DependsOn(GenerateDocumentation),
67-
() => Run(
68-
"dotnet",
69-
"build src/SqlStreamStore.HAL.sln -c Release"));
44+
build,
45+
DependsOn(generateDocumentation),
46+
Build);
7047

7148
Target(
72-
RunTests,
73-
DependsOn(Build),
74-
() => Run(
75-
"dotnet",
76-
$"test src/SqlStreamStore.HAL.Tests -c Release -r ../../{ArtifactsDir} --verbosity normal --no-build -l trx;LogFileName=SqlStreamStore.HAL.Tests.xml"));
49+
runTests,
50+
DependsOn(build),
51+
RunTests);
7752

7853
Target(
79-
Publish,
80-
DependsOn(Build),
81-
() => Run(
82-
"dotnet",
83-
$"publish --configuration=Release --output=../../{PublishDir} --runtime=alpine.3.7-x64 /p:ShowLinkerSizeComparison=true src/SqlStreamStore.HAL.DevServer"));
54+
publish,
55+
DependsOn(build),
56+
Publish);
8457

8558
Target(
86-
Pack,
87-
DependsOn(Publish),
88-
() => Run(
89-
"dotnet",
90-
$"pack src/SqlStreamStore.HAL -c Release -o ../../{ArtifactsDir} --no-build"));
59+
pack,
60+
DependsOn(publish),
61+
Pack);
9162

9263
Target(
93-
Push,
94-
DependsOn(Pack),
95-
() =>
96-
{
97-
var packagesToPush = Directory.GetFiles(ArtifactsDir, "*.nupkg", SearchOption.TopDirectoryOnly);
98-
Console.WriteLine($"Found packages to publish: {string.Join("; ", packagesToPush)}");
99-
100-
if (string.IsNullOrWhiteSpace(apiKey))
101-
{
102-
Console.WriteLine("MyGet API key not available. Packages will not be pushed.");
103-
return;
104-
}
105-
106-
foreach (var packageToPush in packagesToPush)
107-
{
108-
Run(
109-
"dotnet",
110-
$"nuget push {packageToPush} -s https://www.myget.org/F/sqlstreamstore/api/v3/index.json -k {apiKey}");
111-
}
112-
});
113-
114-
Target("default", DependsOn(Clean, RunTests, Push));
64+
push,
65+
DependsOn(pack),
66+
Push);
67+
68+
Target("default", DependsOn(clean, runTests, push));
11569

11670
RunTargets(args.Concat(new[] {"--parallel"}));
11771
}
11872

73+
private static readonly Action Init = () =>
74+
{
75+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
76+
{
77+
Run("cmd", "/c yarn", "docs");
78+
}
79+
else
80+
{
81+
Run("yarn", string.Empty, "docs");
82+
}
83+
};
84+
85+
private static readonly Action Clean = () =>
86+
{
87+
if (Directory.Exists(ArtifactsDir))
88+
{
89+
Directory.Delete(ArtifactsDir, true);
90+
}
91+
92+
if (Directory.Exists(PublishDir))
93+
{
94+
Directory.Delete(PublishDir, true);
95+
}
96+
};
97+
98+
private static readonly Func<string, Task> GenerateDocumentation = schemaDirectory =>
99+
RunAsync(
100+
"node",
101+
$"node_modules/@adobe/jsonschema2md/cli.js -n --input {schemaDirectory} --out {schemaDirectory} --schema-out=-",
102+
"docs");
103+
104+
private static readonly Action Build = () => Run(
105+
"dotnet",
106+
"build src/SqlStreamStore.HAL.sln --configuration Release");
107+
108+
private static readonly Action RunTests = () => Run(
109+
"dotnet",
110+
$"test src/SqlStreamStore.HAL.Tests --configuration Release --results-directory ../../{ArtifactsDir} --verbosity normal --no-build -l trx;LogFileName=SqlStreamStore.HAL.Tests.xml");
111+
112+
private static readonly Action Publish = () => Run(
113+
"dotnet",
114+
$"publish --configuration=Release --output=../../{PublishDir} --runtime=alpine.3.7-x64 /p:ShowLinkerSizeComparison=true src/SqlStreamStore.HAL.DevServer");
115+
116+
private static readonly Action Pack = () => Run(
117+
"dotnet",
118+
$"pack src/SqlStreamStore.HAL --configuration Release --output ../../{ArtifactsDir} --no-build");
119+
120+
private static readonly Action Push = () =>
121+
{
122+
var packagesToPush = Directory.GetFiles(ArtifactsDir, "*.nupkg", SearchOption.TopDirectoryOnly);
123+
Console.WriteLine($"Found packages to publish: {string.Join("; ", packagesToPush)}");
124+
125+
if (string.IsNullOrWhiteSpace(MYGET_API_KEY))
126+
{
127+
Console.WriteLine("MyGet API key not available. Packages will not be pushed.");
128+
return;
129+
}
130+
131+
foreach (var packageToPush in packagesToPush)
132+
{
133+
Run(
134+
"dotnet",
135+
$"nuget push {packageToPush} -s https://www.myget.org/F/sqlstreamstore/api/v3/index.json -k {MYGET_API_KEY}");
136+
}
137+
};
138+
119139
private static string[] SchemaDirectories(DirectoryInfo srcDirectory)
120140
=> srcDirectory.GetFiles("*.schema.json", SearchOption.AllDirectories)
121141
.Select(schemaFile => schemaFile.DirectoryName)

0 commit comments

Comments
 (0)