Atlas › Test

pseudo-version_on_default_branch_passes

Exact test identity: go.temporal.io/server/cmd/tools/check-dependencies/TestValidateMainBranch/pseudo-version_on_default_branch_passes

Package
go.temporal.io/server/cmd/tools/check-dependencies
Suite / test hierarchy
TestValidateMainBranch/pseudo-version_on_default_branch_passes
Test
pseudo-version_on_default_branch_passes
Introduced at
main.go ×1 Frontier kind: Joint frontier
Covered ranges
17
Covered lines
38
Covered files
1

Covered source

Expand a file to inspect source; the > gutter marks covered lines.

go.temporal.io/server/cmd/tools/check-dependencies/main.go 38 covered LOC · 17 ranges

Open complete file

114 ctx context.Context,
115 modFile *modfile.File,
116 > ) error { main.go
117 > var failures []string
118 > for _, mod := range knownModules {
119 > if err := validateMainModule(ctx, modFile, mod); err != nil {
120 failures = append(failures, err.Error())
121 }
122 }
123
124 > if len(failures) > 0 { main.go
125 return fmt.Errorf("main branch dependency validation failed:\n - %s", strings.Join(failures, "\n - "))
126 }
127
128 > fmt.Println("All required dependencies are valid for main branch") main.go
129 > return nil
130 }
131
134 modFile *modfile.File,
135 mod moduleSpec,
136 > ) error { main.go
137 > modVersion, ok := findRequiredModuleVersion(modFile, mod.modulePath)
138 > if !ok {
139 return fmt.Errorf("%s: dependency not found in go.mod", mod.modulePath)
140 }
141 > version := modVersion.Version main.go
142 >
143 > fmt.Printf("Found %s version: %s\n", mod.modulePath, version)
144 >
145 > if !module.IsPseudoVersion(version) {
146 if !semver.IsValid(version) {
147 return fmt.Errorf("%s@%s: not a valid semver tag", mod.modulePath, version)
151 }
152
153 > shortHash, err := module.PseudoVersionRev(version) main.go
154 > if err != nil {
155 return fmt.Errorf("%s@%s: failed to parse pseudo-version revision: %v", mod.modulePath, version, err)
156 }
157
158 > onDefault, err := resolveModuleOriginForSpec(ctx, mod, shortHash) main.go
159 > if err != nil {
160 return fmt.Errorf("%s@%s: failed to resolve module origin: %v", mod.modulePath, version, err)
161 }
162
163 > if !onDefault { main.go
164 return fmt.Errorf("%s@%s: commit %s is not on the default branch (%s) of %s",
165 mod.modulePath, version, shortHash, mod.defaultBranch, mod.repoURL)
166 }
167
168 > fmt.Printf(" - %s@%s is on %s (ok)\n", mod.modulePath, version, mod.defaultBranch) main.go
169 > return nil
170 }
171
172 > func findRequiredModuleVersion(modFile *modfile.File, modulePath string) (module.Version, bool) { main.go
173 > for _, req := range modFile.Require {
174 > if req.Mod.Path == modulePath { main.go
175 > return req.Mod, true main.go
176 > }
177 }
178 return module.Version{}, false
200 // refs/heads/<defaultBranch>: the branch tip to check ancestry against.
201 // Any other exit code indicates an error (e.g. the object does not exist).
202 > func resolveModuleOriginForSpec(ctx context.Context, mod moduleSpec, shortHash string) (bool, error) { main.go
203 > tmpRepo, err := os.MkdirTemp("", "check-dependencies-*")
204 > if err != nil {
205 return false, fmt.Errorf("failed to create temp repo dir: %w", err)
206 }
207 > defer func() { _ = os.RemoveAll(tmpRepo) }() main.go
208
209 > cmd := exec.CommandContext(ctx, "git", "clone", "--bare", "--filter=blob:none", "--single-branch", "--branch", mod.defaultBranch, mod.repoURL, tmpRepo) main.go
210 > out, err := cmd.CombinedOutput()
211 > if err != nil {
212 return false, fmt.Errorf("git clone failed: %w: %s", err, strings.TrimSpace(string(out)))
213 }
214
215 > out, err = exec.CommandContext(ctx, "git", "-C", tmpRepo, "merge-base", "--is-ancestor", shortHash, "refs/heads/"+mod.defaultBranch).CombinedOutput() main.go
216 > if err == nil {
217 > return true, nil main.go
218 > }
219 var exitErr *exec.ExitError
220 if errors.As(err, &exitErr) && exitErr.ExitCode() == 1 {