Skip to content

Commit

Permalink
Add migrate command (purescript#901)
Browse files Browse the repository at this point in the history
  • Loading branch information
f-f authored May 4, 2023
1 parent eb3a92e commit 16f689c
Show file tree
Hide file tree
Showing 17 changed files with 593 additions and 349 deletions.
16 changes: 7 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches: [ master ]

env:
STACK_VERSION: '2.7.3'
STACK_VERSION: '2.9.1'

jobs:
build:
Expand All @@ -17,7 +17,7 @@ jobs:
matrix:
include:
- os: ubuntu-latest
image: haskell:8.10.7-stretch@sha256:100f8fb7d7d8d64adb5e106fe8136b8d4cbdc03aeb2cbd145a7597d74b69bafb
image: haskell:9.2.4
- os: macOS-latest
- os: windows-latest
steps:
Expand All @@ -41,11 +41,9 @@ jobs:
if: runner.os != 'Linux'
uses: haskell/actions/setup@v1
with:
ghc-version: '8.10.7'
stack-version: ${{ env.STACK_VERSION }}
enable-stack: true
stack-version: "${{ env.STACK_VERSION }}"
stack-no-global: true
stack-setup-ghc: true
- name: Check Stack version and fix root access (Linux)
if: runner.os == 'Linux'
run: |
Expand All @@ -55,7 +53,7 @@ jobs:
- name: Setup node and npm
uses: actions/setup-node@v2
with:
node-version: 14
node-version: 18
# NB: We install gnu-tar because BSD tar is buggy on Github's macos machines,
# and it breaks the cache: https://github.com/actions/cache/issues/403
- name: Install GNU tar (macOS)
Expand Down Expand Up @@ -95,7 +93,7 @@ jobs:
$HOME\AppData\Local\Programs\stack\x86_64-windows
key: ${{ runner.os }}-${{ hashFiles('stack.yaml') }}-1

- run: npm install -g [email protected].0 [email protected] [email protected] [email protected]
- run: npm install -g [email protected].8 [email protected] [email protected] [email protected]

- name: Install dependencies
run: |
Expand All @@ -116,8 +114,8 @@ jobs:
run: ./scripts/fix-home stack test
shell: bash

- name: Install PureScript 0.14.0
run: npm install -g [email protected].0
- name: Install PureScript 0.14.9
run: npm install -g [email protected].9

- name: Run tests (PureScript < 0.15.0)
shell: bash
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- '*'

env:
STACK_VERSION: '2.7.3'
STACK_VERSION: '2.9.1'

jobs:
draft_release:
Expand Down Expand Up @@ -38,7 +38,7 @@ jobs:
matrix:
include:
- os: ubuntu-latest
image: haskell:8.10.7-stretch@sha256:100f8fb7d7d8d64adb5e106fe8136b8d4cbdc03aeb2cbd145a7597d74b69bafb
image: haskell:9.2.4
- os: macOS-latest
- os: windows-latest
steps:
Expand All @@ -52,11 +52,9 @@ jobs:
if: runner.os != 'Linux'
uses: haskell/actions/setup@v1
with:
ghc-version: '8.10.7'
stack-version: ${{ env.STACK_VERSION }}
enable-stack: true
stack-no-global: true
stack-setup-ghc: true
- name: Check Stack version and fix root access (Linux)
if: runner.os == 'Linux'
run: |
Expand All @@ -65,7 +63,7 @@ jobs:
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: 10
node-version: 18
# NB: We install gnu-tar because BSD tar is buggy on Github's macos machines,
# and it breaks the cache: https://github.com/actions/cache/issues/403
- name: Install GNU tar (macOS)
Expand Down Expand Up @@ -129,7 +127,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14
node-version: 18
- name: Publish to NPM
shell: bash
env:
Expand Down
2 changes: 2 additions & 0 deletions app/Spago.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Spago.CLI (Command(..))
import qualified System.Environment as Env
import qualified Spago.Build
import qualified Spago.Messages as Messages
import qualified Spago.NewConfig
import qualified Spago.Packages
import qualified Spago.PackageSet
import qualified Spago.CLI as CLI
Expand Down Expand Up @@ -75,6 +76,7 @@ main = withUtf8 $ do
$ Ls.listPackages transitiveFlag jsonFlag
Sources -> Run.withInstallEnv
$ Spago.Packages.sources
Migrate -> Run.withInstallEnv $ Spago.NewConfig.migrate

-- ### Commands that need a "publish env": install env + git and bower
BumpVersion dryRun spec -> Run.withPublishEnv
Expand Down
14 changes: 4 additions & 10 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ branches:

environment:
STACK_ROOT: C:\sr
STACK_VERSION: 2.5.1
nodejs_version: "14"
STACK_VERSION: 2.9.1
nodejs_version: "18"

matrix:
- STACK_YAML: stack.yaml
Expand All @@ -29,11 +29,11 @@ install:
- mkdir ps-0.15
- ps: |
$releases = "https://api.github.com/repos/purescript/purescript/releases"
$tag = "v0.14.0"
$tag = "v0.14.9"
$download = "https://github.com/purescript/purescript/releases/download/$tag/win64.tar.gz"
Invoke-WebRequest $download -Out ps-0.14\purescript.tar.gz
$tag = "v0.15.0"
$tag = "v0.15.8"
$download = "https://github.com/purescript/purescript/releases/download/$tag/win64.tar.gz"
Invoke-WebRequest $download -Out ps-0.15\purescript.tar.gz
- tar -xvf ps-0.14\purescript.tar.gz -C ps-0.14
Expand Down Expand Up @@ -62,9 +62,3 @@ test_script:
# We install psa and rerun the tests that exercise it
- cmd: npm install -g purescript-psa
- cmd: stack test --ta "--match \"/Spago/spago run\""
- cmd: npm uninstall -g purescript-psa
# We rerun the same tests on PureScript 0.14.0
- cmd: set PATH=C:\projects\spago\bin;C:\projects\spago\ps-0.14\purescript;%ORIGINAL_PATH%
- cmd: stack test
- cmd: npm install -g purescript-psa
- cmd: stack test --ta "--match \"/Spago/spago run\""
3 changes: 3 additions & 0 deletions spago.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ library
Spago.GitHub
Spago.GlobalCache
Spago.Messages
Spago.NewConfig
Spago.Packages
Spago.PackageSet
Spago.Prelude
Expand Down Expand Up @@ -163,9 +164,11 @@ library
, turtle
, unliftio
, unordered-containers
, uri-encode
, utf8-string
, versions
, with-utf8
, yaml
, zlib

executable spago
Expand Down
4 changes: 2 additions & 2 deletions src/Spago/Bower.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Spago.Env

import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Encode.Pretty as Pretty
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Aeson.KeyMap as KeyMap
import qualified Data.Text as Text
import qualified System.Info
import qualified Turtle
Expand Down Expand Up @@ -109,7 +109,7 @@ mkBowerVersion packageName version (Repo repo) = do
Just (Object obj) -> pure obj
_ -> die [ display $ "Unable to decode output from `bower " <> Text.intercalate " " args <> "`: ", display out ]

if HashMap.member "version" info
if KeyMap.member "version" info
then pure $ Bower.VersionRange $ "^" <> version
else pure $ Bower.VersionRange $ repo <> "#" <> version

Expand Down
9 changes: 9 additions & 0 deletions src/Spago/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ data Command
-- | Default catch-all command
= Default ShowVersion

| Migrate

-- | Initialize a new project
| Init Force TemplateComments (Maybe Text)

Expand Down Expand Up @@ -286,6 +288,12 @@ parser = do
, pure Sources
)

migrate =
( "migrate"
, "Produce a new-style, Registry-compatible configuration file from the current one"
, pure Migrate
)

verify =
( "verify"
, "Verify that a single package is consistent with the Package Set"
Expand Down Expand Up @@ -350,6 +358,7 @@ parser = do
, search
, path
, sources
, migrate
]
packagesCommands = CLI.subcommandGroup "Packages commands:"
[ install
Expand Down
13 changes: 11 additions & 2 deletions src/Spago/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ parsePackage (Dhall.RecordLit ks') = do
let ks = Dhall.extractRecordValues ks'
repo <- Dhall.requireTypedKey ks "repo" (Dhall.auto :: Dhall.Decoder Repo)
version <- Dhall.requireTypedKey ks "version" Dhall.strictText
dependencies <- Dhall.requireTypedKey ks "dependencies" dependenciesType
dependenciesList <- Dhall.requireTypedKey ks "dependencies" dependenciesType
let dependencies = Set.fromList dependenciesList
let location = Remote{..}
pure Package{..}
parsePackage (Dhall.App
Expand All @@ -77,7 +78,7 @@ parsePackage (Dhall.App
True -> pure $ Text.dropEnd 12 spagoConfigPath
False -> die [ display $ Messages.failedToParseLocalRepo spagoConfigPath ]
rawConfig <- liftIO $ Dhall.readRawExpr spagoConfigPath
dependencies <- case rawConfig of
dependenciesList <- case rawConfig of
Nothing -> die [ display $ Messages.cannotFindConfigLocalPackage spagoConfigPath ]
Just (_header, expr) -> do
newExpr <- transformMExpr (pure . filterDependencies . addSourcePaths) expr
Expand All @@ -89,6 +90,7 @@ parsePackage (Dhall.App
(set Dhall.rootDirectory (Text.unpack localPath) Dhall.defaultInputSettings)
dependenciesType
(pretty newExpr)
let dependencies = Set.fromList dependenciesList
let location = Local{..}
pure Package{..}
parsePackage expr = die [ display $ Messages.failedToParsePackage $ pretty expr ]
Expand Down Expand Up @@ -135,6 +137,12 @@ parseConfig = do
pure PublishConfig{..}
publishConfig <- try ensurePublishConfig

let ensureMigrateConfig = do
migrateLicense <- Dhall.requireTypedKey ks "license" Dhall.strictText
migrateVersion <- Dhall.requireTypedKey ks "version" Dhall.strictText
pure MigrateConfig{..}
migrateConfig <- try ensureMigrateConfig

packageSet <- Dhall.requireKey ks "packages" (\case
Dhall.RecordLit pkgs -> parsePackageSet (Dhall.extractRecordValues pkgs)
something -> throwM $ Dhall.PackagesIsNotRecord something)
Expand Down Expand Up @@ -185,6 +193,7 @@ makeTempConfig dependencies alternateBackend configSourcePaths maybeTag = do
let ks = Dhall.extractRecordValues ks'
packageSet <- parsePackageSet ks
let publishConfig = Left $ Dhall.RequiredKeyMissing "license" ks
let migrateConfig = Left $ Dhall.RequiredKeyMissing "license" ks
pure $ Config { name = "", ..}
_ -> die [ "Failed to parse package set" ]

Expand Down
Loading

0 comments on commit 16f689c

Please sign in to comment.