Skip to content

Commit 9013534

Browse files
committed
Add files
1 parent e5ee316 commit 9013534

File tree

15 files changed

+324
-0
lines changed

15 files changed

+324
-0
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.git/
2+
bin/
3+
examples/
4+
README.md

.github/workflows/ci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
if: ${{ github.repository == 'codewars/purescript' }}
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: docker/setup-buildx-action@v2
15+
16+
- name: Build image
17+
uses: docker/build-push-action@v3
18+
with:
19+
context: .
20+
push: false
21+
# Make the image available in next step
22+
load: true
23+
tags: ghcr.io/codewars/purescript:latest
24+
cache-from: type=gha
25+
cache-to: type=gha,mode=max
26+
27+
- name: Run Passing Example
28+
run: bin/run passing
29+
30+
- name: Report Image Size
31+
run: |
32+
echo "## Image Size" >> $GITHUB_STEP_SUMMARY
33+
docker image inspect --format '{{.Size}}' ghcr.io/codewars/purescript:latest | numfmt --to=si --suffix=B >> $GITHUB_STEP_SUMMARY

.github/workflows/push-image.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Build and push a Docker image to GitHub Container Registry when
2+
# a new tag is pushed.
3+
name: Push Image
4+
5+
on:
6+
push:
7+
tags:
8+
- "*"
9+
10+
jobs:
11+
build-and-push-image:
12+
if: ${{ github.repository == 'codewars/purescript' }}
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
packages: write
17+
steps:
18+
- uses: actions/checkout@v2
19+
20+
- name: Set up Docker Buildx
21+
uses: docker/setup-buildx-action@v2
22+
23+
- name: Login to GitHub Container Registry
24+
uses: docker/login-action@v2
25+
with:
26+
registry: ghcr.io
27+
username: codewars
28+
password: ${{ secrets.GITHUB_TOKEN }}
29+
30+
- name: Build and push image
31+
uses: docker/build-push-action@v3
32+
with:
33+
context: .
34+
push: true
35+
tags: |
36+
ghcr.io/codewars/purescript:latest
37+
ghcr.io/codewars/purescript:${{ github.ref_name }}
38+
cache-from: type=gha
39+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
FROM buildpack-deps:bionic
2+
3+
RUN set -ex; \
4+
useradd --create-home codewarrior; \
5+
ln -s /home/codewarrior /workspace;
6+
7+
RUN set -ex; \
8+
curl -sL https://deb.nodesource.com/setup_8.x | bash -; \
9+
apt-get install -y nodejs; \
10+
apt-get clean; \
11+
rm -rf /var/lib/apt/lists/* /tmp/*;
12+
13+
RUN set -ex; \
14+
mkdir -p /opt/purescript; \
15+
curl -fsSL https://github.com/purescript/purescript/releases/download/v0.12.2/linux64.tar.gz | tar xz -C /opt/purescript --strip-components=1; \
16+
curl -fsSL https://github.com/purescript/psc-package/releases/download/v0.5.1/linux64.tar.gz | tar xz -C /opt/purescript --strip-components=1;
17+
18+
RUN npm install -g pulp@12.3.1;
19+
20+
COPY --chown=codewarrior:codewarrior workspace/ /workspace
21+
WORKDIR /workspace
22+
23+
USER codewarrior
24+
25+
ENV USER=codewarrior \
26+
HOME=/home/codewarrior \
27+
PATH=/opt/purescript:$PATH
28+
29+
RUN set -ex; \
30+
cd /workspace; \
31+
npm install; \
32+
# install packages
33+
psc-package install; \
34+
# compile packages
35+
psc-package build; \
36+
# ensure running `Main.purs` works
37+
pulp run; \
38+
# ensure testing works
39+
pulp test || true; \
40+
# clean up
41+
rm -rf ./src/Main.purs ./output/Main/ ./test/Example/ ./output/Example.ExampleSpec/;

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# purescript
2+
3+
Container image for PureScript
4+
5+
## Usage
6+
7+
```bash
8+
W=/workspace
9+
# Create container
10+
C=$(docker container create --rm -w $W ghcr.io/codewars/purescript:latest pulp test)
11+
12+
# Copy files from the examples directory
13+
docker container cp ./examples/passing/. $C:$W
14+
15+
# Start
16+
docker container start --attach $C
17+
```
18+
19+
## Building
20+
21+
```bash
22+
docker build -t ghcr.io/codewars/purescript:latest .
23+
```

bin/run

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
set -eu
3+
4+
if [ -z "${IMAGE:+x}" ]; then
5+
IMAGE=ghcr.io/codewars/purescript:latest
6+
fi
7+
8+
W=/workspace
9+
10+
# Create container
11+
C=$(docker container create --rm -w $W $IMAGE pulp test)
12+
13+
# Copy files from the examples directory
14+
docker container cp examples/${1:-passing}/. $C:$W
15+
16+
# Run tests
17+
docker container start --attach $C

examples/passing/src/Example.purs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Example where
2+
import Prelude
3+
4+
add' :: Int -> Int -> Int
5+
add' a b = a + b
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module ExampleSpec where
2+
3+
import Prelude
4+
import Example (add')
5+
6+
import Test.Spec (Spec, describe, it)
7+
import Test.Spec.Assertions (shouldEqual)
8+
9+
spec :: Spec Unit
10+
spec =
11+
describe "Example" do
12+
describe "add" do
13+
it "returns sum" do
14+
let sum = add' 1 1
15+
sum `shouldEqual` 2

workspace/package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

workspace/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "cw-purescript",
3+
"version": "0.0.1",
4+
"description": "",
5+
"dependencies": {
6+
"big-integer": "^1.6.41"
7+
}
8+
}

0 commit comments

Comments
 (0)