Download this file
| 1 | package testci |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "encoding/json" |
| 6 | "fmt" |
| 7 | "os/exec" |
| 8 | "path/filepath" |
| 9 | "testing" |
| 10 | ) |
| 11 | |
| 12 | // CopyReleaseCheck is the copy release gate (make copy-release-check) for |
| 13 | // the tree at candidate. copy-status.py verify is the one judge of reviewed |
| 14 | // copy: pending or required copy, under either marker spelling, or stale |
| 15 | // record-bound bookkeeping blocks a release. |
| 16 | func CopyReleaseCheck(t testing.TB, candidate string) error { |
| 17 | t.Helper() |
| 18 | root, err := moduleRoot() |
| 19 | if err != nil { |
| 20 | return err |
| 21 | } |
| 22 | scripts := filepath.Join(root, "scripts") |
| 23 | Files(t, filepath.Join(scripts, "copy-status.py"), filepath.Join(scripts, "copy-contract.py")) |
| 24 | Tools(t, "python3") |
| 25 | input, err := json.Marshal(map[string]string{"candidate": candidate}) |
| 26 | if err != nil { |
| 27 | return err |
| 28 | } |
| 29 | cmd := exec.Command("python3", filepath.Join(scripts, "copy-status.py"), "verify") |
| 30 | cmd.Stdin = bytes.NewReader(input) |
| 31 | out, err := cmd.Output() |
| 32 | if err != nil { |
| 33 | return fmt.Errorf("copy-status.py verify: %w %s", err, out) |
| 34 | } |
| 35 | var result struct { |
| 36 | Valid bool `json:"valid"` |
| 37 | } |
| 38 | if err := json.Unmarshal(out, &result); err != nil { |
| 39 | return fmt.Errorf("copy-status.py verify: %w %s", err, out) |
| 40 | } |
| 41 | if !result.Valid { |
| 42 | return fmt.Errorf("COPY REVIEW REQUIRED: copy-status.py verify found copy pending review or stale bookkeeping") |
| 43 | } |
| 44 | return nil |
| 45 | } |
| 46 | |