@@ -44,6 +44,7 @@ import qualified Lamdera.Evergreen.Snapshot
4444import qualified Lamdera.TypeHash
4545import qualified Lamdera.Types
4646import qualified Lamdera.Legacy
47+ import qualified Network.Status
4748
4849
4950progressPointer t = do
@@ -89,6 +90,67 @@ run () () = do
8990 debug $ " app name:" ++ show appName
9091
9192 (localTypes, externalTypeWarnings) <- getLocalInfo
93+
94+ ips <- Network.Status. ips
95+
96+ if ips == []
97+ then offlineCheck root
98+ else onlineCheck root appName inDebug localTypes externalTypeWarnings isHoistRebuild forceVersion forceNotProd inProduction
99+
100+
101+ offlineCheck root = do
102+ progressDoc $ D. stack
103+ [ D. red $ D. reflow $ " --- OFFLINE MODE ---"
104+ , D. red $ D. reflow $ " It appears you are offline, continuing with limited checks."
105+ , D. red $ D. reflow $ " Note: being offline and continuing can cause serious confusion when returning offline, in particular:"
106+ , D. red $ D. reflow $ " - I have no idea what's in production, so I can only guess no types have changed."
107+ , D. red $ D. reflow $ " - This means I won't make any new snapshots"
108+ , D. red $ D. reflow $ " - I will assume the latest current migration on disk is the real latest migration"
109+ , D. red $ D. reflow $ " - I will type check that migration under Evergreen"
110+ ]
111+
112+ shouldContinue <- Reporting. ask $
113+ D. stack [ D. reflow $ " Do you want me to continue despite this? [Y/n]: " ]
114+
115+ if shouldContinue
116+ then do
117+ migrationFilePaths <- Lamdera.Evergreen. findMigrationFilePaths root
118+
119+ let
120+ nextVersionInfo =
121+ case last_ (debugNote " migrationVersions" $ Lamdera.Evergreen. migrationVersions migrationFilePaths) 1 of
122+ 1 -> WithoutMigrations 1
123+ x -> WithMigrations x
124+
125+ nextVersion = vinfoVersion nextVersionInfo
126+
127+ nextMigrationPathBare = (" src/Evergreen/Migrate/V" ) <> (show nextVersion) <> " .elm"
128+ nextMigrationPath = root </> nextMigrationPathBare
129+
130+ debug_ $ " nextVersionInfo" ++ show nextVersionInfo
131+
132+ debug $ " Reading migration source..."
133+ migrationSource <- T. decodeUtf8 <$> IO. readUtf8 nextMigrationPath
134+
135+ if textContains " Unimplemented" migrationSource
136+ then do
137+ Progress. throw $
138+ Help. report " UNIMPLEMENTED MIGRATION" (Just nextMigrationPathBare)
139+ (" The latest migration still has migration placeholders that need implementing:" )
140+ [ D. reflow $ nextMigrationPathBare
141+ , D. fillSep [" See" ,D. cyan (" <https://dashboard.lamdera.app/docs/evergreen>" )," for more info." ]
142+ ]
143+
144+ else do
145+ migrationCheck root nextVersionInfo
146+ else do
147+ pure ()
148+
149+ pure ()
150+
151+
152+ onlineCheck root appName inDebug localTypes externalTypeWarnings isHoistRebuild forceVersion forceNotProd inProduction = do
153+
92154 (prodVersion, productionTypes, nextVersion) <- getProdInfo appName inProduction forceNotProd forceVersion isHoistRebuild localTypes
93155
94156 let
@@ -278,39 +340,39 @@ forceVersion_ = do
278340 Nothing -> Nothing
279341
280342
281- getNextVersionInfo :: FilePath -> IO VersionInfo
282- getNextVersionInfo root = do
283-
284- hoistRebuild <- Env. lookupEnv " HOIST_REBUILD"
285- forceVersionM <- Env. lookupEnv " VERSION"
286- forceNotProd <- Env. lookupEnv " NOTPROD"
287- inProduction <- Lamdera. inProduction
288-
289- let isHoistRebuild = (hoistRebuild /= Nothing )
290- forceVersion = fromMaybe (- 1 ) $
291- case forceVersionM of
292- Just fv -> Text.Read. readMaybe fv
293- Nothing -> Nothing
294-
295- -- Lamdera.Legacy.temporaryCheckOldTypesNeedingMigration inProduction root
296-
297- -- progressPointer_ "Checking project compiles..."
298- -- checkUserProjectCompiles root
299-
300- appName <- Lamdera.Project. appNameOrThrow
301-
302- (localTypes, externalTypeWarnings) <- getLocalInfo
303- (prodVersion, productionTypes, nextVersion) <- getProdInfo appName inProduction forceNotProd forceVersion isHoistRebuild localTypes
304-
305- let
306- localTypesChangedFromProduction = productionTypes /= localTypes
307-
308- nextVersionInfo <- getNextVersionInfo_ nextVersion prodVersion isHoistRebuild localTypesChangedFromProduction
309-
310- pure nextVersionInfo
311-
312-
313-
343+ -- getNextVersionInfo :: FilePath -> IO VersionInfo
344+ -- getNextVersionInfo root = do
345+ --
346+ -- hoistRebuild <- Env.lookupEnv "HOIST_REBUILD"
347+ -- forceVersionM <- Env.lookupEnv "VERSION"
348+ -- forceNotProd <- Env.lookupEnv "NOTPROD"
349+ -- inProduction <- Lamdera.inProduction
350+ --
351+ -- let isHoistRebuild = (hoistRebuild /= Nothing)
352+ -- forceVersion = fromMaybe (-1) $
353+ -- case forceVersionM of
354+ -- Just fv -> Text.Read.readMaybe fv
355+ -- Nothing -> Nothing
356+ --
357+ -- -- Lamdera.Legacy.temporaryCheckOldTypesNeedingMigration inProduction root
358+ --
359+ -- -- progressPointer_ "Checking project compiles..."
360+ -- -- checkUserProjectCompiles root
361+ --
362+ -- appName <- Lamdera.Project.appNameOrThrow
363+ --
364+ -- (localTypes, externalTypeWarnings) <- getLocalInfo
365+ -- (prodVersion, productionTypes, nextVersion) <- getProdInfo appName inProduction forceNotProd forceVersion isHoistRebuild localTypes
366+ --
367+ -- let
368+ -- localTypesChangedFromProduction = productionTypes /= localTypes
369+ --
370+ -- nextVersionInfo <- getNextVersionInfo_ nextVersion prodVersion isHoistRebuild localTypesChangedFromProduction
371+ --
372+ -- pure nextVersionInfo
373+
374+
375+ getLocalInfo :: IO (([ Text ], [( Text , [ Text ], Lamdera.Types. DiffableType )]))
314376getLocalInfo = do
315377 hashesResult <- Lamdera.TypeHash. calculateAndWrite
316378 case hashesResult of
@@ -320,6 +382,7 @@ getLocalInfo = do
320382 pure (localTypes, externalTypeWarnings)
321383
322384
385+ getProdInfo :: Text -> Bool -> Maybe String -> Int -> Bool -> [Text ] -> IO (Int , [Text ], Int )
323386getProdInfo appName inProduction forceNotProd forceVersion isHoistRebuild localTypes = do
324387 (prodVersion, productionTypes) <-
325388 if isHoistRebuild
0 commit comments