Skip to content

Commit 73ef963

Browse files
committed
Enhance build process by adding packing functionality and updating Cake.Tool installation steps
1 parent 4e59e03 commit 73ef963

File tree

3 files changed

+77
-17
lines changed

3 files changed

+77
-17
lines changed

.github/workflows/main.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ jobs:
3030
dotnet-version: "8.0.x"
3131

3232
- name: Install Cake.Tool
33-
run: dotnet tool install --global Cake.Tool && dotnet tool restore
33+
run: |
34+
dotnet tool install --global Cake.Tool
35+
dotnet tool restore
3436
3537
- name: Run Cake build
3638
run: dotnet cake --target=Build

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -362,3 +362,4 @@ MigrationBackup/
362362
# Fody - auto-generated XML schema
363363
FodyWeavers.xsd
364364
.vscode/settings.json
365+
tools/Addins/*

build.cake

+73-16
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,76 @@
1-
var target = Argument("target", "Build");
1+
var target = Argument("target", "Pack");
22
var configuration = Argument("configuration", "Release");
33

4+
var assemblyName = "FreeGameNotifications";
5+
var solution = "./source/FreeGameNotifications.sln";
6+
var output = $"./source/bin/{configuration}";
7+
8+
// List of files to pack, everything else is ignored
9+
List<string> filesToPack = [
10+
"extension.yaml",
11+
$"{assemblyName}.dll",
12+
$"{assemblyName}.pdb",
13+
"icon.png",
14+
"en_US.xaml"
15+
];
16+
17+
private (string id, string version) ReadExtensionManifest()
18+
{
19+
var manifestPath = $"{output}/extension.yaml";
20+
var manifestLines = System.IO.File.ReadAllLines(manifestPath);
21+
22+
var id = manifestLines
23+
.FirstOrDefault(line => line.StartsWith("Id:"))
24+
?.Replace("Id: ", string.Empty);
25+
26+
var version = manifestLines
27+
.FirstOrDefault(line => line.StartsWith("Version:"))
28+
?.Replace("Version: ", string.Empty)
29+
?.Replace(".", "_");
30+
31+
Information("Reading extension.yaml: Id: {0}, Version: {1}", id, version);
32+
33+
return (id, version);
34+
}
35+
36+
string PackExtension()
37+
{
38+
// remove all files from output folder except the ones in filesToPack
39+
var files = System.IO.Directory.GetFiles(output, "*.*", System.IO.SearchOption.AllDirectories);
40+
41+
Information("Preparing to pack files");
42+
foreach (var file in files)
43+
{
44+
var name = System.IO.Path.GetFileName(file);
45+
if (!filesToPack.Contains(name))
46+
{
47+
Information("File not in filesToPack, removing: {0}", name);
48+
System.IO.File.Delete(file);
49+
}
50+
}
51+
52+
// Read extension manifest
53+
(var id, var version) = ReadExtensionManifest();
54+
var packedExtension = $"{output}/{id}_{version}.pext";
55+
56+
// Zip contents of output
57+
Zip(output, packedExtension);
58+
59+
return packedExtension;
60+
}
61+
462
Task("Clean")
5-
.WithCriteria(c => HasArgument("rebuild"))
663
.Does(() =>
764
{
8-
CleanDirectory($"./source/bin/{configuration}");
65+
CleanDirectory(output);
966
});
1067

1168
Task("Restore")
1269
.Does(() =>
1370
{
1471
// Restore NuGet packages
1572
Information("Restoring NuGet packages...");
16-
DotNetRestore("./source/FreeGameNotifications.sln");
73+
NuGetRestore(solution);
1774
});
1875

1976
Task("Build")
@@ -22,22 +79,22 @@ Task("Build")
2279
.Does(() =>
2380
{
2481
// Build the solution
25-
MSBuild("./source/FreeGameNotifications.sln", settings =>
82+
MSBuild(solution, settings =>
2683
{
2784
settings.SetConfiguration(configuration);
2885
});
2986
});
3087

31-
// Task("Pack")
32-
// .IsDependentOn("Build")
33-
// .Does(() =>
34-
// {
35-
// // Run toolbox.exe with parameters
36-
// var outputDir = $"./source/bin/{configuration}";
37-
// StartProcess("tools/toolbox.exe", new ProcessSettings
38-
// {
39-
// Arguments = $"pack {outputDir} {outputDir}"
40-
// });
41-
// });
88+
Task("Pack")
89+
.IsDependentOn("Build")
90+
.Does(async () =>
91+
{
92+
var packedExtension = PackExtension();
93+
94+
// upload packedExtension artifact to github
95+
Information("Packed extension: {0}", packedExtension);
96+
97+
await GitHubActions.Commands.UploadArtifact(new FilePath(packedExtension), packedExtension);
98+
});
4299

43100
RunTarget(target);

0 commit comments

Comments
 (0)