mirror of
https://github.com/alibaba/open-code-review.git
synced 2026-07-09 17:28:58 +00:00
build: Remove version from binary names and update related scripts
This commit is contained in:
parent
2ca532521b
commit
8ceceaf3e7
3 changed files with 179 additions and 8 deletions
4
Makefile
4
Makefile
|
|
@ -20,7 +20,7 @@ LD_FLAGS := -s -w \
|
|||
|
||||
define BUILD_PLATFORM
|
||||
GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 $(GO) build -ldflags "$(LD_FLAGS)" \
|
||||
-o $(DIST_DIR)/$(BINARY_NAME)-$(VERSION)-$(1)-$(2) \
|
||||
-o $(DIST_DIR)/$(BINARY_NAME)-$(1)-$(2) \
|
||||
./cmd/opencodereview
|
||||
endef
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ build-all: build-linux-amd64 build-linux-arm64 build-darwin-amd64 build-darwin-a
|
|||
|
||||
# Generate SHA256 checksums for all release binaries
|
||||
sha256sum: build-all
|
||||
cd $(DIST_DIR) && shasum -a 256 $(BINARY_NAME)-$(VERSION)-* | sort > sha256sum.txt
|
||||
cd $(DIST_DIR) && shasum -a 256 $(BINARY_NAME)-* | sort > sha256sum.txt
|
||||
|
||||
# Full release: clean → build all platforms → checksums
|
||||
dist: clean build-all sha256sum
|
||||
|
|
|
|||
171
internal/release/asset_naming_test.go
Normal file
171
internal/release/asset_naming_test.go
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
package release
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type ocrConfig struct {
|
||||
URLPattern string `json:"urlPattern"`
|
||||
ChecksumPattern string `json:"checksumPattern"`
|
||||
}
|
||||
|
||||
type packageJSON struct {
|
||||
OcrConfig ocrConfig `json:"ocrConfig"`
|
||||
}
|
||||
|
||||
func projectRoot(t *testing.T) string {
|
||||
t.Helper()
|
||||
_, file, _, ok := runtime.Caller(0)
|
||||
if !ok {
|
||||
t.Fatal("cannot determine project root")
|
||||
}
|
||||
return filepath.Join(filepath.Dir(file), "../..")
|
||||
}
|
||||
|
||||
func loadPackageJSON(t *testing.T) packageJSON {
|
||||
t.Helper()
|
||||
data, err := os.ReadFile(filepath.Join(projectRoot(t), "package.json"))
|
||||
if err != nil {
|
||||
t.Fatalf("read package.json: %v", err)
|
||||
}
|
||||
var pkg packageJSON
|
||||
if err := json.Unmarshal(data, &pkg); err != nil {
|
||||
t.Fatalf("parse package.json: %v", err)
|
||||
}
|
||||
return pkg
|
||||
}
|
||||
|
||||
func loadFile(t *testing.T, relPath string) string {
|
||||
t.Helper()
|
||||
data, err := os.ReadFile(filepath.Join(projectRoot(t), relPath))
|
||||
if err != nil {
|
||||
t.Fatalf("read %s: %v", relPath, err)
|
||||
}
|
||||
return string(data)
|
||||
}
|
||||
|
||||
// extractFilenameFromURL returns the filename part (last path segment) of a URL pattern.
|
||||
func extractFilenameFromURL(pattern string) string {
|
||||
parts := strings.Split(pattern, "/")
|
||||
return parts[len(parts)-1]
|
||||
}
|
||||
|
||||
func TestURLPatternNoVersionInFilename(t *testing.T) {
|
||||
pkg := loadPackageJSON(t)
|
||||
filename := extractFilenameFromURL(pkg.OcrConfig.URLPattern)
|
||||
if strings.Contains(filename, "{version}") {
|
||||
t.Errorf("binary filename %q should not contain {version}", filename)
|
||||
}
|
||||
}
|
||||
|
||||
func TestURLPatternFormat(t *testing.T) {
|
||||
pkg := loadPackageJSON(t)
|
||||
platforms := []struct{ os, arch string }{
|
||||
{"linux", "amd64"},
|
||||
{"linux", "arm64"},
|
||||
{"darwin", "amd64"},
|
||||
{"darwin", "arm64"},
|
||||
}
|
||||
for _, p := range platforms {
|
||||
url := pkg.OcrConfig.URLPattern
|
||||
url = strings.ReplaceAll(url, "{version}", "1.0.7")
|
||||
url = strings.ReplaceAll(url, "{os}", p.os)
|
||||
url = strings.ReplaceAll(url, "{arch}", p.arch)
|
||||
filename := extractFilenameFromURL(url)
|
||||
expected := "opencodereview-" + p.os + "-" + p.arch
|
||||
if filename != expected {
|
||||
t.Errorf("urlPattern produces %q, want %q", filename, expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestReleaseYmlMatchesURLPattern(t *testing.T) {
|
||||
pkg := loadPackageJSON(t)
|
||||
yml := loadFile(t, ".github/workflows/release.yml")
|
||||
|
||||
// Match: -o opencodereview-${{ matrix.goos }}-${{ matrix.goarch }}
|
||||
re := regexp.MustCompile(`go build[^\n]*-o\s+(opencodereview[^\n]*\}\})`)
|
||||
m := re.FindStringSubmatch(yml)
|
||||
if m == nil {
|
||||
t.Fatal("cannot find 'go build -o' output pattern in release.yml")
|
||||
}
|
||||
outputTemplate := strings.TrimSpace(strings.Split(m[1], " ./")[0])
|
||||
|
||||
platforms := []struct{ os, arch string }{
|
||||
{"linux", "amd64"},
|
||||
{"linux", "arm64"},
|
||||
{"darwin", "amd64"},
|
||||
{"darwin", "arm64"},
|
||||
}
|
||||
for _, p := range platforms {
|
||||
rendered := outputTemplate
|
||||
rendered = strings.ReplaceAll(rendered, "${{ matrix.goos }}", p.os)
|
||||
rendered = strings.ReplaceAll(rendered, "${{ matrix.goarch }}", p.arch)
|
||||
|
||||
url := pkg.OcrConfig.URLPattern
|
||||
url = strings.ReplaceAll(url, "{version}", "1.0.7")
|
||||
url = strings.ReplaceAll(url, "{os}", p.os)
|
||||
url = strings.ReplaceAll(url, "{arch}", p.arch)
|
||||
expected := extractFilenameFromURL(url)
|
||||
|
||||
if rendered != expected {
|
||||
t.Errorf("release.yml produces %q, urlPattern expects %q", rendered, expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMakefileBuildMatchesURLPattern(t *testing.T) {
|
||||
pkg := loadPackageJSON(t)
|
||||
makefile := loadFile(t, "Makefile")
|
||||
|
||||
re := regexp.MustCompile(`-o\s+\$\(DIST_DIR\)/([^\s\\]+)`)
|
||||
m := re.FindStringSubmatch(makefile)
|
||||
if m == nil {
|
||||
t.Fatal("cannot find BUILD_PLATFORM -o pattern in Makefile")
|
||||
}
|
||||
outputTemplate := m[1]
|
||||
|
||||
platforms := []struct{ os, arch string }{
|
||||
{"linux", "amd64"},
|
||||
{"linux", "arm64"},
|
||||
{"darwin", "amd64"},
|
||||
{"darwin", "arm64"},
|
||||
}
|
||||
for _, p := range platforms {
|
||||
rendered := outputTemplate
|
||||
rendered = strings.ReplaceAll(rendered, "$(BINARY_NAME)", "opencodereview")
|
||||
rendered = strings.ReplaceAll(rendered, "$(1)", p.os)
|
||||
rendered = strings.ReplaceAll(rendered, "$(2)", p.arch)
|
||||
|
||||
url := pkg.OcrConfig.URLPattern
|
||||
url = strings.ReplaceAll(url, "{version}", "1.0.7")
|
||||
url = strings.ReplaceAll(url, "{os}", p.os)
|
||||
url = strings.ReplaceAll(url, "{arch}", p.arch)
|
||||
expected := extractFilenameFromURL(url)
|
||||
|
||||
if rendered != expected {
|
||||
t.Errorf("Makefile produces %q, urlPattern expects %q", rendered, expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestChecksumFilenameNoVersion(t *testing.T) {
|
||||
pkg := loadPackageJSON(t)
|
||||
filename := extractFilenameFromURL(pkg.OcrConfig.ChecksumPattern)
|
||||
if filename != "sha256sum.txt" {
|
||||
t.Errorf("checksumPattern filename = %q, want %q", filename, "sha256sum.txt")
|
||||
}
|
||||
}
|
||||
|
||||
func TestURLPatternHTTPS(t *testing.T) {
|
||||
pkg := loadPackageJSON(t)
|
||||
if !strings.HasPrefix(pkg.OcrConfig.URLPattern, "https://github.com/alibaba/open-code-review/releases/download/") {
|
||||
t.Errorf("urlPattern should point to GitHub releases via HTTPS, got %q", pkg.OcrConfig.URLPattern)
|
||||
}
|
||||
}
|
||||
|
|
@ -118,18 +118,18 @@ upload_to_git_repo() {
|
|||
mkdir -p "$bin_dir"
|
||||
|
||||
local count=0
|
||||
for f in "$dist_dir"/opencodereview-${VERSION_TAG}-*; do
|
||||
for f in "$dist_dir"/opencodereview-*; do
|
||||
[ -f "$f" ] || continue
|
||||
local base target
|
||||
[[ "$(basename "$f")" == *.txt ]] && continue
|
||||
local base
|
||||
base=$(basename "$f")
|
||||
target="${base/opencodereview-${VERSION_TAG}-/opencodereview-}"
|
||||
info " Copying ${target}"
|
||||
cp "$f" "$bin_dir/${target}"
|
||||
info " Copying ${base}"
|
||||
cp "$f" "$bin_dir/${base}"
|
||||
count=$((count + 1))
|
||||
done
|
||||
if [ "$count" -eq 0 ]; then
|
||||
rm -rf "$tmp_repo"
|
||||
die "No binaries found matching opencodereview-${VERSION_TAG}-*"
|
||||
die "No binaries found matching opencodereview-*"
|
||||
fi
|
||||
success "Copied ${count} binaries"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue