Skip to content

Commit

Permalink
StageCommit returns a build
Browse files Browse the repository at this point in the history
  • Loading branch information
MDrakos committed Jul 29, 2024
1 parent dd0c713 commit d8be069
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 45 deletions.
36 changes: 15 additions & 21 deletions internal/runbits/runtime/requirements/requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
"github.com/ActiveState/cli/internal/primer"
"github.com/ActiveState/cli/internal/prompt"
"github.com/ActiveState/cli/internal/rtutils/ptr"
"github.com/ActiveState/cli/internal/runbits/buildscript"
buildscript_runbit "github.com/ActiveState/cli/internal/runbits/buildscript"
"github.com/ActiveState/cli/internal/runbits/cves"
"github.com/ActiveState/cli/internal/runbits/dependencies"
"github.com/ActiveState/cli/internal/runbits/rationalize"
"github.com/ActiveState/cli/internal/runbits/runtime"
runtime_runbit "github.com/ActiveState/cli/internal/runbits/runtime"
"github.com/ActiveState/cli/internal/runbits/runtime/trigger"
"github.com/ActiveState/cli/pkg/buildplan"
"github.com/ActiveState/cli/pkg/buildscript"
Expand Down Expand Up @@ -214,10 +214,14 @@ func (r *RequirementOperation) ExecuteRequirementOperation(ts *time.Time, requir
Script: script,
}

commitID, err := bp.StageCommit(params)
// Solve runtime
solveSpinner := output.StartSpinner(r.Output, locale.T("progress_solve_preruntime"), constants.TerminalAnimationInterval)
commit, err := bp.StageCommit(params)
if err != nil {
solveSpinner.Stop(locale.T("progress_fail"))
return locale.WrapError(err, "err_package_save_and_build", "Error occurred while trying to create a commit")
}
solveSpinner.Stop(locale.T("progress_success"))

pg.Stop(locale.T("progress_success"))
pg = nil
Expand All @@ -233,32 +237,22 @@ func (r *RequirementOperation) ExecuteRequirementOperation(ts *time.Time, requir
trig = trigger.TriggerPackage
}

// Solve runtime
solveSpinner := output.StartSpinner(r.Output, locale.T("progress_solve_preruntime"), constants.TerminalAnimationInterval)
bpm := bpModel.NewBuildPlannerModel(r.Auth)
rtCommit, err := bpm.FetchCommit(commitID, r.Project.Owner(), r.Project.Name(), nil)
if err != nil {
solveSpinner.Stop(locale.T("progress_fail"))
return errs.Wrap(err, "Failed to fetch build result")
}
solveSpinner.Stop(locale.T("progress_success"))

var oldBuildPlan *buildplan.BuildPlan
if rtCommit.ParentID != "" {
if commit.ParentID != "" {
bpm := bpModel.NewBuildPlannerModel(r.Auth)
commit, err := bpm.FetchCommit(rtCommit.ParentID, r.Project.Owner(), r.Project.Name(), nil)
oldCommit, err := bpm.FetchCommit(commit.ParentID, r.Project.Owner(), r.Project.Name(), nil)
if err != nil {
return errs.Wrap(err, "Failed to fetch build result")
}
oldBuildPlan = commit.BuildPlan()
oldBuildPlan = oldCommit.BuildPlan()
}

r.Output.Notice("") // blank line
dependencies.OutputChangeSummary(r.Output, rtCommit.BuildPlan(), oldBuildPlan)
dependencies.OutputChangeSummary(r.Output, commit.BuildPlan(), oldBuildPlan)

// Report CVEs
names := requirementNames(requirements...)
if err := cves.NewCveReport(r.prime).Report(rtCommit.BuildPlan(), oldBuildPlan, names...); err != nil {
if err := cves.NewCveReport(r.prime).Report(commit.BuildPlan(), oldBuildPlan, names...); err != nil {
return errs.Wrap(err, "Could not report CVEs")
}

Expand All @@ -268,21 +262,21 @@ func (r *RequirementOperation) ExecuteRequirementOperation(ts *time.Time, requir

// refresh or install runtime
_, err = runtime_runbit.Update(r.prime, trig,
runtime_runbit.WithCommit(rtCommit),
runtime_runbit.WithCommit(commit),
runtime_runbit.WithoutBuildscriptValidation(),
)
if err != nil {
if !IsBuildError(err) {
// If the error is not a build error we want to retain the changes
if err2 := r.updateCommitID(commitID); err2 != nil {
if err2 := r.updateCommitID(commit.CommitID); err2 != nil {
return errs.Pack(err, locale.WrapError(err2, "err_package_update_commit_id"))
}
}
return errs.Wrap(err, "Failed to refresh runtime")
}
}

if err := r.updateCommitID(commitID); err != nil {
if err := r.updateCommitID(commit.CommitID); err != nil {
return locale.WrapError(err, "err_package_update_commit_id")
}

Expand Down
14 changes: 7 additions & 7 deletions internal/runners/commit/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/ActiveState/cli/internal/locale"
"github.com/ActiveState/cli/internal/output"
"github.com/ActiveState/cli/internal/primer"
"github.com/ActiveState/cli/internal/runbits/buildscript"
buildscript_runbit "github.com/ActiveState/cli/internal/runbits/buildscript"
"github.com/ActiveState/cli/internal/runbits/cves"
"github.com/ActiveState/cli/internal/runbits/dependencies"
"github.com/ActiveState/cli/internal/runbits/rationalize"
Expand Down Expand Up @@ -106,7 +106,7 @@ func (c *Commit) Run() (rerr error) {
}
}()

stagedCommitID, err := bp.StageCommit(buildplanner.StageCommitParams{
stagedCommit, err := bp.StageCommit(buildplanner.StageCommitParams{
Owner: proj.Owner(),
Project: proj.Name(),
ParentCommit: localCommitID.String(),
Expand All @@ -117,12 +117,12 @@ func (c *Commit) Run() (rerr error) {
}

// Update local commit ID
if err := localcommit.Set(proj.Dir(), stagedCommitID.String()); err != nil {
if err := localcommit.Set(proj.Dir(), stagedCommit.CommitID.String()); err != nil {
return errs.Wrap(err, "Could not set local commit ID")
}

// Update our local build expression to match the committed one. This allows our API a way to ensure forward compatibility.
newScript, err := bp.GetBuildScript(stagedCommitID.String())
newScript, err := bp.GetBuildScript(stagedCommit.CommitID.String())
if err != nil {
return errs.Wrap(err, "Unable to get the remote build script")
}
Expand All @@ -141,7 +141,7 @@ func (c *Commit) Run() (rerr error) {
}()

// Solve runtime
rtCommit, err := bp.FetchCommit(stagedCommitID, proj.Owner(), proj.Name(), nil)
rtCommit, err := bp.FetchCommit(stagedCommit.CommitID, proj.Owner(), proj.Name(), nil)
if err != nil {
return errs.Wrap(err, "Could not fetch staged commit")
}
Expand All @@ -167,7 +167,7 @@ func (c *Commit) Run() (rerr error) {
out.Print(output.Prepare(
locale.Tl(
"commit_success",
"", stagedCommitID.String(), proj.NamespaceString(),
"", stagedCommit.CommitID.String(), proj.NamespaceString(),
),
&struct {
Namespace string `json:"namespace"`
Expand All @@ -176,7 +176,7 @@ func (c *Commit) Run() (rerr error) {
}{
proj.NamespaceString(),
proj.Dir(),
stagedCommitID.String(),
stagedCommit.CommitID.String(),
},
))

Expand Down
10 changes: 5 additions & 5 deletions internal/runners/packages/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/ActiveState/cli/internal/runbits/dependencies"
"github.com/ActiveState/cli/internal/runbits/org"
"github.com/ActiveState/cli/internal/runbits/rationalize"
"github.com/ActiveState/cli/internal/runbits/runtime"
runtime_runbit "github.com/ActiveState/cli/internal/runbits/runtime"
"github.com/ActiveState/cli/internal/runbits/runtime/trigger"
"github.com/ActiveState/cli/pkg/buildscript"
"github.com/ActiveState/cli/pkg/localcommit"
Expand Down Expand Up @@ -126,7 +126,7 @@ func (i *Import) Run(params *ImportRunParams) (rerr error) {
}

msg := locale.T("commit_reqstext_message")
stagedCommitId, err := bp.StageCommit(buildplanner.StageCommitParams{
stagedCommit, err := bp.StageCommit(buildplanner.StageCommitParams{
Owner: proj.Owner(),
Project: proj.Name(),
ParentCommit: localCommitId.String(),
Expand All @@ -140,12 +140,12 @@ func (i *Import) Run(params *ImportRunParams) (rerr error) {
pg.Stop(locale.T("progress_success"))
pg = nil

if err := localcommit.Set(proj.Dir(), stagedCommitId.String()); err != nil {
if err := localcommit.Set(proj.Dir(), stagedCommit.CommitID.String()); err != nil {
return locale.WrapError(err, "err_package_update_commit_id")
}

// Solve the runtime.
rtCommit, err := bp.FetchCommit(stagedCommitId, proj.Owner(), proj.Name(), nil)
rtCommit, err := bp.FetchCommit(stagedCommit.CommitID, proj.Owner(), proj.Name(), nil)
if err != nil {
return errs.Wrap(err, "Failed to fetch build result for staged commit")
}
Expand All @@ -164,7 +164,7 @@ func (i *Import) Run(params *ImportRunParams) (rerr error) {
return errs.Wrap(err, "Could not report CVEs")
}

_, err = runtime_runbit.Update(i.prime, trigger.TriggerImport, runtime_runbit.WithCommitID(stagedCommitId))
_, err = runtime_runbit.Update(i.prime, trigger.TriggerImport, runtime_runbit.WithCommitID(stagedCommit.CommitID))
if err != nil {
return errs.Wrap(err, "Runtime update failed")
}
Expand Down
6 changes: 3 additions & 3 deletions internal/runners/revert/revert.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/ActiveState/cli/internal/prompt"
"github.com/ActiveState/cli/internal/runbits/commit"
"github.com/ActiveState/cli/internal/runbits/rationalize"
"github.com/ActiveState/cli/internal/runbits/runtime"
runtime_runbit "github.com/ActiveState/cli/internal/runbits/runtime"
"github.com/ActiveState/cli/internal/runbits/runtime/trigger"
"github.com/ActiveState/cli/pkg/localcommit"
gqlmodel "github.com/ActiveState/cli/pkg/platform/api/graphql/model"
Expand Down Expand Up @@ -208,10 +208,10 @@ func (r *Revert) revertToCommit(params revertParams, bp *buildplanner.BuildPlann
Script: bs,
}

newCommitID, err := bp.StageCommit(stageCommitParams)
newCommit, err := bp.StageCommit(stageCommitParams)
if err != nil {
return "", errs.Wrap(err, "Could not stage commit")
}

return newCommitID, nil
return newCommit.CommitID, nil
}
164 changes: 163 additions & 1 deletion pkg/platform/api/buildplanner/request/stagecommit.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,168 @@ mutation ($organization: String!, $project: String!, $parentCommit: ID!, $descri
__typename
expr
commitId
build {
__typename
... on BuildCompleted {
buildLogIds {
... on AltBuildId {
id
}
}
}
... on BuildStarted {
buildLogIds {
... on AltBuildId {
id
}
}
}
... on Build {
status
terminals {
tag
nodeIds
}
sources: nodes {
... on Source {
nodeId
ingredientID
ingredientVersionID
revision
name
namespace
version
licenses
}
}
steps: steps {
... on Step {
stepId
inputs {
tag
nodeIds
}
outputs
}
}
artifacts: nodes {
... on ArtifactSucceeded {
__typename
nodeId
displayName
mimeType
generatedBy
runtimeDependencies
status
logURL
url
checksum
}
... on ArtifactUnbuilt {
__typename
nodeId
displayName
mimeType
generatedBy
runtimeDependencies
status
}
... on ArtifactStarted {
__typename
nodeId
displayName
mimeType
generatedBy
runtimeDependencies
status
}
... on ArtifactTransientlyFailed {
__typename
nodeId
displayName
mimeType
generatedBy
runtimeDependencies
status
logURL
errors
attempts
nextAttemptAt
}
... on ArtifactPermanentlyFailed {
__typename
nodeId
displayName
mimeType
generatedBy
runtimeDependencies
status
logURL
errors
}
... on ArtifactFailed {
__typename
nodeId
displayName
mimeType
generatedBy
runtimeDependencies
status
logURL
errors
}
}
resolvedRequirements {
requirement {
name
namespace
version_requirements: versionRequirements {
comparator
version
}
}
resolvedSource
}
}
... on Error {
message
}
... on PlanningError {
message
subErrors {
__typename
... on GenericSolveError {
path
message
isTransient
validationErrors {
error
jsonPath
}
}
... on RemediableSolveError {
path
message
isTransient
errorType
validationErrors {
error
jsonPath
}
suggestedRemediations {
remediationType
command
parameters
}
}
... on TargetNotFound {
message
requestedTarget
possibleTargets
}
}
}
}
}
... on Error {
__typename
Expand Down Expand Up @@ -69,7 +231,7 @@ mutation ($organization: String!, $project: String!, $parentCommit: ID!, $descri
commitId
message
}
...on ValidationError {
... on ValidationError {
__typename
subErrors {
__typename
Expand Down
Loading

0 comments on commit d8be069

Please sign in to comment.