Skip to content

Commit

Permalink
Reinstate Windows CI (#995)
Browse files Browse the repository at this point in the history
  • Loading branch information
f-f authored Sep 17, 2023
1 parent 0eda274 commit 2206c40
Show file tree
Hide file tree
Showing 23 changed files with 198 additions and 94 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
include:
- os: ubuntu-latest
- os: macOS-latest
# - os: windows-latest
- os: windows-latest
steps:
# We set LF endings so that the Windows environment is consistent with the rest
# See here for context: https://github.com/actions/checkout/issues/135
Expand Down Expand Up @@ -52,8 +52,8 @@ jobs:
${{ runner.os }}-build-
${{ runner.os }}-
- name: Setup PureScript dependencies
run: npm i --global purescript@0.15.10 spago@0.93.11 purs-tidy@latest esbuild@latest
- name: Install global NPM packages
run: npm i --global purescript@0.15.10 spago@next purs-tidy@latest esbuild@latest

- name: Cache PureScript dependencies
uses: actions/cache@v2
Expand All @@ -64,13 +64,16 @@ jobs:
output
- name: Install NPM dependencies
run: npm install
run: npm ci

- name: Install PureScript dependencies
run: spago install

- name: Build executable
run: spago bundle -p spago-bin
- name: Build the project
run: spago build

- name: Bootstrap executable
run: ./bin/index.dev.js -p spago-bin

- name: Run tests
run: spago test
Expand Down
2 changes: 1 addition & 1 deletion bin/spago.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package:
name: spago-bin
publish:
version: 0.93.11
version: 0.93.13
license: BSD-3-Clause
dependencies:
- aff
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spago",
"version": "0.93.11",
"version": "0.93.13",
"license": "BSD-3-Clause",
"description": "🍝 PureScript package manager and build tool",
"keywords": [
Expand Down
78 changes: 74 additions & 4 deletions spago.lock
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ workspace:
extra_packages:
registry-foreign:
git: https://github.com/purescript/registry-dev.git
ref: 7e1f67d1205d68d7f22d9d55d25ba2354dfbb14e
ref: 6a803c37577af368caa221a2a06d6be2079d32da
subdir: foreign
registry-lib:
git: https://github.com/purescript/registry-dev.git
ref: 7e1f67d1205d68d7f22d9d55d25ba2354dfbb14e
ref: 6a803c37577af368caa221a2a06d6be2079d32da
subdir: lib
packages:
aff:
Expand Down Expand Up @@ -469,6 +469,52 @@ packages:
integrity: sha256-A0JQHpTfo1dNOj9U5/Fd3xndlRSE0g2IQWOGor2yXn8=
dependencies:
- unsafe-coerce
fetch:
type: registry
version: 1.1.4
integrity: sha256-Tmt60rjS4PNtKMVGpo8O6W1Fdhcu3a3CvyN/x+SwXEs=
dependencies:
- aff
- aff-promise
- arraybuffer-types
- effect
- fetch-core
- foreign
- http-methods
- newtype
- prelude
- record
- typelevel-prelude
- unsafe-coerce
- web-file
- web-promise
- web-streams
fetch-core:
type: registry
version: 4.0.4
integrity: sha256-lS4yhvznII/vg37LewU/Ubeoj6OpxED2kb5/yn58YQQ=
dependencies:
- arraybuffer-types
- arrays
- console
- effect
- foldable-traversable
- foreign
- foreign-object
- functions
- http-methods
- maybe
- newtype
- nullable
- prelude
- record
- tuples
- typelevel-prelude
- unfoldable
- unsafe-coerce
- web-file
- web-promise
- web-streams
filterable:
type: registry
version: 5.0.0
Expand Down Expand Up @@ -1175,7 +1221,7 @@ packages:
registry-foreign:
type: git
url: https://github.com/purescript/registry-dev.git
rev: 7e1f67d1205d68d7f22d9d55d25ba2354dfbb14e
rev: 6a803c37577af368caa221a2a06d6be2079d32da
subdir: foreign
dependencies:
- aff
Expand All @@ -1189,6 +1235,7 @@ packages:
- datetime
- effect
- either
- fetch
- filterable
- foldable-traversable
- foreign-object
Expand All @@ -1212,7 +1259,7 @@ packages:
registry-lib:
type: git
url: https://github.com/purescript/registry-dev.git
rev: 7e1f67d1205d68d7f22d9d55d25ba2354dfbb14e
rev: 6a803c37577af368caa221a2a06d6be2079d32da
subdir: lib
dependencies:
- aff
Expand Down Expand Up @@ -1468,13 +1515,36 @@ packages:
- web-dom
- web-file
- web-storage
web-promise:
type: registry
version: 3.1.0
integrity: sha256-YfqJyEC3bHH6D8QgTi0ME5oJmGYOuZ2TlcyOdpG8dIE=
dependencies:
- effect
- exceptions
- foldable-traversable
- functions
- maybe
- prelude
web-storage:
type: registry
version: 5.0.0
integrity: sha256-q+6lxcnfWxus0/nDeFVtF1V+tLehZvvXQ0cduYPLksY=
dependencies:
- nullable
- web-events
web-streams:
type: registry
version: 3.0.0
integrity: sha256-+QELAR7lb08Ebr4lCntxeGk5Z1i+NInDJwzEzz3Pigc=
dependencies:
- arraybuffer-types
- effect
- exceptions
- nullable
- prelude
- tuples
- web-promise
web-xhr:
type: registry
version: 5.0.1
Expand Down
6 changes: 3 additions & 3 deletions spago.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package:
name: spago
publish:
version: 0.93.11
version: 0.93.13
license: BSD-3-Clause
location:
githubOwner: purescript
Expand Down Expand Up @@ -58,9 +58,9 @@ workspace:
extra_packages:
registry-lib:
git: https://github.com/purescript/registry-dev.git
ref: 7e1f67d1205d68d7f22d9d55d25ba2354dfbb14e
ref: 6a803c37577af368caa221a2a06d6be2079d32da
subdir: lib
registry-foreign:
git: https://github.com/purescript/registry-dev.git
ref: 7e1f67d1205d68d7f22d9d55d25ba2354dfbb14e
ref: 6a803c37577af368caa221a2a06d6be2079d32da
subdir: foreign
34 changes: 32 additions & 2 deletions src/Spago/Cmd.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ module Spago.Cmd where
import Spago.Prelude

import Data.Array as Array
import Data.Nullable (Nullable)
import Data.String (Pattern(..))
import Data.String as String
import Data.Time.Duration (Milliseconds(..))
import Node.Library.Execa as Execa
import Node.Platform as Platform
import Node.Process as Process
import Partial.Unsafe (unsafeCrashWith)
import Data.Time.Duration (Milliseconds(..))

data StdinConfig
= StdinPipeParent
Expand Down Expand Up @@ -97,3 +98,32 @@ findFlag { flags, args } = case Array.uncons args of
_ -> Nothing
_ -> Just h1
_ -> Nothing

getExecutable :: forall a. String -> Spago (LogEnv a) { cmd :: String, output :: String }
getExecutable command =
case Process.platform of
Just Platform.Win32 -> do
-- On Windows, we often need to call the `.cmd` version
let cmd1 = mkCmd command (Just "cmd")
askVersion cmd1 >>= case _ of
Right r -> pure { cmd: cmd1, output: r.stdout }
Left err' -> do
let cmd2 = mkCmd command Nothing
logDebug [ "Failed to find purs.cmd. Trying with just purs...", show err' ]
askVersion cmd2 >>= case _ of
Right r -> pure { cmd: cmd2, output: r.stdout }
Left err -> complain err
_ -> do
-- On other platforms, we just call `purs`
let cmd1 = mkCmd command Nothing
askVersion cmd1 >>= case _ of
Right r -> pure { cmd: cmd1, output: r.stdout }
Left err -> complain err
where
askVersion cmd = exec cmd [ "--version" ] defaultExecOptions { pipeStdout = false, pipeStderr = false }

mkCmd cmd maybeExtension = cmd <> maybe "" (append ".") maybeExtension

complain err = do
logDebug $ show err
die [ "Failed to find " <> command <> ". Have you installed it, and is it in your PATH?" ]
4 changes: 1 addition & 3 deletions src/Spago/Command/Bundle.purs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ run = do
Nothing -> "output"
Just o -> o
-- TODO: we might need to use `Path.relative selected.path output` instead of just output there
mainPath =
String.replaceAll (Pattern "\\") (Replacement "/") $
Path.concat [ output, opts.module, "index.js" ]
mainPath = withForwardSlashes $ Path.concat [ output, opts.module, "index.js" ]

{ input, entrypoint } = case opts.type of
BundleApp -> { entrypoint: [], input: Cmd.StdinWrite ("#!/usr/bin/env node\n\nimport { main } from './" <> mainPath <> "'; main();") }
Expand Down
12 changes: 7 additions & 5 deletions src/Spago/Command/Fetch.purs
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,23 @@ run { packages, ensureRanges } = do
case tarExists, tarIsGood of
true, true -> pure unit -- Tar exists and is good, and we already unpacked it. Happy days!
_, _ -> do
let packageUrl = "https://packages.registry.purescript.org/" <> PackageName.print name <> "/" <> versionString <> ".tar.gz"
logInfo $ "Fetching package " <> packageVersion
response <- liftAff $ Http.request
response <- liftAff $ withBackoff' $ Http.request
( Http.defaultRequest
{ method = Left Method.GET
, responseFormat = Response.arrayBuffer
, url = "https://packages.registry.purescript.org/" <> PackageName.print name <> "/" <> versionString <> ".tar.gz"
, url = packageUrl
}
)
case response of
Left err -> die $ "Couldn't fetch package " <> packageVersion <> ":\n " <> Http.printError err
Right { status, body } | status /= StatusCode 200 -> do
Nothing -> die $ "Couldn't reach the registry at " <> packageUrl
Just (Left err) -> die $ "Couldn't fetch package " <> packageVersion <> ":\n " <> Http.printError err
Just (Right { status, body }) | status /= StatusCode 200 -> do
(buf :: Buffer) <- liftEffect $ Buffer.fromArrayBuffer body
bodyString <- liftEffect $ Buffer.toString Encoding.UTF8 buf
die $ "Couldn't fetch package " <> packageVersion <> ", status was not ok " <> show status <> ", got answer:\n " <> bodyString
Right r@{ body: archiveArrayBuffer } -> do
Just (Right r@{ body: archiveArrayBuffer }) -> do
logDebug $ "Got status: " <> show r.status
-- check the size and hash of the tar against the metadata
archiveBuffer <- liftEffect $ Buffer.fromArrayBuffer archiveArrayBuffer
Expand Down
7 changes: 4 additions & 3 deletions src/Spago/Command/Init.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Spago.Command.Init
import Spago.Prelude

import Data.Map as Map
import Node.Path as Path
import Registry.PackageName as PackageName
import Registry.Version as Version
import Spago.Config (Dependencies(..), SetAddress(..), Config)
Expand Down Expand Up @@ -46,11 +47,11 @@ run opts = do
-- or just migrate a psc-package project
let mainModuleName = "Main"
whenDirNotExists "src" do
copyIfNotExists ("src/" <> mainModuleName <> ".purs") (srcMainTemplate mainModuleName)
copyIfNotExists ("src" <> Path.sep <> mainModuleName <> ".purs") (srcMainTemplate mainModuleName)

whenDirNotExists "test" $ do
FS.mkdirp "test/Test"
copyIfNotExists "test/Test/Main.purs" (testMainTemplate "Test.Main")
FS.mkdirp (Path.concat [ "test", "Test" ])
copyIfNotExists (Path.concat [ "test", "Test", "Main.purs" ]) (testMainTemplate "Test.Main")

copyIfNotExists ".gitignore" gitignoreTemplate

Expand Down
3 changes: 2 additions & 1 deletion src/Spago/Command/Publish.purs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ publish _args = do
, version: publishConfig.version
, license: publishConfig.license
, owners: Nothing -- TODO specify owners in spago config
, files: Nothing -- TODO specify files in spago config
, excludeFiles: Nothing -- TODO specify files in spago config
, includeFiles: Nothing -- TODO specify files in spago config
}

unless (Operation.Validation.locationMatches (Manifest manifest) (Metadata metadata)) $ addError $ toDoc
Expand Down
2 changes: 1 addition & 1 deletion src/Spago/Command/Run.purs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ run = do
nodeContents =
Array.fold
[ "import { main } from 'file://"
, String.replaceAll (Pattern "\\") (Replacement "/") opts.sourceDir
, withForwardSlashes opts.sourceDir
, "/"
, fromMaybe "output" workspace.buildOptions.output
, "/"
Expand Down
2 changes: 1 addition & 1 deletion src/Spago/Config.purs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ readWorkspace maybeSelectedPackage = do
| otherwise -> do
-- TODO: here figure out if the lockfile is still valid by checking if:
-- - the package set section of the workspace is the same
-- - the dependencies of each package are the same
-- - the dependencies of each package are the same
pure (UseLockfile contents)
false
-- If the user specifies lock: true then we always create a lockfile.
Expand Down
9 changes: 3 additions & 6 deletions src/Spago/Esbuild.purs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ type Esbuild =
}

getEsbuild :: forall a. Spago (LogEnv a) Esbuild
getEsbuild =
Cmd.exec "esbuild" [ "--version" ] Cmd.defaultExecOptions { pipeStdout = false, pipeStderr = false } >>= case _ of
Left err -> do
logDebug $ show err
die [ "Failed to find esbuild. See https://esbuild.github.io/getting-started/#install-esbuild for ways to install esbuild." ]
Right r -> pure { cmd: "esbuild", version: r.stdout }
getEsbuild = do
{ cmd, output } <- Cmd.getExecutable "esbuild"
pure { cmd, version: output }
5 changes: 5 additions & 0 deletions src/Spago/Prelude.purs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Spago.Prelude
, withBackoff'
, mkTemp
, mkTemp'
, withForwardSlashes
) where

import Spago.Core.Prelude
Expand All @@ -24,6 +25,7 @@ import Data.Foldable as Foldable
import Data.Function.Uncurried (Fn3, runFn3)
import Data.Int as Int
import Data.Maybe as Maybe
import Data.String (Pattern(..), Replacement(..))
import Data.String as String
import Effect.Aff as Aff
import Effect.Now as Now
Expand Down Expand Up @@ -148,3 +150,6 @@ mkTemp' maybeSuffix = liftAff do

mkTemp :: forall m. MonadAff m => m FilePath
mkTemp = mkTemp' Nothing

withForwardSlashes :: String -> String
withForwardSlashes = String.replaceAll (Pattern "\\") (Replacement "/")
Loading

0 comments on commit 2206c40

Please sign in to comment.