Skip to content

Commit d0b77d8

Browse files
Cache publish failures (solver errors) (#589)
* Cache publish failures (solver errors) * Consolidate import caches
1 parent ab1340b commit d0b77d8

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

scripts/src/LegacyImporter.purs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,11 @@ runLegacyImport mode logs = do
222222
Log.info $ formatImportStats $ calculateImportStats legacyRegistry importedIndex
223223

224224
Log.info "Sorting packages for upload..."
225-
let indexPackages = ManifestIndex.toSortedArray importedIndex.registryIndex
225+
let allIndexPackages = ManifestIndex.toSortedArray importedIndex.registryIndex
226+
227+
Log.info "Removing packages that previously failed publish"
228+
indexPackages <- allIndexPackages # Array.filterA \(Manifest { name, version }) ->
229+
isNothing <$> Cache.get _importCache (PublishFailure name version)
226230

227231
allMetadata <- Registry.readAllMetadata
228232

@@ -287,6 +291,7 @@ runLegacyImport mode logs = do
287291
, "----------"
288292
]
289293
operation <- mkOperation (Manifest manifest)
294+
290295
result <- Except.runExcept $ API.publish source operation
291296
-- TODO: Some packages will fail because the legacy importer does not
292297
-- perform all the same validation checks that the publishing flow does.
@@ -297,7 +302,8 @@ runLegacyImport mode logs = do
297302
case result of
298303
Left error -> do
299304
Log.error $ "Failed to publish " <> formatted <> ": " <> error
300-
Right _ ->
305+
Cache.put _importCache (PublishFailure manifest.name manifest.version) error
306+
Right _ -> do
301307
Log.info $ "Published " <> formatted
302308

303309
-- | Record all package failures to the 'package-failures.json' file.
@@ -826,21 +832,29 @@ legacyRepoParser = do
826832
-- | A key type for the storage cache. Only supports packages identified by
827833
-- | their name and version.
828834
data ImportCache :: (Type -> Type -> Type) -> Type -> Type
829-
data ImportCache c a = ImportManifest PackageName RawVersion (c (Either VersionValidationError Manifest) a)
835+
data ImportCache c a
836+
= ImportManifest PackageName RawVersion (c (Either VersionValidationError Manifest) a)
837+
| PublishFailure PackageName Version (c String a)
830838

831839
instance Functor2 c => Functor (ImportCache c) where
832840
map k (ImportManifest name version a) = ImportManifest name version (map2 k a)
841+
map k (PublishFailure name version a) = PublishFailure name version (map2 k a)
833842

834843
instance MemoryEncodable ImportCache where
835844
encodeMemory = case _ of
836845
ImportManifest name (RawVersion version) next ->
837846
Exists.mkExists $ Key ("ImportManifest__" <> PackageName.print name <> "__" <> version) next
847+
PublishFailure name version next -> do
848+
Exists.mkExists $ Key ("PublishFailureCache__" <> PackageName.print name <> "__" <> Version.print version) next
838849

839850
instance FsEncodable ImportCache where
840851
encodeFs = case _ of
841852
ImportManifest name (RawVersion version) next -> do
842853
let codec = CA.Common.either versionValidationErrorCodec Manifest.codec
843854
Exists.mkExists $ AsJson ("ImportManifest__" <> PackageName.print name <> "__" <> version) codec next
855+
PublishFailure name version next -> do
856+
let codec = CA.string
857+
Exists.mkExists $ AsJson ("PublishFailureCache__" <> PackageName.print name <> "__" <> Version.print version) codec next
844858

845859
type IMPORT_CACHE r = (importCache :: Cache ImportCache | r)
846860

0 commit comments

Comments
 (0)