1
- var target = Argument ( "target" , "Build " ) ;
1
+ var target = Argument ( "target" , "Pack " ) ;
2
2
var configuration = Argument ( "configuration" , "Release" ) ;
3
3
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
+
4
62
Task ( "Clean" )
5
- . WithCriteria ( c => HasArgument ( "rebuild" ) )
6
63
. Does ( ( ) =>
7
64
{
8
- CleanDirectory ( $ "./source/bin/ { configuration } " ) ;
65
+ CleanDirectory ( output ) ;
9
66
} ) ;
10
67
11
68
Task ( "Restore" )
12
69
. Does ( ( ) =>
13
70
{
14
71
// Restore NuGet packages
15
72
Information ( "Restoring NuGet packages..." ) ;
16
- DotNetRestore ( "./source/FreeGameNotifications.sln" ) ;
73
+ NuGetRestore ( solution ) ;
17
74
} ) ;
18
75
19
76
Task ( "Build" )
@@ -22,22 +79,22 @@ Task("Build")
22
79
. Does ( ( ) =>
23
80
{
24
81
// Build the solution
25
- MSBuild ( "./source/FreeGameNotifications.sln" , settings =>
82
+ MSBuild ( solution , settings =>
26
83
{
27
84
settings . SetConfiguration ( configuration ) ;
28
85
} ) ;
29
86
} ) ;
30
87
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
+ } ) ;
42
99
43
100
RunTarget ( target ) ;
0 commit comments