Skip to content

Commit 3b6967b

Browse files
Enable spago init and spago upgrade-set to use user-specified package-set tag rather than latest release (#680)
* Enable user to specify a tag when initializing project via --tag * Add --tag option to `upgrade-set` command * Only notify user that package set doesn't exist if Dhall gets a 404 * Move useLatestRelease to where clause in updatePackageSetVersion * Inline shared code into updatePackageSetVersion * Implement tests for `--tag` parameter * Update changelog: add --tag as new feature and 'breaking changes' * Update readme to document --tag argument
1 parent 71b093c commit 3b6967b

File tree

12 files changed

+306
-104
lines changed

12 files changed

+306
-104
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
Breaking changes (😱!!!):
11+
- **Specify the package set version via `--tag` (#680)**
12+
13+
Example usage: `spago init --tag psc-0.13.2-20190725` and `spago upgrade-set --tag psc-0.13.2-20190725`. This is a breaking change because we are removing support for the old spacchetti/spacchetti-style location (i.e. in the src/packages.dhall) for the upgrade-set command.
14+
1015
## [0.16.0] - 2020-08-14
1116

1217
Breaking changes (😱!!!):

README.md

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ you'll have to carefully:
233233
- try to run `spago install some-package` for packages in the set
234234
- [add the missing packages](#add-a-package-to-the-package-set) if not in the set
235235

236-
237236
### See what commands and flags are supported
238237

239238
For an overview of the available commands, run:
@@ -252,6 +251,14 @@ $ spago build --help
252251
This will give a detailed view of the command, and list any command-specific
253252
(vs global) flags.
254253

254+
### Setup a new project using a specific package set
255+
256+
Since `spago init` does not necessarily use the latest package set. Fortunately, you can specify which package set to use via the `--tag` argument. See the [`purescript/package-sets` repo's releases](https://github.com/purescript/package-sets/releases) for tags you can use:
257+
258+
```bash
259+
$ spago init --tag "psc-0.13.8-20200822"
260+
```
261+
255262

256263
### Install a direct dependency
257264

@@ -557,23 +564,47 @@ if you could pull request it to the [Upstream package-set][package-sets] ❤️
557564
If you decide so, you can read up on how to do it [here][package-sets-contributing].
558565

559566

560-
### Automagically upgrade the package set
567+
### Upgrade the package set...
561568

562569
The version of the package-set you depend on is fixed in the `packages.dhall` file
563570
(look for the `upstream` var).
564571

565572
You can upgrade to the latest version of the package-set with the `upgrade-set`
566-
command, that will automatically find out the latest version, download it, and write
573+
command. It will download the package set and write
567574
the new url and hashes in the `packages.dhall` file for you.
568575

576+
Spago can update the package set to the latest release or to a specific release automagically. If you wish to use a specific commit, you will have to manually edit one part of your `packages.dhall` file. Each is covered below.
577+
578+
#### ...to the latest release automatically
579+
569580
Running it would look something like this:
570581

571582
```bash
572-
$ spago upgrade-set
573-
Found the most recent tag for "purescript/package-sets": "psc-0.12.3-20190227"
574-
Package-set upgraded to latest tag "psc-0.12.3-20190227"
583+
$ spago upgrade-set
584+
[info] Updating package-set tag to "psc-0.13.8-20200822"
585+
Fetching the new one and generating hashes.. (this might take some time)
586+
[info] Generating new hashes for the package set file so it will be cached.. (this might take some time)
587+
```
588+
589+
#### ...to a specific release automatically
590+
591+
If the package set exists, running `upgrade-set` would look something like this:
592+
593+
```bash
594+
$ spago upgrade-set --tag "psc-0.13.8-20200822"
595+
[info] Updating package-set tag to "psc-0.13.8-20200822"
575596
Fetching the new one and generating hashes.. (this might take some time)
576-
Done. Updating the local package-set file..
597+
[info] Generating new hashes for the package set file so it will be cached.. (this might take some time)
598+
```
599+
600+
If the package set does not exist, your `packages.dhall` file will not be touched and you will see a warning:
601+
602+
```bash
603+
spago upgrade-set --tag "whoops-i-made-a-big-typo"
604+
[info] Updating package-set tag to "whoops-i-made-a-big-typo"
605+
Fetching the new one and generating hashes.. (this might take some time)
606+
[warn] Package-set tag "whoops-i-made-a-big-typo" in the repo "purescript/package-sets" does not exist.
607+
Will ignore user-specified tag and continue using current tag: "psc-0.13.4-20191025"
577608
```
578609

579610
If you wish to detach from tags for your package-set, you can of course point it to a
@@ -584,6 +615,15 @@ let upstream =
584615
https://raw.githubusercontent.com/purescript/package-sets/bd72269fec59950404a380a46e293bde34b4618f/src/packages.dhall
585616
```
586617

618+
#### ... to a specific tag manually
619+
620+
If you wish to detach from tags for your package-set, you can of course point it to a
621+
specific commit. Just set your `upstream` to look something like this:
622+
623+
```haskell
624+
let upstream =
625+
https://raw.githubusercontent.com/purescript/package-sets/bd72269fec59950404a380a46e293bde34b4618f/src/packages.dhall
626+
```
587627

588628
### Monorepo
589629

app/Spago.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ main = withUtf8 $ do
4545
-> handleDefault shouldShowVersion
4646

4747
-- ### Commands that need only a basic global env
48-
Init force noComments
49-
-> void $ Spago.Packages.initProject force noComments
50-
PackageSetUpgrade
51-
-> Spago.PackageSet.upgradePackageSet
52-
Freeze
48+
Init force noComments tag
49+
-> void $ Spago.Packages.initProject force noComments tag
50+
PackageSetUpgrade tag
51+
-> Spago.PackageSet.updatePackageSetVersion tag
52+
Freeze
5353
-> Spago.PackageSet.freeze Spago.PackageSet.packagesPath
5454
Login
5555
-> Spago.GitHub.login

package.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ library:
9393
- fsnotify
9494
- github
9595
- Glob
96+
- http-types
9697
- http-client
9798
- http-conduit
9899
- lens-family-core

src/Spago/Build.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ repl newPackages sourcePaths pursArgs depsOnly = do
152152
Temp.withTempDirectory cacheDir "spago-repl-tmp" $ \dir -> do
153153
Turtle.cd (Turtle.decodeString dir)
154154

155-
config@Config{ packageSet = PackageSet{..}, ..}
156-
<- Packages.initProject NoForce Dhall.WithComments
157-
155+
config@Config{ packageSet = PackageSet{..}, ..}
156+
<- Packages.initProject NoForce Dhall.WithComments Nothing
157+
158158
let newConfig :: Config
159159
newConfig = config { Config.dependencies = dependencies <> newPackages }
160160
Run.withInstallEnv' (Just newConfig) (replAction purs)

src/Spago/CLI.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ data Command
2626
= Default ShowVersion
2727

2828
-- | Initialize a new project
29-
| Init Force TemplateComments
29+
| Init Force TemplateComments (Maybe Text)
3030

3131
-- | Install (download) dependencies defined in spago.dhall
3232
| Install [PackageName]
@@ -47,7 +47,7 @@ data Command
4747
| Login
4848

4949
-- | Upgrade the package-set to the latest release
50-
| PackageSetUpgrade
50+
| PackageSetUpgrade (Maybe Text)
5151

5252
-- | Freeze the package-set so it will be cached
5353
| Freeze
@@ -148,6 +148,7 @@ parser = do
148148
usePsa = bool UsePsa NoPsa <$> CLI.switch "no-psa" 'P' "Don't build with `psa`, but use `purs`"
149149
openDocs = bool NoOpenDocs DoOpenDocs <$> CLI.switch "open" 'o' "Open generated documentation in browser (for HTML format only)"
150150
noComments = bool WithComments NoComments <$> CLI.switch "no-comments" 'C' "Generate package.dhall and spago.dhall files without tutorial comments"
151+
tag = CLI.optional $ Opts.strOption (Opts.long "tag" <> Opts.help "Optional package set tag to be used instead of the latest one.")
151152
configPath = CLI.optional $ CLI.optText "config" 'x' "Optional config path to be used instead of the default spago.dhall"
152153
chkModsUniq = bool DoCheckModulesUnique NoCheckModulesUnique <$> CLI.switch "no-check-modules-unique" 'M' "Skip checking whether modules names are unique across all packages."
153154
transitive = bool NoIncludeTransitive IncludeTransitive <$> CLI.switch "transitive" 't' "Include transitive dependencies"
@@ -180,7 +181,7 @@ parser = do
180181
initProject =
181182
( "init"
182183
, "Initialize a new sample project, or migrate a psc-package one"
183-
, Init <$> force <*> noComments
184+
, Init <$> force <*> noComments <*> tag
184185
)
185186

186187
build =
@@ -283,7 +284,7 @@ parser = do
283284
upgradeSet =
284285
( "upgrade-set"
285286
, "Upgrade the upstream in packages.dhall to the latest package-sets release"
286-
, pure PackageSetUpgrade
287+
, PackageSetUpgrade <$> tag
287288
)
288289

289290
freeze =

src/Spago/Dhall.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,11 @@ readRawExpr pathText = do
9090

9191
writeRawExpr :: Text -> (Dhall.Header, DhallExpr Dhall.Import) -> IO ()
9292
writeRawExpr pathText (header, expr) = do
93+
-- Verify that the package set exists
94+
-- If Dhall gets a 404, it will throw a PrettyHttpException
95+
resolvedExpr <- Dhall.Import.load expr
9396
-- After modifying the expression, we have to check if it still typechecks
9497
-- if it doesn't we don't write to file.
95-
resolvedExpr <- Dhall.Import.load expr
9698
_ <- throws (Dhall.TypeCheck.typeOf resolvedExpr)
9799
writeTextFile pathText $ prettyWithHeader header expr
98100
format pathText

src/Spago/Messages.hs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,18 @@ failedToAddDeps pkgs = makeMessage $
140140
<> map ("- " <>) (NonEmpty.toList pkgs)
141141
<> [""]
142142

143-
upgradingPackageSet :: Text -> Text
144-
upgradingPackageSet newTag = makeMessage
145-
[ "Package-set upgraded to latest tag " <> surroundQuote newTag
143+
updatingPackageSet :: Text -> Text
144+
updatingPackageSet newTag = makeMessage
145+
[ "Updating package-set tag to " <> surroundQuote newTag
146146
, "Fetching the new one and generating hashes.. (this might take some time)"
147147
]
148148

149+
nonExistentPackageSet :: Text -> Text -> Text -> Text -> Text
150+
nonExistentPackageSet org repo oldTag newTag = makeMessage
151+
[ "Package-set tag " <> surroundQuote newTag <> " in the repo " <> surroundQuote (org <> "/" <> repo) <> " does not exist."
152+
, "Will ignore user-specified tag and continue using current tag: " <> surroundQuote oldTag
153+
]
154+
149155
freezePackageSet :: Text
150156
freezePackageSet = makeMessage
151157
[ "Generating new hashes for the package set file so it will be cached.. (this might take some time)"

0 commit comments

Comments
 (0)