@@ -7,106 +7,111 @@ import * as gulp from 'gulp';
7
7
import * as fs from 'fs' ;
8
8
import minimist from 'minimist' ;
9
9
import { Octokit } from '@octokit/rest' ;
10
+ import { allNugetPackages , NugetPackageInfo , platformSpecificPackages } from './offlinePackagingTasks' ;
11
+ import { PlatformInformation } from '../src/shared/platform' ;
12
+ import path from 'path' ;
10
13
11
14
interface Options {
12
15
releaseVersion : string ;
13
16
releaseCommit : string ;
14
17
// Even it is specified as boolean, it would still be parsed as string in compiled js.
15
18
dryRun : string ;
19
+ githubPAT : string | null ;
16
20
}
17
21
18
- gulp . task ( 'createTags' , async ( ) : Promise < void > => {
22
+ gulp . task ( 'createTags:roslyn ' , async ( ) : Promise < void > => {
19
23
const options = minimist < Options > ( process . argv . slice ( 2 ) ) ;
24
+
25
+ return createTagsAsync (
26
+ options ,
27
+ 'dotnet' ,
28
+ 'roslyn' ,
29
+ async ( ) => getCommitFromNugetAsync ( allNugetPackages . roslyn ) ,
30
+ ( releaseVersion : string ) : [ string , string ] => [
31
+ `VSCode-CSharp-${ releaseVersion } ` ,
32
+ `${ releaseVersion } VSCode C# extension release` ,
33
+ ]
34
+ ) ;
35
+ } ) ;
36
+
37
+ gulp . task ( 'createTags:razor' , async ( ) : Promise < void > => {
38
+ const options = minimist < Options > ( process . argv . slice ( 2 ) ) ;
39
+
40
+ return createTagsAsync (
41
+ options ,
42
+ 'dotnet' ,
43
+ 'razor' ,
44
+ async ( ) => getCommitFromNugetAsync ( allNugetPackages . razor ) ,
45
+ ( releaseVersion : string ) : [ string , string ] => [
46
+ `VSCode-CSharp-${ releaseVersion } ` ,
47
+ `${ releaseVersion } VSCode C# extension release` ,
48
+ ]
49
+ ) ;
50
+ } ) ;
51
+
52
+ gulp . task ( 'createTags:vscode-csharp' , async ( ) : Promise < void > => {
53
+ const options = minimist < Options > ( process . argv . slice ( 2 ) ) ;
54
+
55
+ return createTagsAsync (
56
+ options ,
57
+ 'dotnet' ,
58
+ 'vscode-csharp' ,
59
+ async ( ) => options . releaseCommit ,
60
+ ( releaseVersion : string ) : [ string , string ] => [ `v${ releaseVersion } ` , releaseVersion ]
61
+ ) ;
62
+ } ) ;
63
+
64
+ gulp . task ( 'createTags' , gulp . series ( 'createTags:roslyn' , 'createTags:razor' , 'createTags:vscode-csharp' ) ) ;
65
+
66
+ async function createTagsAsync (
67
+ options : Options ,
68
+ owner : string ,
69
+ repo : string ,
70
+ getCommit : ( ) => Promise < string | null > ,
71
+ getTagAndMessage : ( releaseVersion : string ) => [ string , string ]
72
+ ) : Promise < void > {
20
73
console . log ( `releaseVersion: ${ options . releaseVersion } ` ) ;
21
74
console . log ( `releaseCommit: ${ options . releaseCommit } ` ) ;
22
- const dryRun = options . dryRun . toLocaleLowerCase ( ) === 'true' ;
75
+ const dryRun = options . dryRun ? options . dryRun . toLocaleLowerCase ( ) === 'true' : false ;
23
76
console . log ( `dry run: ${ dryRun } ` ) ;
24
77
25
- const roslynCommit = await findRoslynCommitAsync ( ) ;
26
- if ( ! roslynCommit ) {
27
- logError ( 'Failed to find roslyn commit.' ) ;
78
+ const commit = await getCommit ( ) ;
79
+ if ( ! commit ) {
80
+ logError ( 'Failed to find commit.' ) ;
28
81
return ;
29
82
}
30
83
84
+ const [ tag , message ] = getTagAndMessage ( options . releaseVersion ) ;
85
+ console . log ( `tag: ${ tag } ` ) ;
86
+ console . log ( `message: ${ message } ` ) ;
87
+
31
88
// The compiled option value in js type is 'any' type.
32
89
if ( dryRun ) {
33
90
console . log ( 'Tagging is skipped in dry run mode.' ) ;
34
91
return ;
35
92
} else {
36
- const tagCreatedInRoslyn = await tagRepoAsync (
37
- 'dotnet' ,
38
- 'roslyn' ,
39
- roslynCommit ,
40
- `VSCode-CSharp-${ options . releaseVersion } ` ,
41
- `${ options . releaseVersion } VSCode C# extension release`
42
- ) ;
43
-
44
- if ( ! tagCreatedInRoslyn ) {
45
- logError ( 'Failed to tag roslyn' ) ;
46
- return ;
47
- }
48
-
49
- console . log ( 'tag created in roslyn' ) ;
93
+ const tagCreated = await tagRepoAsync ( owner , repo , commit , tag , message , options . githubPAT ) ;
50
94
51
- const tagCreatedInVsCodeCsharp = await tagRepoAsync (
52
- 'dotnet' ,
53
- 'vscode-csharp' ,
54
- options . releaseCommit ,
55
- `v${ options . releaseVersion } ` ,
56
- options . releaseVersion
57
- ) ;
58
-
59
- if ( ! tagCreatedInVsCodeCsharp ) {
60
- logError ( 'Failed to tag vscode-csharp' ) ;
95
+ if ( ! tagCreated ) {
96
+ logError ( `Failed to tag '${ owner } /${ repo } '` ) ;
61
97
return ;
62
98
}
63
99
64
- console . log ( 'tag created in vscode-csharp' ) ;
65
- }
66
- } ) ;
67
-
68
- async function findRoslynCommitAsync ( ) : Promise < string | null > {
69
- const packageJsonString = fs . readFileSync ( './package.json' ) . toString ( ) ;
70
- const packageJson = JSON . parse ( packageJsonString ) ;
71
- const roslynVersion = packageJson [ 'defaults' ] [ 'roslyn' ] ;
72
- if ( ! roslynVersion ) {
73
- logError ( "Can't find roslyn version in package.json" ) ;
74
- return null ;
75
- }
76
-
77
- console . log ( `Roslyn version is ${ roslynVersion } ` ) ;
78
- // Nuget package should exist under out/.nuget/ since we have run the install dependencies task.
79
- const nuspecFile = fs
80
- . readFileSync (
81
- `out/.nuget/microsoft.codeanalysis.languageserver.linux-x64/${ roslynVersion } /microsoft.codeanalysis.languageserver.linux-x64.nuspec`
82
- )
83
- . toString ( ) ;
84
- const results = / c o m m i t = " ( .* ) " / . exec ( nuspecFile ) ;
85
- if ( results == null || results . length == 0 ) {
86
- logError ( 'Failed to find commit number from nuspec file' ) ;
87
- return null ;
100
+ console . log ( `tag created in '${ owner } /${ repo } '` ) ;
88
101
}
89
-
90
- if ( results . length != 2 ) {
91
- logError ( 'Unexpected regex match result from nuspec file.' ) ;
92
- return null ;
93
- }
94
-
95
- const commitNumber = results [ 1 ] ;
96
- console . log ( `commitNumber is ${ commitNumber } ` ) ;
97
- return commitNumber ;
98
102
}
99
103
100
104
async function tagRepoAsync (
101
105
owner : string ,
102
106
repo : string ,
103
107
commit : string ,
104
108
releaseTag : string ,
105
- tagMessage : string
109
+ tagMessage : string ,
110
+ githubPAT : string | null
106
111
) : Promise < boolean > {
107
- const pat = process . env [ 'GitHubPAT' ] ;
112
+ const pat = githubPAT ?? process . env [ 'GitHubPAT' ] ;
108
113
if ( ! pat ) {
109
- throw 'No GitHub Pat found.' ;
114
+ throw 'No GitHub Pat found. Specify with --githubPAT or set GitHubPAT environment variable. ' ;
110
115
}
111
116
112
117
console . log ( `Start to tag ${ owner } /${ repo } . Commit: ${ commit } , tag: ${ releaseTag } , message: ${ tagMessage } ` ) ;
@@ -144,3 +149,51 @@ async function tagRepoAsync(
144
149
function logError ( message : string ) : void {
145
150
console . log ( `##vso[task.logissue type=error]${ message } ` ) ;
146
151
}
152
+ async function getCommitFromNugetAsync ( packageInfo : NugetPackageInfo ) : Promise < string | null > {
153
+ const packageJsonString = fs . readFileSync ( './package.json' ) . toString ( ) ;
154
+ const packageJson = JSON . parse ( packageJsonString ) ;
155
+ const packageVersion = packageJson [ 'defaults' ] [ packageInfo . packageJsonName ] ;
156
+ if ( ! packageVersion ) {
157
+ logError ( `Can't find ${ packageInfo . packageJsonName } version in package.json` ) ;
158
+ return null ;
159
+ }
160
+
161
+ const platform = await PlatformInformation . GetCurrent ( ) ;
162
+ const vsixPlatformInfo = platformSpecificPackages . find (
163
+ ( p ) => p . platformInfo . platform === platform . platform && p . platformInfo . architecture === platform . architecture
164
+ ) ! ;
165
+
166
+ const packageName = packageInfo . getPackageName ( vsixPlatformInfo ) ;
167
+ console . log ( `${ packageName } version is ${ packageVersion } ` ) ;
168
+
169
+ // Nuget package should exist under out/.nuget/ since we have run the install dependencies task.
170
+ const packageDir = path . join ( 'out' , '.nuget' , packageName , packageVersion ) ;
171
+ const nuspecFiles = fs . readdirSync ( packageDir ) . filter ( ( file ) => file . endsWith ( '.nuspec' ) ) ;
172
+
173
+ if ( nuspecFiles . length === 0 ) {
174
+ logError ( `No .nuspec file found in ${ packageDir } ` ) ;
175
+ return null ;
176
+ }
177
+
178
+ if ( nuspecFiles . length > 1 ) {
179
+ logError ( `Multiple .nuspec files found in ${ packageDir } ` ) ;
180
+ return null ;
181
+ }
182
+
183
+ const nuspecFilePath = path . join ( packageDir , nuspecFiles [ 0 ] ) ;
184
+ const nuspecFile = fs . readFileSync ( nuspecFilePath ) . toString ( ) ;
185
+ const results = / c o m m i t = " ( .* ) " / . exec ( nuspecFile ) ;
186
+ if ( results == null || results . length == 0 ) {
187
+ logError ( 'Failed to find commit number from nuspec file' ) ;
188
+ return null ;
189
+ }
190
+
191
+ if ( results . length != 2 ) {
192
+ logError ( 'Unexpected regex match result from nuspec file.' ) ;
193
+ return null ;
194
+ }
195
+
196
+ const commitNumber = results [ 1 ] ;
197
+ console . log ( `commitNumber is ${ commitNumber } ` ) ;
198
+ return commitNumber ;
199
+ }
0 commit comments