MCPcopy Create free account
hub / github.com/riverqueue/river / run

Function run

rivershared/cmd/update-mod-version/main.go:28–75  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26}
27
28func run() error {
29 // Allows secondary River repositories to make use of this command by
30 // specifying their own prefix.
31 packagePrefix := os.Getenv("PACKAGE_PREFIX")
32 if packagePrefix == "" {
33 return errors.New("expected to find PACKAGE_PREFIX in env")
34 }
35
36 version := os.Getenv("VERSION")
37 if version == "" {
38 return errors.New("expected to find VERSION in env")
39 }
40
41 if !semver.IsValid(version) {
42 return fmt.Errorf("invalid semver version: %s", version)
43 }
44
45 if len(os.Args) != 2 {
46 return errors.New("expected exactly one arg, which should be the path to a go.work file")
47 }
48
49 workFilename, err := localPath(".", os.Args[1])
50 if err != nil {
51 return err
52 }
53
54 workFileData, err := os.ReadFile(workFilename)
55 if err != nil {
56 return fmt.Errorf("error reading file %q: %w", workFilename, err)
57 }
58
59 workFile, err := modfile.ParseWork(workFilename, workFileData, nil)
60 if err != nil {
61 return fmt.Errorf("error parsing file %q: %w", workFilename, err)
62 }
63
64 workDir := filepath.Dir(workFilename)
65 for _, workUse := range workFile.Use {
66 filename, err := localPath(workDir, filepath.Join(workUse.Path, "go.mod"))
67 if err != nil {
68 return err
69 }
70 if _, err := parseAndUpdateGoModFile(filename, packagePrefix, version); err != nil {
71 return err
72 }
73 }
74 return nil
75}
76
77func localPath(baseDir, filename string) (string, error) {
78 absBaseDir, err := filepath.Abs(baseDir)

Callers 1

mainFunction · 0.70

Calls 3

localPathFunction · 0.70
parseAndUpdateGoModFileFunction · 0.70
ErrorfMethod · 0.65

Tested by

no test coverage detected