Skip to content

Commit

Permalink
Add purescript-psa to the supported tools (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomashoneyman authored Aug 13, 2020
1 parent e53c99c commit 32fa32c
Show file tree
Hide file tree
Showing 18 changed files with 264 additions and 203 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ jobs:
- name: Check tools are installed correctly
run: |
purty src/Main.purs
spago build --purs-args '--codegen corefn,js'
spago build --purs-args '--censor-lib --strict --codegen corefn,js'
zephyr -f Main.main
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ A GitHub Action which sets up a PureScript toolchain for CI. Contains the follow

- The [PureScript compiler](https://github.com/purescript/purescript)
- The [Spago package manager and build tool](https://github.com/purescript/spago)
- The [`psa` error reporting frontend for the compiler](https://github.com/natefaubion/purescript-psa)

You can also optionally include the following tools:

- The [Zephyr dead code elimination tool](https://github.com/coot/zephyr)
- The [Purty source code formatter](https://gitlab.com/joneshf/purty)

This action is designed to support tools with static binaries. Your PureScript project may also depend on tooling and libraries provided by the NPM ecosystem, in which case you will also want to use the [setup-node](https://github.com/actions/setup-node) action.
This action is designed to support PureScript tools. Your PureScript project may also depend on tooling and libraries provided by the NPM ecosystem, in which case you will also want to use the [setup-node](https://github.com/actions/setup-node) action.

## Usage

Expand Down Expand Up @@ -41,6 +42,7 @@ steps:
- uses: thomashoneyman/setup-purescript@main
with:
purescript: "0.13.8"
psa: "0.7.2"
spago: "0.15.3"
purty: "latest"
zephyr: "0.3.2"
Expand All @@ -61,7 +63,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: thomashoneyman/setup-purescript@main
- name: Cache PureScript dependencies
Expand Down Expand Up @@ -102,7 +104,7 @@ npm install
GitHub Actions uses the `action.yml` file to define the action and the `dist/index.js` file to execute it. After making any changes to the source code, make sure those changes are visible by running:

```sh
npm run package
npm run build
```

This will bundle and minify the source code so it is available to the end user.
Expand Down
7 changes: 5 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ inputs:
spago:
description: "The Spago version to install. Examples: latest, 0.15.3"
default: "latest"
psa:
description: "The psa version to install. Examples: latest, 0.7.2"
default: "latest"
purty:
description: "The Purty version to install. Examples: latest, 6.2.0"
zephyr:
Expand All @@ -16,5 +19,5 @@ runs:
using: "node12"
main: "dist/index.js"
branding:
icon: 'download'
color: 'gray-dark'
icon: "download"
color: "gray-dark"
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/update.js

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion dist/versions.json
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
{"purs":"0.13.8","spago":"0.15.3","purty":"6.2.0","zephyr":"0.3.2"}
{
"purs": "0.13.8",
"spago": "0.15.3",
"psa": "0.7.3",
"purty": "6.2.0",
"zephyr": "0.3.2"
}
23 changes: 10 additions & 13 deletions package-lock.json

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

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
"description": "Set up a PureScript toolchain in GitHub Actions",
"author": "Thomas Honeyman",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/thomashoneyman/setup-purescript.git"
},
"scripts": {
"package": "spago bundle-module --to output/index.js && ncc build --minify update.js && mv dist/index.js dist/update.js && ncc build --minify index.js"
"build": "spago bundle-module --to output/index.js && ncc build --minify update.js && mv dist/index.js dist/update.js && ncc build --minify index.js"
},
"dependencies": {
"@actions/core": "^1.2.4",
"@actions/exec": "^1.0.4",
"@actions/tool-cache": "^1.6.0",
"xhr2": "^0.2.0"
},
"devDependencies": {
"@zeit/ncc": "^0.22.3"
"@vercel/ncc": "^0.23.0"
}
}
3 changes: 3 additions & 0 deletions src/Actions/Exec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const exec = require("@actions/exec");

exports.execImpl = exec.exec;
20 changes: 20 additions & 0 deletions src/Actions/Exec.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- | Exports functions from the @actions/exec module provided by GitHub
-- | https://github.com/actions/toolkit/tree/main/packages/exec
module Actions.Exec
( exec
) where

import Prelude

import Control.Promise (Promise, toAffE)
import Effect.Aff (Aff)
import Effect.Uncurried (EffectFn2, runEffectFn2)

foreign import execImpl :: EffectFn2 String (Array String) (Promise Number)

-- | Executes a command on the command line, with arguments
exec :: String -> Array String -> Aff { succeeded :: Boolean }
exec command args =
map ((_ == 0.0) >>> { succeeded: _ })
$ toAffE
$ runEffectFn2 execImpl command args
10 changes: 5 additions & 5 deletions src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import Data.Foldable (traverse_)
import Effect (Effect)
import Effect.Aff (launchAff_)
import Setup.BuildPlan (constructBuildPlan)
import Setup.Download (download)
import Setup.GetTool (getTool)
import Setup.UpdateVersions (updateVersions)

main :: Json -> Effect Unit
main json = do
plan <- constructBuildPlan json
launchAff_ $ traverse_ download plan
main json = do
tools <- constructBuildPlan json
launchAff_ $ traverse_ getTool tools

update :: Effect Unit
update = launchAff_ updateVersions
update = launchAff_ updateVersions
9 changes: 4 additions & 5 deletions src/Setup/BuildPlan.purs
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,24 @@ resolve versionsContents tool = do
Nothing | required tool -> throwError $ error "No input received for required key."
Nothing -> pure Nothing
Just field -> map Just $ getVersion field

where
getVersion :: Either String VersionField -> Effect { tool :: Tool, version :: Version }
getVersion = case _ of
Left err -> do
Core.setFailed $ fold [ "Unable to parse version: ", err ]
throwError $ error "Unable to complete fetching version."

Right (Exact v) -> do
Core.info "Found exact version"
pure { tool, version: v }

Right Latest -> do
Core.info $ fold [ "Fetching latest tag for ", Tool.name tool ]

let
let
version = lmap printJsonDecodeError $ (_ .: Tool.name tool) =<< decodeJson versionsContents
parse = lmap parseErrorMessage <<< Version.parseVersion
parse = lmap parseErrorMessage <<< Version.parseVersion

case parse =<< version of
Left e -> do
Expand All @@ -75,4 +75,3 @@ resolve versionsContents tool = do

Right v ->
pure { tool, version: v }

6 changes: 5 additions & 1 deletion src/Setup/Data/Key.purs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Setup.Data.Key
module Setup.Data.Key
( Key
, fromTool
) where
Expand All @@ -13,6 +13,9 @@ purescriptKey = Key "purescript"
spagoKey :: Key
spagoKey = Key "spago"

psaKey :: Key
psaKey = Key "psa"

purtyKey :: Key
purtyKey = Key "purty"

Expand All @@ -23,5 +26,6 @@ fromTool :: Tool -> Key
fromTool = case _ of
PureScript -> purescriptKey
Spago -> spagoKey
Psa -> psaKey
Purty -> purtyKey
Zephyr -> zephyrKey
Loading

0 comments on commit 32fa32c

Please sign in to comment.