Skip to content

Commit 7ce274e

Browse files
h9jianggopherbot
authored andcommitted
extension/tools/release: remove tool requirement of jq, git, gh
Remove jq as the version check is now skipped. Remove gh as the github release and asset upload is now handled using relui's client library. Remove git as it's never being used. Local test log: $ TAG_NAME=v0.43.3 VSCE_PAT=fake go run -C extension tools/release/release.go publish ERROR TF400813: The user 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' is not authorized to access this resource. failed to publish release exit status 1 For #3500 Change-Id: I121db842f74079310c2599c7e09081dd73863cff Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/614335 Auto-Submit: Hongxiang Jiang <[email protected]> kokoro-CI: kokoro <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]> Commit-Queue: Hongxiang Jiang <[email protected]>
1 parent c233889 commit 7ce274e

File tree

4 files changed

+11
-72
lines changed

4 files changed

+11
-72
lines changed

extension/tools/release/release.go

Lines changed: 11 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ package main
3030

3131
import (
3232
"archive/zip"
33-
"bytes"
3433
"encoding/json"
3534
"flag"
3635
"fmt"
@@ -226,17 +225,16 @@ func runPublish(cmd *command, args []string) {
226225

227226
checkWD()
228227

229-
requireTools("jq", "npx", "gh", "git")
228+
requireTools("npx")
230229

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
231232
requireEnv("VSCE_PAT")
232-
requireEnv("GITHUB_TOKEN")
233233
tagName := requireEnv("TAG_NAME")
234234

235235
version, isPrerelease := releaseVersionInfo(tagName)
236-
checkPackageJSON(tagName, isPrerelease)
237236
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)
240238
}
241239

242240
func fatalf(format string, args ...any) {
@@ -354,40 +352,6 @@ func parseVersionTagName(tagName string) (major, minor, patch int, label string)
354352
return atoi("Major"), atoi("Minor"), atoi("Patch"), m[versionTagRE.SubexpIndex("Label")]
355353
}
356354

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-
391355
func commandRun(cmd *exec.Cmd) error {
392356
if flagN {
393357
if cmd.Dir != "" {
@@ -456,36 +420,21 @@ func buildPackage(version, tagName string, isPrerelease bool, output string) {
456420
}
457421
}
458422

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.
460424
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+
461430
// check if the package file exists.
462431
if flagN {
463432
tracef("stat %s", packageFile)
464433
} else {
465434
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)
467436
}
468437
}
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-
}
489438

490439
npxVsceArgs := []string{"vsce", "publish", "-i", packageFile}
491440
if isPrerelease {
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
jq -r .version package.json
21
stat /tmp/artifacts/go-0.43.0.vsix
3-
release create --generate-notes --target 4893cd984d190bdf2cd65e11c425b42819ae6f57 --title Release v0.43.0 --draft
4-
gh release create --generate-notes --target 4893cd984d190bdf2cd65e11c425b42819ae6f57 --title Release v0.43.0 --draft --prerelease -R github.com/golang/vscode-go v0.43.0 /tmp/artifacts/go-0.43.0.vsix
52
npx vsce publish -i /tmp/artifacts/go-0.43.0.vsix --pre-release
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
jq -r .version package.json
2-
stat /tmp/artifacts/go-0.44.0-rc.1.vsix
3-
release create --generate-notes --target 4893cd984d190bdf2cd65e11c425b42819ae6f57 --title Release v0.44.0-rc.1 --draft
4-
gh release create --generate-notes --target 4893cd984d190bdf2cd65e11c425b42819ae6f57 --title Release v0.44.0-rc.1 --draft --prerelease -R github.com/golang/vscode-go v0.44.0-rc.1 /tmp/artifacts/go-0.44.0-rc.1.vsix
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
jq -r .version package.json
21
stat /tmp/artifacts/go-0.44.0.vsix
3-
release create --generate-notes --target 4893cd984d190bdf2cd65e11c425b42819ae6f57 --title Release v0.44.0 --draft
4-
gh release create --generate-notes --target 4893cd984d190bdf2cd65e11c425b42819ae6f57 --title Release v0.44.0 --draft -R github.com/golang/vscode-go v0.44.0 /tmp/artifacts/go-0.44.0.vsix
52
npx vsce publish -i /tmp/artifacts/go-0.44.0.vsix

0 commit comments

Comments
 (0)