Skip to content

Commit 16f689c

Browse files
authored
Add migrate command (#901)
1 parent eb3a92e commit 16f689c

File tree

17 files changed

+593
-349
lines changed

17 files changed

+593
-349
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
branches: [ master ]
88

99
env:
10-
STACK_VERSION: '2.7.3'
10+
STACK_VERSION: '2.9.1'
1111

1212
jobs:
1313
build:
@@ -17,7 +17,7 @@ jobs:
1717
matrix:
1818
include:
1919
- os: ubuntu-latest
20-
image: haskell:8.10.7-stretch@sha256:100f8fb7d7d8d64adb5e106fe8136b8d4cbdc03aeb2cbd145a7597d74b69bafb
20+
image: haskell:9.2.4
2121
- os: macOS-latest
2222
- os: windows-latest
2323
steps:
@@ -41,11 +41,9 @@ jobs:
4141
if: runner.os != 'Linux'
4242
uses: haskell/actions/setup@v1
4343
with:
44-
ghc-version: '8.10.7'
45-
stack-version: ${{ env.STACK_VERSION }}
4644
enable-stack: true
45+
stack-version: "${{ env.STACK_VERSION }}"
4746
stack-no-global: true
48-
stack-setup-ghc: true
4947
- name: Check Stack version and fix root access (Linux)
5048
if: runner.os == 'Linux'
5149
run: |
@@ -55,7 +53,7 @@ jobs:
5553
- name: Setup node and npm
5654
uses: actions/setup-node@v2
5755
with:
58-
node-version: 14
56+
node-version: 18
5957
# NB: We install gnu-tar because BSD tar is buggy on Github's macos machines,
6058
# and it breaks the cache: https://github.com/actions/cache/issues/403
6159
- name: Install GNU tar (macOS)
@@ -95,7 +93,7 @@ jobs:
9593
$HOME\AppData\Local\Programs\stack\x86_64-windows
9694
key: ${{ runner.os }}-${{ hashFiles('stack.yaml') }}-1
9795

98-
96+
9997

10098
- name: Install dependencies
10199
run: |
@@ -116,8 +114,8 @@ jobs:
116114
run: ./scripts/fix-home stack test
117115
shell: bash
118116

119-
- name: Install PureScript 0.14.0
120-
run: npm install -g [email protected].0
117+
- name: Install PureScript 0.14.9
118+
run: npm install -g [email protected].9
121119

122120
- name: Run tests (PureScript < 0.15.0)
123121
shell: bash

.github/workflows/release.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- '*'
77

88
env:
9-
STACK_VERSION: '2.7.3'
9+
STACK_VERSION: '2.9.1'
1010

1111
jobs:
1212
draft_release:
@@ -38,7 +38,7 @@ jobs:
3838
matrix:
3939
include:
4040
- os: ubuntu-latest
41-
image: haskell:8.10.7-stretch@sha256:100f8fb7d7d8d64adb5e106fe8136b8d4cbdc03aeb2cbd145a7597d74b69bafb
41+
image: haskell:9.2.4
4242
- os: macOS-latest
4343
- os: windows-latest
4444
steps:
@@ -52,11 +52,9 @@ jobs:
5252
if: runner.os != 'Linux'
5353
uses: haskell/actions/setup@v1
5454
with:
55-
ghc-version: '8.10.7'
5655
stack-version: ${{ env.STACK_VERSION }}
5756
enable-stack: true
5857
stack-no-global: true
59-
stack-setup-ghc: true
6058
- name: Check Stack version and fix root access (Linux)
6159
if: runner.os == 'Linux'
6260
run: |
@@ -65,7 +63,7 @@ jobs:
6563
- name: Setup node
6664
uses: actions/setup-node@v1
6765
with:
68-
node-version: 10
66+
node-version: 18
6967
# NB: We install gnu-tar because BSD tar is buggy on Github's macos machines,
7068
# and it breaks the cache: https://github.com/actions/cache/issues/403
7169
- name: Install GNU tar (macOS)
@@ -129,7 +127,7 @@ jobs:
129127
- uses: actions/checkout@v2
130128
- uses: actions/setup-node@v2
131129
with:
132-
node-version: 14
130+
node-version: 18
133131
- name: Publish to NPM
134132
shell: bash
135133
env:

app/Spago.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Spago.CLI (Command(..))
1111
import qualified System.Environment as Env
1212
import qualified Spago.Build
1313
import qualified Spago.Messages as Messages
14+
import qualified Spago.NewConfig
1415
import qualified Spago.Packages
1516
import qualified Spago.PackageSet
1617
import qualified Spago.CLI as CLI
@@ -75,6 +76,7 @@ main = withUtf8 $ do
7576
$ Ls.listPackages transitiveFlag jsonFlag
7677
Sources -> Run.withInstallEnv
7778
$ Spago.Packages.sources
79+
Migrate -> Run.withInstallEnv $ Spago.NewConfig.migrate
7880

7981
-- ### Commands that need a "publish env": install env + git and bower
8082
BumpVersion dryRun spec -> Run.withPublishEnv

appveyor.yml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ branches:
66

77
environment:
88
STACK_ROOT: C:\sr
9-
STACK_VERSION: 2.5.1
10-
nodejs_version: "14"
9+
STACK_VERSION: 2.9.1
10+
nodejs_version: "18"
1111

1212
matrix:
1313
- STACK_YAML: stack.yaml
@@ -29,11 +29,11 @@ install:
2929
- mkdir ps-0.15
3030
- ps: |
3131
$releases = "https://api.github.com/repos/purescript/purescript/releases"
32-
$tag = "v0.14.0"
32+
$tag = "v0.14.9"
3333
$download = "https://github.com/purescript/purescript/releases/download/$tag/win64.tar.gz"
3434
Invoke-WebRequest $download -Out ps-0.14\purescript.tar.gz
3535
36-
$tag = "v0.15.0"
36+
$tag = "v0.15.8"
3737
$download = "https://github.com/purescript/purescript/releases/download/$tag/win64.tar.gz"
3838
Invoke-WebRequest $download -Out ps-0.15\purescript.tar.gz
3939
- tar -xvf ps-0.14\purescript.tar.gz -C ps-0.14
@@ -62,9 +62,3 @@ test_script:
6262
# We install psa and rerun the tests that exercise it
6363
- cmd: npm install -g purescript-psa
6464
- cmd: stack test --ta "--match \"/Spago/spago run\""
65-
- cmd: npm uninstall -g purescript-psa
66-
# We rerun the same tests on PureScript 0.14.0
67-
- cmd: set PATH=C:\projects\spago\bin;C:\projects\spago\ps-0.14\purescript;%ORIGINAL_PATH%
68-
- cmd: stack test
69-
- cmd: npm install -g purescript-psa
70-
- cmd: stack test --ta "--match \"/Spago/spago run\""

spago.cabal

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ library
101101
Spago.GitHub
102102
Spago.GlobalCache
103103
Spago.Messages
104+
Spago.NewConfig
104105
Spago.Packages
105106
Spago.PackageSet
106107
Spago.Prelude
@@ -163,9 +164,11 @@ library
163164
, turtle
164165
, unliftio
165166
, unordered-containers
167+
, uri-encode
166168
, utf8-string
167169
, versions
168170
, with-utf8
171+
, yaml
169172
, zlib
170173

171174
executable spago

src/Spago/Bower.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Spago.Env
99

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

112-
if HashMap.member "version" info
112+
if KeyMap.member "version" info
113113
then pure $ Bower.VersionRange $ "^" <> version
114114
else pure $ Bower.VersionRange $ repo <> "#" <> version
115115

src/Spago/CLI.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ data Command
2525
-- | Default catch-all command
2626
= Default ShowVersion
2727

28+
| Migrate
29+
2830
-- | Initialize a new project
2931
| Init Force TemplateComments (Maybe Text)
3032

@@ -286,6 +288,12 @@ parser = do
286288
, pure Sources
287289
)
288290

291+
migrate =
292+
( "migrate"
293+
, "Produce a new-style, Registry-compatible configuration file from the current one"
294+
, pure Migrate
295+
)
296+
289297
verify =
290298
( "verify"
291299
, "Verify that a single package is consistent with the Package Set"
@@ -350,6 +358,7 @@ parser = do
350358
, search
351359
, path
352360
, sources
361+
, migrate
353362
]
354363
packagesCommands = CLI.subcommandGroup "Packages commands:"
355364
[ install

src/Spago/Config.hs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ parsePackage (Dhall.RecordLit ks') = do
6666
let ks = Dhall.extractRecordValues ks'
6767
repo <- Dhall.requireTypedKey ks "repo" (Dhall.auto :: Dhall.Decoder Repo)
6868
version <- Dhall.requireTypedKey ks "version" Dhall.strictText
69-
dependencies <- Dhall.requireTypedKey ks "dependencies" dependenciesType
69+
dependenciesList <- Dhall.requireTypedKey ks "dependencies" dependenciesType
70+
let dependencies = Set.fromList dependenciesList
7071
let location = Remote{..}
7172
pure Package{..}
7273
parsePackage (Dhall.App
@@ -77,7 +78,7 @@ parsePackage (Dhall.App
7778
True -> pure $ Text.dropEnd 12 spagoConfigPath
7879
False -> die [ display $ Messages.failedToParseLocalRepo spagoConfigPath ]
7980
rawConfig <- liftIO $ Dhall.readRawExpr spagoConfigPath
80-
dependencies <- case rawConfig of
81+
dependenciesList <- case rawConfig of
8182
Nothing -> die [ display $ Messages.cannotFindConfigLocalPackage spagoConfigPath ]
8283
Just (_header, expr) -> do
8384
newExpr <- transformMExpr (pure . filterDependencies . addSourcePaths) expr
@@ -89,6 +90,7 @@ parsePackage (Dhall.App
8990
(set Dhall.rootDirectory (Text.unpack localPath) Dhall.defaultInputSettings)
9091
dependenciesType
9192
(pretty newExpr)
93+
let dependencies = Set.fromList dependenciesList
9294
let location = Local{..}
9395
pure Package{..}
9496
parsePackage expr = die [ display $ Messages.failedToParsePackage $ pretty expr ]
@@ -135,6 +137,12 @@ parseConfig = do
135137
pure PublishConfig{..}
136138
publishConfig <- try ensurePublishConfig
137139

140+
let ensureMigrateConfig = do
141+
migrateLicense <- Dhall.requireTypedKey ks "license" Dhall.strictText
142+
migrateVersion <- Dhall.requireTypedKey ks "version" Dhall.strictText
143+
pure MigrateConfig{..}
144+
migrateConfig <- try ensureMigrateConfig
145+
138146
packageSet <- Dhall.requireKey ks "packages" (\case
139147
Dhall.RecordLit pkgs -> parsePackageSet (Dhall.extractRecordValues pkgs)
140148
something -> throwM $ Dhall.PackagesIsNotRecord something)
@@ -185,6 +193,7 @@ makeTempConfig dependencies alternateBackend configSourcePaths maybeTag = do
185193
let ks = Dhall.extractRecordValues ks'
186194
packageSet <- parsePackageSet ks
187195
let publishConfig = Left $ Dhall.RequiredKeyMissing "license" ks
196+
let migrateConfig = Left $ Dhall.RequiredKeyMissing "license" ks
188197
pure $ Config { name = "", ..}
189198
_ -> die [ "Failed to parse package set" ]
190199

0 commit comments

Comments
 (0)