@@ -30,7 +30,6 @@ package main
30
30
31
31
import (
32
32
"archive/zip"
33
- "bytes"
34
33
"encoding/json"
35
34
"flag"
36
35
"fmt"
@@ -226,17 +225,16 @@ func runPublish(cmd *command, args []string) {
226
225
227
226
checkWD ()
228
227
229
- requireTools ("jq" , " npx" , "gh" , "git " )
228
+ requireTools ("npx" )
230
229
230
+ // npx vsce directly reads VSCE_PAT, so no parsing is needed.
231
+ // See https://github.com/microsoft/vscode-vsce/blob/ba6681809080ee8685fb86d4b4fca765f1d82708/src/main.ts#L186
231
232
requireEnv ("VSCE_PAT" )
232
- requireEnv ("GITHUB_TOKEN" )
233
233
tagName := requireEnv ("TAG_NAME" )
234
234
235
235
version , isPrerelease := releaseVersionInfo (tagName )
236
- checkPackageJSON (tagName , isPrerelease )
237
236
inDir := prepareInputDir (cmd .lookupFlag ("in" ).String ())
238
- vsix := filepath .Join (inDir , fmt .Sprintf ("go-%s.vsix" , version ))
239
- publish (tagName , vsix , isPrerelease )
237
+ publish (tagName , filepath .Join (inDir , fmt .Sprintf ("go-%s.vsix" , version )), isPrerelease )
240
238
}
241
239
242
240
func fatalf (format string , args ... any ) {
@@ -354,40 +352,6 @@ func parseVersionTagName(tagName string) (major, minor, patch int, label string)
354
352
return atoi ("Major" ), atoi ("Minor" ), atoi ("Patch" ), m [versionTagRE .SubexpIndex ("Label" )]
355
353
}
356
354
357
- // checkPackageJSON checks if package.json has the expected version value.
358
- // If prerelease, the major/minor version should match.
359
- // Otherwise, major/minor/patch version should match.
360
- func checkPackageJSON (tagName string , isPrerelease bool ) {
361
- if ! strings .HasPrefix (tagName , "v" ) {
362
- fatalf ("unexpected tagName in checkPackageJSON: %q" , tagName )
363
- }
364
-
365
- if flagN {
366
- tracef ("jq -r .version package.json" )
367
- return
368
- }
369
- cmd := exec .Command ("jq" , "-r" , ".version" , "package.json" )
370
- cmd .Stderr = os .Stderr
371
- var buf bytes.Buffer
372
- cmd .Stdout = & buf
373
- if err := commandRun (cmd ); err != nil {
374
- fatalf ("failed to read package.json version" )
375
- }
376
-
377
- versionInPackageJSON := string (bytes .TrimSpace (buf .Bytes ()))
378
- if ! isPrerelease {
379
- if got , want := versionInPackageJSON , tagName [1 :]; got != want {
380
- fatalf ("package.json version %q does not match wanted string %q" , got , want )
381
- }
382
- return
383
- }
384
- // Check only major.minor for prerelease.
385
- major , minor , _ , _ := parseVersionTagName (tagName )
386
- if want := fmt .Sprintf ("%d.%d." , major , minor ); ! strings .HasPrefix (versionInPackageJSON , want ) {
387
- fatalf ("package.json version %q does not match wanted string %q" , versionInPackageJSON , want )
388
- }
389
- }
390
-
391
355
func commandRun (cmd * exec.Cmd ) error {
392
356
if flagN {
393
357
if cmd .Dir != "" {
@@ -456,36 +420,21 @@ func buildPackage(version, tagName string, isPrerelease bool, output string) {
456
420
}
457
421
}
458
422
459
- // publish publishes the extension to the VS Code Marketplace and GitHub, using npx vsce and gh release create .
423
+ // publish publishes the extension to the VS Code Marketplace using npx vsce.
460
424
func publish (tagName , packageFile string , isPrerelease bool ) {
425
+ // Skip prerelease versions, as they are not published to the marketplace.
426
+ if strings .Contains (tagName , "-rc." ) {
427
+ return
428
+ }
429
+
461
430
// check if the package file exists.
462
431
if flagN {
463
432
tracef ("stat %s" , packageFile )
464
433
} else {
465
434
if _ , err := os .Stat (packageFile ); os .IsNotExist (err ) {
466
- fatalf ("package file %q does not exist. Did you run 'go run build /release.go package'?" , packageFile )
435
+ fatalf ("package file %q does not exist. Did you run 'go run tools/release /release.go package'?" , packageFile )
467
436
}
468
437
}
469
- isRC := strings .Contains (tagName , "-rc." )
470
-
471
- // publish release to GitHub. This will create a draft release - manually publish it after reviewing the draft.
472
- // TODO(hyangah): populate the changelog (the first section of CHANGELOG.md) and pass it using --notes-file instead of --generate-notes.
473
- ghArgs := []string {"release" , "create" , "--generate-notes" , "--target" , commitSHA (), "--title" , "Release " + tagName , "--draft" }
474
- fmt .Printf ("%s\n " , strings .Join (ghArgs , " " ))
475
- if isRC || isPrerelease {
476
- ghArgs = append (ghArgs , "--prerelease" )
477
- }
478
- ghArgs = append (ghArgs , "-R" , "github.com/golang/vscode-go" )
479
- ghArgs = append (ghArgs , tagName , packageFile )
480
- cmd := exec .Command ("gh" , ghArgs ... )
481
- cmd .Stderr = os .Stderr
482
- if err := commandRun (cmd ); err != nil {
483
- fatalf ("failed to publish release: %v" , err )
484
- }
485
-
486
- if isRC { // Do not publish RC versions to the marketplace.
487
- return
488
- }
489
438
490
439
npxVsceArgs := []string {"vsce" , "publish" , "-i" , packageFile }
491
440
if isPrerelease {
0 commit comments