Skip to content

Commit 96f0c5b

Browse files
committed
extension/tools/release: clean up temporarily created README.md
When building vsix, we want to embed the README.md file located in the project root directory. However, vsce package is strict about files that can be included into the vsix and does not pack files outside the node.js module root. To work around, package command copies the README.md file to extension/ before running vsce. This left-over README.md file is annoying and complicates the release process. Let's do clean up. For #3500 Change-Id: I4b817609f0bb0e6234c732909a044e69d23e0dfe Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/613079 kokoro-CI: kokoro <[email protected]> Commit-Queue: Hyang-Ah Hana Kim <[email protected]> Reviewed-by: Hongxiang Jiang <[email protected]>
1 parent be7de09 commit 96f0c5b

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

extension/tools/release/release.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,11 @@ func runPublish(cmd *command, args []string) {
240240
}
241241

242242
func fatalf(format string, args ...any) {
243-
fmt.Fprintf(os.Stderr, format, args...)
243+
if len(args) == 0 {
244+
fmt.Fprint(os.Stderr, format)
245+
} else {
246+
fmt.Fprintf(os.Stderr, format, args...)
247+
}
244248
fmt.Fprintf(os.Stderr, "\n")
245249
os.Exit(1)
246250
}
@@ -407,18 +411,37 @@ func copy(dst, src string) error {
407411
return os.WriteFile(dst, data, 0644)
408412
}
409413

414+
func rm(file string) error {
415+
if flagN {
416+
tracef("rm %s", file)
417+
return nil
418+
}
419+
return os.Remove(file)
420+
}
421+
410422
// buildPackage builds the extension of the given version, using npx vsce package.
411423
func buildPackage(version, tagName string, isPrerelease bool, output string) {
424+
// We want to embed the README.md file of the repo root to the extension,
425+
// but vsce does not allow to include a file outside the node.js module directory.
426+
// So, let's copy the file temporarily.
412427
if err := copy("README.md", filepath.Join("..", "README.md")); err != nil {
413428
fatalf("failed to copy README.md: %v", err)
414429
}
430+
defer func() {
431+
if err := rm("README.md"); err != nil {
432+
fatalf("failed to delete the temporarily created README.md file: %v", err)
433+
}
434+
}()
415435
// build the package.
416436
args := []string{"vsce", "package",
417437
"-o", output,
418438
"--baseContentUrl", "https://github.com/golang/vscode-go/raw/" + tagName,
419439
"--baseImagesUrl", "https://github.com/golang/vscode-go/raw/" + tagName,
420-
"--no-update-package-json",
421-
"--no-git-tag-version",
440+
}
441+
if isPrerelease || strings.Contains(tagName, "-rc.") {
442+
// Do not update of the version field in packages.json for prerelease or rc.
443+
// relui will create a cl to update package.json during stable release only.
444+
args = append(args, "--no-update-package-json", "--no-git-tag-version")
422445
}
423446
if isPrerelease {
424447
args = append(args, "--pre-release")
@@ -681,7 +704,10 @@ var tempDirs []replaceRule
681704
type replaceRule struct{ from, to string }
682705

683706
func tracef(format string, args ...any) {
684-
str := fmt.Sprintf(format, args...)
707+
str := format
708+
if len(args) > 0 {
709+
str = fmt.Sprintf(format, args...)
710+
}
685711
for _, tmpdir := range tempDirs {
686712
str = strings.ReplaceAll(str, tmpdir.from, tmpdir.to)
687713
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
cp ../README.md README.md
22
npx vsce package -o /tmp/artifacts/go-0.43.0.vsix --baseContentUrl https://github.com/golang/vscode-go/raw/v0.43.0 --baseImagesUrl https://github.com/golang/vscode-go/raw/v0.43.0 --no-update-package-json --no-git-tag-version --pre-release 0.43.0
3+
rm README.md
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
cp ../README.md README.md
22
npx vsce package -o /tmp/artifacts/go-0.44.0-rc.1.vsix --baseContentUrl https://github.com/golang/vscode-go/raw/v0.44.0-rc.1 --baseImagesUrl https://github.com/golang/vscode-go/raw/v0.44.0-rc.1 --no-update-package-json --no-git-tag-version --pre-release 0.44.0-rc.1
3+
rm README.md
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
cp ../README.md README.md
2-
npx vsce package -o /tmp/artifacts/go-0.44.0.vsix --baseContentUrl https://github.com/golang/vscode-go/raw/v0.44.0 --baseImagesUrl https://github.com/golang/vscode-go/raw/v0.44.0 --no-update-package-json --no-git-tag-version 0.44.0
2+
npx vsce package -o /tmp/artifacts/go-0.44.0.vsix --baseContentUrl https://github.com/golang/vscode-go/raw/v0.44.0 --baseImagesUrl https://github.com/golang/vscode-go/raw/v0.44.0 0.44.0
3+
rm README.md

0 commit comments

Comments
 (0)