-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
324 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.git/ | ||
bin/ | ||
examples/ | ||
README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
if: ${{ github.repository == 'codewars/purescript' }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Build image | ||
uses: docker/build-push-action@v3 | ||
with: | ||
context: . | ||
push: false | ||
# Make the image available in next step | ||
load: true | ||
tags: ghcr.io/codewars/purescript:latest | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
|
||
- name: Run Passing Example | ||
run: bin/run passing | ||
|
||
- name: Report Image Size | ||
run: | | ||
echo "## Image Size" >> $GITHUB_STEP_SUMMARY | ||
docker image inspect --format '{{.Size}}' ghcr.io/codewars/purescript:latest | numfmt --to=si --suffix=B >> $GITHUB_STEP_SUMMARY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Build and push a Docker image to GitHub Container Registry when | ||
# a new tag is pushed. | ||
name: Push Image | ||
|
||
on: | ||
push: | ||
tags: | ||
- "*" | ||
|
||
jobs: | ||
build-and-push-image: | ||
if: ${{ github.repository == 'codewars/purescript' }} | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: codewars | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build and push image | ||
uses: docker/build-push-action@v3 | ||
with: | ||
context: . | ||
push: true | ||
tags: | | ||
ghcr.io/codewars/purescript:latest | ||
ghcr.io/codewars/purescript:${{ github.ref_name }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
FROM buildpack-deps:bionic | ||
|
||
RUN set -ex; \ | ||
useradd --create-home codewarrior; \ | ||
ln -s /home/codewarrior /workspace; | ||
|
||
RUN set -ex; \ | ||
curl -sL https://deb.nodesource.com/setup_8.x | bash -; \ | ||
apt-get install -y nodejs; \ | ||
apt-get clean; \ | ||
rm -rf /var/lib/apt/lists/* /tmp/*; | ||
|
||
RUN set -ex; \ | ||
mkdir -p /opt/purescript; \ | ||
curl -fsSL https://github.com/purescript/purescript/releases/download/v0.12.2/linux64.tar.gz | tar xz -C /opt/purescript --strip-components=1; \ | ||
curl -fsSL https://github.com/purescript/psc-package/releases/download/v0.5.1/linux64.tar.gz | tar xz -C /opt/purescript --strip-components=1; | ||
|
||
RUN npm install -g pulp@12.3.1; | ||
|
||
COPY --chown=codewarrior:codewarrior workspace/ /workspace | ||
WORKDIR /workspace | ||
|
||
USER codewarrior | ||
|
||
ENV USER=codewarrior \ | ||
HOME=/home/codewarrior \ | ||
PATH=/opt/purescript:$PATH | ||
|
||
RUN set -ex; \ | ||
cd /workspace; \ | ||
npm install; \ | ||
# install packages | ||
psc-package install; \ | ||
# compile packages | ||
psc-package build; \ | ||
# ensure running `Main.purs` works | ||
pulp run; \ | ||
# ensure testing works | ||
pulp test || true; \ | ||
# clean up | ||
rm -rf ./src/Main.purs ./output/Main/ ./test/Example/ ./output/Example.ExampleSpec/; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# purescript | ||
|
||
Container image for PureScript | ||
|
||
## Usage | ||
|
||
```bash | ||
W=/workspace | ||
# Create container | ||
C=$(docker container create --rm -w $W ghcr.io/codewars/purescript:latest pulp test) | ||
|
||
# Copy files from the examples directory | ||
docker container cp ./examples/passing/. $C:$W | ||
|
||
# Start | ||
docker container start --attach $C | ||
``` | ||
|
||
## Building | ||
|
||
```bash | ||
docker build -t ghcr.io/codewars/purescript:latest . | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
set -eu | ||
|
||
if [ -z "${IMAGE:+x}" ]; then | ||
IMAGE=ghcr.io/codewars/purescript:latest | ||
fi | ||
|
||
W=/workspace | ||
|
||
# Create container | ||
C=$(docker container create --rm -w $W $IMAGE pulp test) | ||
|
||
# Copy files from the examples directory | ||
docker container cp examples/${1:-passing}/. $C:$W | ||
|
||
# Run tests | ||
docker container start --attach $C |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Example where | ||
import Prelude | ||
|
||
add' :: Int -> Int -> Int | ||
add' a b = a + b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module ExampleSpec where | ||
|
||
import Prelude | ||
import Example (add') | ||
|
||
import Test.Spec (Spec, describe, it) | ||
import Test.Spec.Assertions (shouldEqual) | ||
|
||
spec :: Spec Unit | ||
spec = | ||
describe "Example" do | ||
describe "add" do | ||
it "returns sum" do | ||
let sum = add' 1 1 | ||
sum `shouldEqual` 2 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "cw-purescript", | ||
"version": "0.0.1", | ||
"description": "", | ||
"dependencies": { | ||
"big-integer": "^1.6.41" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "cw-purescript", | ||
"set": "psc-0.12.2-20190119", | ||
"source": "https://github.com/purescript/package-sets.git", | ||
"depends": [ | ||
"prelude", | ||
"console", | ||
"debug", | ||
"effect", | ||
"bigints", | ||
"rationals", | ||
"profunctor-lenses", | ||
"spec", | ||
"spec-discovery", | ||
"spec-quickcheck" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Main where | ||
|
||
import Prelude | ||
import Effect (Effect) | ||
import Effect.Console (log) | ||
|
||
main :: Effect Unit | ||
main = do | ||
log "Hello World!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module Test.Spec.Reporter.Codewars (codewarsReporter) where | ||
|
||
import Prelude | ||
|
||
import Data.Maybe (Maybe(..)) | ||
import Data.String | ||
( Pattern(Pattern) | ||
, Replacement(Replacement) | ||
, replaceAll | ||
) | ||
import Effect.Console (log) | ||
|
||
import Test.Spec.Reporter.Base (defaultReporter) | ||
import Test.Spec.Runner (Reporter) | ||
import Test.Spec.Runner.Event as Event | ||
|
||
|
||
codewarsReporter :: Reporter | ||
codewarsReporter = defaultReporter {} update | ||
where | ||
update s = case _ of | ||
Event.Start _ -> pure s | ||
Event.End _ -> pure s | ||
Event.Suite name -> s <$ log ("\n<DESCRIBE::>" <> name) | ||
Event.SuiteEnd -> s <$ log "\n<COMPLETEDIN::>" | ||
|
||
Event.Pending name -> s <$ do | ||
log $ "\n<IT::>" <> name | ||
log $ "\n<LOG::>Pending Test" | ||
log $ "\n<COMPLETEDIN::>" | ||
|
||
Event.Pass name _ ms -> s <$ do | ||
log $ "\n<IT::>" <> name | ||
log $ "\n<PASSED::>Test Passed" | ||
log $ "\n<COMPLETEDIN::>" <> (show ms) | ||
|
||
Event.Fail name msg mStack -> s <$ do | ||
log $ "\n<IT::>" <> name | ||
log $ "\n<FAILED::>Test Failed<:LF:>" <> (escapeLF msg) | ||
case mStack of | ||
Nothing -> pure unit | ||
Just k -> log $ "\n<LOG::-Stack Trace>" <> (escapeLF k) | ||
log $ "\n<COMPLETEDIN::>" | ||
|
||
_ -> pure s | ||
|
||
|
||
escapeLF :: String -> String | ||
escapeLF = replaceAll (Pattern "\n") (Replacement "<:LF:>") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Example.ExampleSpec where | ||
|
||
import Prelude | ||
import Effect.Aff (delay) | ||
import Data.Time.Duration (Milliseconds(..)) | ||
|
||
import Test.QuickCheck ((===), (/==)) | ||
import Test.Spec (Spec, describe, it) | ||
import Test.Spec.Assertions (shouldEqual) | ||
import Test.Spec.QuickCheck (quickCheck) | ||
|
||
-- example from README plus basic sanity checks | ||
spec :: Spec Unit | ||
spec = | ||
describe "purescript-spec" do | ||
describe "Attributes" do | ||
it "awesome" do | ||
let isAwesome = true | ||
isAwesome `shouldEqual` true | ||
|
||
describe "Features" do | ||
it "runs in NodeJS" $ pure unit | ||
it "runs in the browser" $ pure unit | ||
it "supports async specs" do | ||
res <- delay (Milliseconds 100.0) *> pure "Alligator" | ||
res `shouldEqual` "Alligator" | ||
|
||
describe "QuickCheck" do | ||
it "works" $ | ||
quickCheck \n -> (n * 2 / 2) === n | ||
it "works again" $ | ||
quickCheck \n -> ((n + 1) * 2) /== n | ||
|
||
describe "Failure example" do | ||
it "should fail" do | ||
1 `shouldEqual` 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Test.Main where | ||
|
||
import Prelude | ||
import Data.Maybe (Maybe(..)) | ||
import Effect (Effect) | ||
|
||
import Test.Spec.Discovery (discover) | ||
import Test.Spec.Runner (defaultConfig, run') | ||
|
||
import Test.Spec.Reporter.Codewars (codewarsReporter) | ||
|
||
main :: Effect Unit | ||
main = discover ".+Spec" >>= run' config [codewarsReporter] | ||
where | ||
config = defaultConfig { timeout = Just 12000 } |