Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,11 @@ cadence-releaser: $(BINS_DEPEND_ON)
$Q echo "compiling cadence-releaser with OS: $(GOOS), ARCH: $(GOARCH)"
$Q ./scripts/build-with-ldflags.sh -o $@ cmd/tools/releaser/releaser.go

BINS += cadence-releasetagger
cadence-releasetagger: $(BINS_DEPEND_ON)
$Q echo "compiling cadence-releasetagger with OS: $(GOOS), ARCH: $(GOARCH)"
$Q go build -o $@ cmd/tools/releasetagger/main.go
Comment on lines +541 to +544
Copy link
Member

@Groxx Groxx Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you do end up using x/mod/semver, this is likely better as

$(BIN)/releasetagger: internal/tools/go.mod $(wildcard internal/tools/releasetagger/*) | $(BIN)
	$(call go_build_tool,./releasetagger)

as that way it'll rebuild on go / mod changes.

as long as it's just stdlib it doesn't really matter what builds it though.


.PHONY: go-generate bins tools release clean

bins: $(BINS) ## Build all binaries, and any fast codegen needed (does not refresh wrappers or mocks)
Expand All @@ -556,6 +561,10 @@ release: ## Re-generate generated code and run tests
$(MAKE) --no-print-directory go-generate
$(MAKE) --no-print-directory test

tag-release: cadence-releasetagger ## Tag all submodules and print the push command
$(if $(VERSION),,$(error VERSION is not set))
$Q ./cadence-releasetagger $(VERSION)

build: ## `go build` all packages and tests (a quick compile check only, skips all other steps)
$Q echo 'Building all packages and submodules...'
$Q go build ./...
Expand Down
Binary file added cadence-releasetagger
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there's a way to tell git to ignore executable files by default

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops - deleted and added to gitigonore

Binary file not shown.
68 changes: 68 additions & 0 deletions cmd/tools/releasetagger/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package main

import (
"bytes"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
)

const mainModule = "github.com/uber/cadence"

func generateTags(version string, goListOutput string, root string) (string, error) {
tags := []string{version}

for _, line := range strings.Split(goListOutput, "\n") {
parts := strings.Split(line, "\t")
if len(parts) != 2 {
continue
}
modulePath, moduleDir := parts[0], parts[1]

if strings.HasPrefix(modulePath, mainModule+"/") {
relPath, err := filepath.Rel(root, moduleDir)
if err != nil {
return "", fmt.Errorf("error getting relative path for %s: %v", moduleDir, err)
}
tags = append(tags, fmt.Sprintf("%s/%s", relPath, version))
}
}
Comment on lines +17 to +31
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

frustratingly hard in bash, yea. tbh I think minor go scripts like this are reasonable, and they have the extreme benefit of being far more likely to be cross-platform by accident.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO anything that has branching, loops or string processing should not be written in bash - it becomes impossible to read so fast.


if len(tags) == 0 {
return "", nil
}
tagsStr := strings.Join(tags, " ")
return fmt.Sprintf("git tag %s\ngit push origin %s\n", tagsStr, tagsStr), nil
}

func main() {
if len(os.Args) < 2 {
fmt.Println("Usage: go run main.go <version>")
os.Exit(1)
}
version := os.Args[1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably worth doing a https://pkg.go.dev/golang.org/x/mod/semver#IsValid check to make sure it's a valid semver?


cmd := exec.Command("go", "list", "-m", "-f", "{{.Path}}\t{{.Dir}}", "all")
Copy link
Member

@Groxx Groxx Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is probably fine to use, but as an fyi: this can probably trigger downloads and be kinda slow. might want to limit it to like 1s and give up (and print stderr) if it takes too long.

(it does not appear to need the modules to be downloaded, but it could still trigger e.g. a go-toolchain download-and-install during which it'll just hang silently)

that said: I suppose this probably is the canonically correct way to get this info 🤔 tags need to be based on the relative path, not whatever the module names happen to be, so 👍 https://go.dev/doc/modules/managing-source#multiple-module-source

var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
fmt.Printf("Error running 'go list': %v\n", err)
os.Exit(1)
}

root, err := os.Getwd()
if err != nil {
fmt.Printf("Error getting current directory: %v\n", err)
os.Exit(1)
}

output, err := generateTags(version, out.String(), root)
if err != nil {
fmt.Printf("Error generating tags: %v\n", err)
os.Exit(1)
}
fmt.Print(output)
}
Loading