Skip to content

Commit

Permalink
extension/tools/release: clean up temporarily created README.md
Browse files Browse the repository at this point in the history
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 <noreply+kokoro@google.com>
Commit-Queue: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Hongxiang Jiang <hxjiang@golang.org>
  • Loading branch information
hyangah committed Sep 16, 2024
1 parent be7de09 commit 96f0c5b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
34 changes: 30 additions & 4 deletions extension/tools/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,11 @@ func runPublish(cmd *command, args []string) {
}

func fatalf(format string, args ...any) {
fmt.Fprintf(os.Stderr, format, args...)
if len(args) == 0 {
fmt.Fprint(os.Stderr, format)
} else {
fmt.Fprintf(os.Stderr, format, args...)
}
fmt.Fprintf(os.Stderr, "\n")
os.Exit(1)
}
Expand Down Expand Up @@ -407,18 +411,37 @@ func copy(dst, src string) error {
return os.WriteFile(dst, data, 0644)
}

func rm(file string) error {
if flagN {
tracef("rm %s", file)
return nil
}
return os.Remove(file)
}

// buildPackage builds the extension of the given version, using npx vsce package.
func buildPackage(version, tagName string, isPrerelease bool, output string) {
// We want to embed the README.md file of the repo root to the extension,
// but vsce does not allow to include a file outside the node.js module directory.
// So, let's copy the file temporarily.
if err := copy("README.md", filepath.Join("..", "README.md")); err != nil {
fatalf("failed to copy README.md: %v", err)
}
defer func() {
if err := rm("README.md"); err != nil {
fatalf("failed to delete the temporarily created README.md file: %v", err)
}
}()
// build the package.
args := []string{"vsce", "package",
"-o", output,
"--baseContentUrl", "https://github.com/golang/vscode-go/raw/" + tagName,
"--baseImagesUrl", "https://github.com/golang/vscode-go/raw/" + tagName,
"--no-update-package-json",
"--no-git-tag-version",
}
if isPrerelease || strings.Contains(tagName, "-rc.") {
// Do not update of the version field in packages.json for prerelease or rc.
// relui will create a cl to update package.json during stable release only.
args = append(args, "--no-update-package-json", "--no-git-tag-version")
}
if isPrerelease {
args = append(args, "--pre-release")
Expand Down Expand Up @@ -681,7 +704,10 @@ var tempDirs []replaceRule
type replaceRule struct{ from, to string }

func tracef(format string, args ...any) {
str := fmt.Sprintf(format, args...)
str := format
if len(args) > 0 {
str = fmt.Sprintf(format, args...)
}
for _, tmpdir := range tempDirs {
str = strings.ReplaceAll(str, tmpdir.from, tmpdir.to)
}
Expand Down
1 change: 1 addition & 0 deletions extension/tools/release/testdata/package-v0.43.0.golden
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
cp ../README.md README.md
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
rm README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
cp ../README.md README.md
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
rm README.md
3 changes: 2 additions & 1 deletion extension/tools/release/testdata/package-v0.44.0.golden
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
cp ../README.md README.md
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
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
rm README.md

0 comments on commit 96f0c5b

Please sign in to comment.