Simplify previous manifest collection
This commit is contained in:
@@ -111,13 +111,10 @@ func (publishStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*S
|
|||||||
return nil, fmt.Errorf("publish: object store does not support verified source uploads")
|
return nil, fmt.Errorf("publish: object store does not support verified source uploads")
|
||||||
}
|
}
|
||||||
sessionPaths := publishSessionPaths(env, m)
|
sessionPaths := publishSessionPaths(env, m)
|
||||||
previousFiles, previousManifestFile, err := collectPublishPreviousFiles(ctx, sessionPaths.PreviousDir)
|
previousFiles, err := collectPublishPreviousFiles(ctx, sessionPaths.PreviousDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("publish: collect previous files: %w", err)
|
return nil, fmt.Errorf("publish: collect previous files: %w", err)
|
||||||
}
|
}
|
||||||
if previousManifestFile != nil {
|
|
||||||
defer previousManifestFile.Close()
|
|
||||||
}
|
|
||||||
previousSources, err := openPublishRunFiles(sessionPaths.PreviousDir, previousFiles)
|
previousSources, err := openPublishRunFiles(sessionPaths.PreviousDir, previousFiles)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("publish: verify previous files: %w", err)
|
return nil, fmt.Errorf("publish: verify previous files: %w", err)
|
||||||
@@ -877,37 +874,33 @@ func collectPublishRunFiles(runRoot string, sessionManifest *manifest.Manifest)
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func collectPublishPreviousFiles(ctx context.Context, previousDir string) ([]publishUploadFile, *os.File, error) {
|
func collectPublishPreviousFiles(ctx context.Context, previousDir string) ([]publishUploadFile, error) {
|
||||||
previousDir = filepath.Clean(strings.TrimSpace(previousDir))
|
previousDir = filepath.Clean(strings.TrimSpace(previousDir))
|
||||||
if previousDir == "" || previousDir == "." {
|
if previousDir == "" || previousDir == "." {
|
||||||
return nil, nil, fmt.Errorf("previous directory is required")
|
return nil, fmt.Errorf("previous directory is required")
|
||||||
}
|
}
|
||||||
info, err := os.Lstat(previousDir)
|
info, err := os.Lstat(previousDir)
|
||||||
if errors.Is(err, os.ErrNotExist) {
|
if errors.Is(err, os.ErrNotExist) {
|
||||||
return nil, nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("inspect previous directory: %w", err)
|
return nil, fmt.Errorf("inspect previous directory: %w", err)
|
||||||
}
|
}
|
||||||
if info.Mode()&os.ModeSymlink != 0 || !info.IsDir() {
|
if info.Mode()&os.ModeSymlink != 0 || !info.IsDir() {
|
||||||
return nil, nil, fmt.Errorf("previous directory is not a regular directory")
|
return nil, fmt.Errorf("previous directory is not a regular directory")
|
||||||
}
|
}
|
||||||
|
|
||||||
manifestFile, err := openPublishOutputSource(filepath.Join(previousDir, "manifest.json"))
|
manifestFile, err := openPublishOutputSource(filepath.Join(previousDir, "manifest.json"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, os.ErrNotExist) {
|
if errors.Is(err, os.ErrNotExist) {
|
||||||
return nil, nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
return nil, nil, fmt.Errorf("open previous manifest: %w", err)
|
return nil, fmt.Errorf("open previous manifest: %w", err)
|
||||||
}
|
}
|
||||||
|
defer manifestFile.Close()
|
||||||
previousManifest, err := (&manifest.LocalStore{}).LoadReader(ctx, manifestFile)
|
previousManifest, err := (&manifest.LocalStore{}).LoadReader(ctx, manifestFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = manifestFile.Close()
|
return nil, fmt.Errorf("load previous manifest: %w", err)
|
||||||
return nil, nil, fmt.Errorf("load previous manifest: %w", err)
|
|
||||||
}
|
|
||||||
if _, err := manifestFile.Seek(0, io.SeekStart); err != nil {
|
|
||||||
_ = manifestFile.Close()
|
|
||||||
return nil, nil, fmt.Errorf("rewind previous manifest: %w", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
files := map[string]publishUploadFile{
|
files := map[string]publishUploadFile{
|
||||||
@@ -934,13 +927,11 @@ func collectPublishPreviousFiles(ctx context.Context, previousDir string) ([]pub
|
|||||||
}
|
}
|
||||||
for _, artifact := range previousManifest.Artifacts {
|
for _, artifact := range previousManifest.Artifacts {
|
||||||
if err := add(artifact.ArchivePath, artifact.Checksum); err != nil {
|
if err := add(artifact.ArchivePath, artifact.Checksum); err != nil {
|
||||||
_ = manifestFile.Close()
|
return nil, err
|
||||||
return nil, nil, err
|
|
||||||
}
|
}
|
||||||
if artifact.ArchivePath == "" {
|
if artifact.ArchivePath == "" {
|
||||||
if err := add(artifact.LocalPath, artifact.Checksum); err != nil {
|
if err := add(artifact.LocalPath, artifact.Checksum); err != nil {
|
||||||
_ = manifestFile.Close()
|
return nil, err
|
||||||
return nil, nil, err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -950,20 +941,17 @@ func collectPublishPreviousFiles(ctx context.Context, previousDir string) ([]pub
|
|||||||
}
|
}
|
||||||
for _, artifact := range record.Outputs {
|
for _, artifact := range record.Outputs {
|
||||||
if err := add(artifact.ArchivePath, artifact.Checksum); err != nil {
|
if err := add(artifact.ArchivePath, artifact.Checksum); err != nil {
|
||||||
_ = manifestFile.Close()
|
return nil, err
|
||||||
return nil, nil, err
|
|
||||||
}
|
}
|
||||||
if artifact.ArchivePath == "" {
|
if artifact.ArchivePath == "" {
|
||||||
if err := add(artifact.LocalPath, artifact.Checksum); err != nil {
|
if err := add(artifact.LocalPath, artifact.Checksum); err != nil {
|
||||||
_ = manifestFile.Close()
|
return nil, err
|
||||||
return nil, nil, err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, path := range append(append([]string(nil), record.Logs...), record.GeneratedConfigs...) {
|
for _, path := range append(append([]string(nil), record.Logs...), record.GeneratedConfigs...) {
|
||||||
if err := add(path, ""); err != nil {
|
if err := add(path, ""); err != nil {
|
||||||
_ = manifestFile.Close()
|
return nil, err
|
||||||
return nil, nil, err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -972,7 +960,7 @@ func collectPublishPreviousFiles(ctx context.Context, previousDir string) ([]pub
|
|||||||
out = append(out, file)
|
out = append(out, file)
|
||||||
}
|
}
|
||||||
sort.Slice(out, func(i, j int) bool { return out[i].RelativePath < out[j].RelativePath })
|
sort.Slice(out, func(i, j int) bool { return out[i].RelativePath < out[j].RelativePath })
|
||||||
return out, manifestFile, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func openPublishRunFiles(runRoot string, files []publishUploadFile) ([]*os.File, error) {
|
func openPublishRunFiles(runRoot string, files []publishUploadFile) ([]*os.File, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user