Skip to content

Commit

Permalink
Move (Package)Source data type to Prelude
Browse files Browse the repository at this point in the history
  • Loading branch information
pete-murphy committed Aug 22, 2023
1 parent 282a4f0 commit 6da962e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
25 changes: 6 additions & 19 deletions app/src/App/API.purs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Registry.App.API
( Source(..)
, PackageSetUpdateEffects
( PackageSetUpdateEffects
, packageSetUpdate
, PublishEffects
, publish
Expand Down Expand Up @@ -95,18 +94,6 @@ import Spago.Core.Config as Spago
import Spago.Core.Prelude as Spago.Prelude
import Spago.Log as Spago.Log

-- | Operations can be exercised for old, pre-registry packages, or for packages
-- | which are on the 0.15 compiler series. If a true legacy package is uploaded
-- | then we do not require compilation to succeed and we don't publish docs.
data Source = Legacy | Current

derive instance Eq Source

printSource :: Source -> String
printSource = case _ of
Legacy -> "legacy"
Current -> "current"

type PackageSetUpdateEffects r = (REGISTRY + PACKAGE_SETS + GITHUB + GITHUB_EVENT_ENV + COMMENT + LOG + EXCEPT String + r)

-- | Process a package set update. Package set updates are only processed via
Expand Down Expand Up @@ -327,11 +314,11 @@ type PublishEffects r = (RESOURCE_ENV + PURSUIT + REGISTRY + STORAGE + SOURCE +
-- | published before then it will be registered and the given version will be
-- | upload. If it has been published before then the existing metadata will be
-- | updated with the new version.
publish :: forall r. Source -> PublishData -> Run (PublishEffects + r) Unit
publish :: forall r. PackageSource -> PublishData -> Run (PublishEffects + r) Unit
publish source payload = do
let printedName = PackageName.print payload.name

Log.debug $ "Publishing " <> printSource source <> " package " <> printedName <> " with payload:\n" <> stringifyJson Operation.publishCodec payload
Log.debug $ "Publishing " <> printPackageSource source <> " package " <> printedName <> " with payload:\n" <> stringifyJson Operation.publishCodec payload

Log.debug $ "Verifying metadata..."
Metadata existingMetadata <- Registry.readMetadata payload.name >>= case _ of
Expand Down Expand Up @@ -551,7 +538,7 @@ publish source payload = do
}

type PublishRegistry =
{ source :: Source
{ source :: PackageSource
, manifest :: Manifest
, metadata :: Metadata
, payload :: PublishData
Expand Down Expand Up @@ -632,7 +619,7 @@ publishRegistry { source, payload, metadata: Metadata metadata, manifest: Manife
Left error
-- We allow legacy packages to fail compilation because we do not
-- necessarily know what compiler to use with them.
| source == Legacy -> do
| source == PackageSource'Legacy -> do
Log.debug error
Log.warn "Failed to compile, but continuing because this package is a legacy package."
| otherwise ->
Expand All @@ -655,7 +642,7 @@ publishRegistry { source, payload, metadata: Metadata metadata, manifest: Manife
-- team should manually insert the entry.
Registry.writeManifest (Manifest manifest)

when (source == Current) $ case compilationResult of
when (source == PackageSource'Current) $ case compilationResult of
Left error -> do
Log.error $ "Compilation failed, cannot upload to pursuit: " <> error
Except.throw "Cannot publish to Pursuit because this package failed to compile."
Expand Down
3 changes: 1 addition & 2 deletions app/src/App/GitHubIssue.purs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import Foreign.Object as Object
import Node.FS.Aff as FS.Aff
import Node.Path as Path
import Node.Process as Process
import Registry.App.API (Source(..))
import Registry.App.API as API
import Registry.App.Auth as Auth
import Registry.App.CLI.Git as Git
Expand Down Expand Up @@ -58,7 +57,7 @@ main = launchAff_ $ do

Right packageOperation -> case packageOperation of
Publish payload ->
API.publish Current payload
API.publish PackageSource'Current payload
Authenticated payload -> do
-- If we receive an authenticated operation via GitHub, then we
-- re-sign it with pacchettibotti credentials if and only if the
Expand Down
16 changes: 16 additions & 0 deletions app/src/App/Prelude.purs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Registry.App.Prelude
( LogVerbosity(..)
, PackageSource(..)
, PursPublishMethod(..)
, RetryRequestError(..)
, Retry
Expand All @@ -21,6 +22,7 @@ module Registry.App.Prelude
, parseJson
, partitionEithers
, printJson
, printPackageSource
, pursPublishMethod
, readJsonFile
, scratchDir
Expand Down Expand Up @@ -272,3 +274,17 @@ data PursPublishMethod = LegacyPursPublish | PursPublish
-- | The current purs publish method
pursPublishMethod :: PursPublishMethod
pursPublishMethod = LegacyPursPublish

-- | Operations can be exercised for old, pre-registry packages, or for packages
-- | which are on the 0.15 compiler series. If a true legacy package is uploaded
-- | then we do not require compilation to succeed and we don't publish docs.
data PackageSource
= PackageSource'Legacy
| PackageSource'Current

derive instance Eq PackageSource

printPackageSource :: PackageSource -> String
printPackageSource = case _ of
PackageSource'Legacy -> "legacy"
PackageSource'Current -> "current"
3 changes: 1 addition & 2 deletions app/src/App/Server.purs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import Node.Process as Process
import Record as Record
import Registry.API.V1 (JobId(..), JobType(..), LogLevel(..), Route(..))
import Registry.API.V1 as V1
import Registry.App.API (Source(..))
import Registry.App.API as API
import Registry.App.CLI.Git as Git
import Registry.App.Effect.Cache (CacheRef)
Expand Down Expand Up @@ -71,7 +70,7 @@ router env { route, method, body } = HTTPurple.usingCont case route, method of
lift $ Log.info $ "Received Publish request: " <> printJson Operation.publishCodec publish
forkPipelineJob publish.name publish.ref PublishJob \jobId -> do
Log.info $ "Received Publish request, job id: " <> unwrap jobId
API.publish Current publish
API.publish PackageSource'Current publish

Unpublish, Post -> do
auth <- HTTPurple.fromJson (jsonDecoder Operation.authenticatedCodec) body
Expand Down
4 changes: 2 additions & 2 deletions app/test/App/API.purs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ spec = do
}

-- First, we publish the package.
API.publish API.Current publishArgs
API.publish PackageSource'Current publishArgs

-- Then, we can check that it did make it to "Pursuit" as expected
Pursuit.getPublishedVersions name >>= case _ of
Expand All @@ -84,7 +84,7 @@ spec = do

-- Finally, we can verify that publishing the package again should fail
-- since it already exists.
Except.runExcept (API.publish API.Current publishArgs) >>= case _ of
Except.runExcept (API.publish PackageSource'Current publishArgs) >>= case _ of
Left _ -> pure unit
Right _ -> Except.throw $ "Expected publishing " <> formatPackageVersion name version <> " twice to fail."
where
Expand Down
7 changes: 3 additions & 4 deletions scripts/src/LegacyImporter.purs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import Parsing.Combinators as Parsing.Combinators
import Parsing.Combinators.Array as Parsing.Combinators.Array
import Parsing.String as Parsing.String
import Parsing.String.Basic as Parsing.String.Basic
import Registry.App.API (Source(..))
import Registry.App.API as API
import Registry.App.CLI.Git as Git
import Registry.App.Effect.Cache (class FsEncodable, class MemoryEncodable, Cache, FsEncoding(..), MemoryEncoding(..))
Expand Down Expand Up @@ -281,9 +280,9 @@ runLegacyImport mode logs = do

let
source = case mode of
DryRun -> Legacy
GenerateRegistry -> Legacy
UpdateRegistry -> Current
DryRun -> PackageSource'Legacy
GenerateRegistry -> PackageSource'Legacy
UpdateRegistry -> PackageSource'Current

void $ for notPublished \(Manifest manifest) -> do
let formatted = formatPackageVersion manifest.name manifest.version
Expand Down
2 changes: 1 addition & 1 deletion scripts/src/PackageDeleter.purs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ deleteVersion arguments name version = do
Just (Left _) -> Log.error "Cannot reimport a version that was specifically unpublished"
Just (Right specificPackageMetadata) -> do
-- Obtains `newMetadata` via cache
API.publish API.Legacy
API.publish PackageSource'Legacy
{ location: Just oldMetadata.location
, name: name
, ref: specificPackageMetadata.ref
Expand Down

0 comments on commit 6da962e

Please sign in to comment.