blob: 0ba436d11960900e90ad60c1c72a334c82e28cb2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
package deployment
import (
"os/exec"
"github.com/thepeterstone/claudomator/internal/task"
"github.com/thepeterstone/claudomator/internal/version"
)
// Status describes whether the currently-deployed server includes a set of fix commits.
type Status struct {
DeployedCommit string `json:"deployed_commit"`
FixCommits []task.GitCommit `json:"fix_commits"`
IncludesFix bool `json:"includes_fix"`
}
// Check returns the deployment status for a set of fix commits given the project directory.
// It uses `git merge-base --is-ancestor` to check whether each fix commit is an ancestor
// of the deployed server's commit. Returns a non-nil Status in all cases; IncludesFix is
// false when the check cannot be performed (missing git, "dev" version, no commits, etc.).
func Check(fixCommits []task.GitCommit, projectDir string) *Status {
deployedCommit := version.Version()
status := &Status{
DeployedCommit: deployedCommit,
FixCommits: fixCommits,
}
if deployedCommit == "dev" || projectDir == "" || len(fixCommits) == 0 {
return status
}
// All fix commits must be ancestors of (or equal to) the deployed commit.
for _, commit := range fixCommits {
if commit.Hash == "" {
continue
}
cmd := exec.Command("git", "-C", projectDir, "merge-base", "--is-ancestor", commit.Hash, deployedCommit)
if err := cmd.Run(); err != nil {
return status
}
}
status.IncludesFix = true
return status
}
|