Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI #20

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/bundle.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Bundle

on:
# Run when a release is published
release:
types:
- published

jobs:
bundle:
name: Bundle
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Check out the repository
uses: actions/checkout@v3
- name: Install Roc
uses: hasnep/setup-roc@main
with:
roc-version: nightly
- name: Bundle and release the library
uses: hasnep/[email protected]
with:
library: package/main.roc
token: ${{ github.token }}
33 changes: 33 additions & 0 deletions .github/workflows/generate-docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Generate docs

on:
# Run when a release is published
release:
types:
- published

jobs:
generate-docs:
name: Generate docs
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
steps:
- name: Check out the repository
uses: actions/checkout@v3
- name: Install Roc
uses: hasnep/setup-roc@main
with:
roc-version: nightly
- name: Generate docs
run: roc docs package/main.roc
- name: Fix absolute paths
run: |
find generated-docs/ -type f -name '*.html' -exec sed -i "s/\(href\|src\)=\"\//\1=\"\/${{ github.event.repository.name }}\//g" {} +
- name: Upload docs artifact
uses: actions/upload-pages-artifact@v1
with:
path: generated-docs
- name: Deploy docs
uses: actions/deploy-pages@v2
21 changes: 0 additions & 21 deletions .github/workflows/gh_pages.yaml

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
on:
pull_request:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test-examples:
runs-on: ubuntu-latest
env:
ROC_VERSION: nightly
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install ROC
run: |
# Install ROC
curl -fOL https://github.com/roc-lang/roc/releases/download/${ROC_VERSION}/roc_nightly-linux_x86_64-latest.tar.gz
mv $(ls | grep "roc_nightly.*tar\.gz") roc_nightly.tar.gz
tar -xzf roc_nightly.tar.gz
rm roc_nightly.tar.gz
mv roc_nightly* roc_nightly

- name: Check ROC version
run: ./roc_nightly/roc version

- name: Run all tests
run: ROC=./roc_nightly/roc ./ci/all_tests.sh
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ generated-docs/
*.ll

# Compiled executables
example_complex
example_digits
example_simple
examples/complex
examples/digits
examples/simple

# macOS noise
.DS_Store
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

24 changes: 8 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ A [Roc](https://github.com/roc-lang/roc) library for random number generation

## Status

This works, but there's much more it could do.
Forked from [JanCVanB/roc-random](https://github.com/JanCVanB/roc-random), updated to build package and documentation, and do some maintenance.

Contributions & feedback are very welcome! :)
This works, but there's much more it could do. Contributions & feedback are very welcome!

## Examples

```coffee
```roc
# Print a list of 10 random numbers in the range 25-75 inclusive.
main =

Expand All @@ -37,20 +37,16 @@ main =
|> List.map Num.toStr
|> Str.joinWith ","

Stdout.line "Random numbers are: \(numbersListStr)"
Stdout.line! "Random numbers are: \(numbersListStr)"
```

See the `examples/*.roc` files for more examples.

## Documentation

See [the library documentation site](https://JanCVanB.github.io/roc-random)
See [the library documentation site](https://lukewilliamboswell.github.io/roc-parser/)
for more info about its API.

However,
[the single library file itself](Random.roc)
should be self-documenting.

## Goals

* An external API that is similar to that of
Expand All @@ -63,10 +59,6 @@ should be self-documenting.

## Seeding

In order to receive a different sequence of outputs from this library
between executions of your application,
your Roc platform of choice must provide
a random/pseudorandom/varying seed.
Otherwise, your pure functions will be responsible
for providing `Random`'s pure functions with a constant seed
that will merely choose which predictable sequence you'll receive.
In order to receive a different sequence of outputs from this library between executions of your application, your Roc platform of choice must provide a random/pseudorandom/varying seed.

Otherwise, your pure functions will be responsible for providing `Random`'s pure functions with a constant seed that will merely choose which predictable sequence you'll receive.
28 changes: 28 additions & 0 deletions ci/all_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

# https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
set -euxo pipefail

if [ -z "${ROC:-}" ]; then
echo "INFO: The ROC environment variable is not set."
export ROC=$(which roc)
fi

EXAMPLES_DIR='./examples'
PACKAGE_DIR='./package'

# List of files to ignore
IGNORED_FILES=("xx.roc")

# roc check examples
for ROC_FILE in $EXAMPLES_DIR/*.roc; do
if [[ " ${IGNORED_FILES[*]} " != *" ${ROC_FILE##*/} "* ]]; then
$ROC check $ROC_FILE
fi
done

# roc test package
$ROC test $PACKAGE_DIR/main.roc

# test building docs website
$ROC docs $PACKAGE_DIR/main.roc
62 changes: 26 additions & 36 deletions examples/complex.roc
Original file line number Diff line number Diff line change
@@ -1,46 +1,36 @@
# !/usr/bin/env roc
app "example_complex"
packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.3.1/97mY3sUwo433-pcnEQUlMhn-sWiIf_J9bPhcAFZoqY4.tar.br" }
imports [
pf.Stdout.{ line },
pf.Task.{ await },
Random,
]
provides [main] to pf
app [main] {
cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.15.0/SlwdbJ-3GR7uBWQo6zlmYWNYOxnvo8r6YABXD-45UOw.tar.br",
rand: "../package/main.roc",
}

import cli.Stdout
import rand.Random

main =
a = point (Random.seed 36)
b = a |> Random.next point

_ <- await (line (Num.toStr a.value.x |> \s -> "a.x == -59 == \(s)"))
_ <- await (line (Num.toStr a.value.y |> \s -> "a.y == -62 == \(s)"))
_ <- await (line (Num.toStr a.value.z |> \s -> "a.z == -64 == \(s)"))
_ <- await (line (Num.toStr a.value.t |> \s -> "a.t == 4 == \(s)"))
_ <- await (line (Num.toStr b.value.x |> \s -> "b.x == 82 == \(s)"))
_ <- await (line (Num.toStr b.value.y |> \s -> "b.y == 78 == \(s)"))
_ <- await (line (Num.toStr b.value.z |> \s -> "b.z == -64 == \(s)"))
_ <- await (line (Num.toStr b.value.t |> \s -> "b.t == -20 == \(s)"))

line "These values will be the same on every run, because we use a constant seed."
Stdout.line! (Num.toStr a.value.x |> \s -> "a.x == -59 == $(s)")
Stdout.line! (Num.toStr a.value.y |> \s -> "a.y == -62 == $(s)")
Stdout.line! (Num.toStr a.value.z |> \s -> "a.z == -64 == $(s)")
Stdout.line! (Num.toStr a.value.t |> \s -> "a.t == 4 == $(s)")
Stdout.line! (Num.toStr b.value.x |> \s -> "b.x == 82 == $(s)")
Stdout.line! (Num.toStr b.value.y |> \s -> "b.y == 78 == $(s)")
Stdout.line! (Num.toStr b.value.z |> \s -> "b.z == -64 == $(s)")
Stdout.line! (Num.toStr b.value.t |> \s -> "b.t == -20 == $(s)")
Stdout.line! "These values will be the same on every run, because we use a constant seed."

# Complex `Generator`s can be created by chaining primitive `Generator`s.
# Point a : { x : a, y : a, z : a, t : a }
Point : { t : I32, x : I32, y : I32, z : I32 }

# TODO fix this type annotation
# point : Random.Generator (Point I32) (Random.State U32)
point = \state ->
point : Random.Generator U32 Point
point =
min = -100
max = 100
# Primitive generator constructors are included in `Random`.
i = Random.int min max
# The initial seed is used to generate the first generation.
x = Random.step state i
# The updated seed is passed forward to generate the next generation.
y = Random.step x.state i
# `Random.next` is just a convenience method for passing a seed (equivalent to `Random.step y.seed i`).
z = Random.next y i
# `Random.next` pairs nicely with the pipe operator (equivalent to `Random.step z.seed i`).
t = z |> Random.next i
boundedInt = Random.int min max

# Return a record with `.seed` and `.value` for compatibility.
{ value: { x: x.value, y: y.value, z: z.value, t: t.value }, state: t.state }
{ Random.chain <-
x: boundedInt,
y: boundedInt,
z: boundedInt,
t: boundedInt,
}
56 changes: 29 additions & 27 deletions examples/digits.roc
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# !/usr/bin/env roc
app "example_digits"
packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.3.1/97mY3sUwo433-pcnEQUlMhn-sWiIf_J9bPhcAFZoqY4.tar.br" }
imports [pf.Stdout.{ line }, pf.Task.{ await }, Random]
provides [main] to pf
#!/usr/bin/env roc
app [main] {
cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.15.0/SlwdbJ-3GR7uBWQo6zlmYWNYOxnvo8r6YABXD-45UOw.tar.br",
rand: "../package/main.roc",
}

import cli.Stdout
import rand.Random

main =

Expand Down Expand Up @@ -35,25 +38,24 @@ main =

s = q |> Random.next (Random.u8 0 9)
t = r |> Random.next (Random.u8 0 9)

_ <- await (line (Num.toStr a.value |> \x -> "a == 9 == \(x)"))
_ <- await (line (Num.toStr b.value |> \x -> "b == 9 == \(x)"))
_ <- await (line (Num.toStr c.value |> \x -> "c == 9 == \(x)"))
_ <- await (line (Num.toStr d.value |> \x -> "d == 9 == \(x)"))
_ <- await (line (Num.toStr e.value |> \x -> "e == 6 == \(x)"))
_ <- await (line (Num.toStr f.value |> \x -> "f == 6 == \(x)"))
_ <- await (line (Num.toStr g.value |> \x -> "g == 2 == \(x)"))
_ <- await (line (Num.toStr h.value |> \x -> "h == 2 == \(x)"))
_ <- await (line (Num.toStr i.value |> \x -> "i == 2 == \(x)"))
_ <- await (line (Num.toStr j.value |> \x -> "j == 2 == \(x)"))
_ <- await (line (Num.toStr k.value |> \x -> "k == 6 == \(x)"))
_ <- await (line (Num.toStr l.value |> \x -> "l == 6 == \(x)"))
_ <- await (line (Num.toStr m.value |> \x -> "m == 3 == \(x)"))
_ <- await (line (Num.toStr n.value |> \x -> "n == 3 == \(x)"))
_ <- await (line (Num.toStr o.value |> \x -> "o == 7 == \(x)"))
_ <- await (line (Num.toStr p.value |> \x -> "p == 7 == \(x)"))
_ <- await (line (Num.toStr q.value |> \x -> "q == 3 == \(x)"))
_ <- await (line (Num.toStr r.value |> \x -> "r == 3 == \(x)"))
_ <- await (line (Num.toStr s.value |> \x -> "s == 0 == \(x)"))
_ <- await (line (Num.toStr t.value |> \x -> "t == 5 == \(x)"))
line "These values will be the same on every run, because we use constant seeds."
Stdout.line! (Num.toStr a.value |> \x -> "a == 9 == $(x)")
Stdout.line! (Num.toStr b.value |> \x -> "b == 9 == $(x)")
Stdout.line! (Num.toStr c.value |> \x -> "c == 9 == $(x)")
Stdout.line! (Num.toStr d.value |> \x -> "d == 9 == $(x)")
Stdout.line! (Num.toStr e.value |> \x -> "e == 6 == $(x)")
Stdout.line! (Num.toStr f.value |> \x -> "f == 6 == $(x)")
Stdout.line! (Num.toStr g.value |> \x -> "g == 2 == $(x)")
Stdout.line! (Num.toStr h.value |> \x -> "h == 2 == $(x)")
Stdout.line! (Num.toStr i.value |> \x -> "i == 2 == $(x)")
Stdout.line! (Num.toStr j.value |> \x -> "j == 2 == $(x)")
Stdout.line! (Num.toStr k.value |> \x -> "k == 6 == $(x)")
Stdout.line! (Num.toStr l.value |> \x -> "l == 6 == $(x)")
Stdout.line! (Num.toStr m.value |> \x -> "m == 3 == $(x)")
Stdout.line! (Num.toStr n.value |> \x -> "n == 3 == $(x)")
Stdout.line! (Num.toStr o.value |> \x -> "o == 7 == $(x)")
Stdout.line! (Num.toStr p.value |> \x -> "p == 7 == $(x)")
Stdout.line! (Num.toStr q.value |> \x -> "q == 3 == $(x)")
Stdout.line! (Num.toStr r.value |> \x -> "r == 3 == $(x)")
Stdout.line! (Num.toStr s.value |> \x -> "s == 0 == $(x)")
Stdout.line! (Num.toStr t.value |> \x -> "t == 5 == $(x)")
Stdout.line! "These values will be the same on every run, because we use constant seeds."
Loading
Loading