Skip to content

Commit 48c3cf7

Browse files
committed
[content-service] incremental workspace init
if we initialize the workspace from an outdated prebuild, we need the regular workspace tasks (including init) should run.
1 parent 3a6fe3a commit 48c3cf7

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

components/content-service/pkg/initializer/prebuild.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,20 @@ func (p *PrebuildInitializer) Run(ctx context.Context, mappings []archive.IDMapp
8181

8282
// at this point we're actually a prebuild initialiser because we've been able to restore
8383
// the prebuild.
84+
8485
src = csapi.WorkspaceInitFromPrebuild
8586

8687
// make sure we're on the correct branch
8788
for _, gi := range p.Git {
88-
err = runGitInit(ctx, gi)
89+
90+
commitChanged, err := runGitInit(ctx, gi)
8991
if err != nil {
9092
return src, err
9193
}
94+
if commitChanged {
95+
// head commit has changed, so it's an outdated prebuild, which we treat as other
96+
src = csapi.WorkspaceInitFromOther
97+
}
9298
}
9399
log.Debug("Initialized workspace with prebuilt snapshot")
94100
return
@@ -108,7 +114,7 @@ func clearWorkspace(location string) error {
108114
return nil
109115
}
110116

111-
func runGitInit(ctx context.Context, gInit *GitInitializer) (err error) {
117+
func runGitInit(ctx context.Context, gInit *GitInitializer) (commitChanged bool, err error) {
112118
span, ctx := opentracing.StartSpanFromContext(ctx, "runGitInit")
113119
span.LogFields(
114120
tracelog.String("IsWorkingCopy", fmt.Sprintf("%v", git.IsWorkingCopy(gInit.Location))),
@@ -125,14 +131,25 @@ func runGitInit(ctx context.Context, gInit *GitInitializer) (err error) {
125131
} else {
126132
// git returned a non-zero exit code because of some reason we did not anticipate or an actual failure.
127133
log.WithError(err).WithField("output", string(out)).Error("unexpected git stash error")
128-
return xerrors.Errorf("prebuild initializer: %w", err)
134+
return commitChanged, xerrors.Errorf("prebuild initializer: %w", err)
129135
}
130136
}
131137
didStash := !strings.Contains(string(out), "No local changes to save")
132138

139+
statusBefore, err := gInit.Status(ctx)
140+
if err != nil {
141+
log.WithError(err).Warn("couldn't run git status - continuing")
142+
}
133143
err = checkGitStatus(gInit.realizeCloneTarget(ctx))
134144
if err != nil {
135-
return xerrors.Errorf("prebuild initializer: %w", err)
145+
return commitChanged, xerrors.Errorf("prebuild initializer: %w", err)
146+
}
147+
statusAfter, err := gInit.Status(ctx)
148+
if err != nil {
149+
log.WithError(err).Warn("couldn't run git status - continuing")
150+
}
151+
if statusBefore != nil && statusAfter != nil {
152+
commitChanged = statusBefore.LatestCommit != statusAfter.LatestCommit
136153
}
137154

138155
err = gInit.UpdateSubmodules(ctx)
@@ -173,5 +190,5 @@ func runGitInit(ctx context.Context, gInit *GitInitializer) (err error) {
173190
return
174191
}
175192
}()
176-
return nil
193+
return commitChanged, nil
177194
}

0 commit comments

Comments
 (0)