Skip to content

Commit

Permalink
Merge pull request #8 from juancarlospaco/ci2
Browse files Browse the repository at this point in the history
Optimize CI 2
  • Loading branch information
juancarlospaco committed Jan 15, 2022
2 parents 76ec1f0 + 8ae4295 commit e20b37b
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 42 deletions.
35 changes: 28 additions & 7 deletions .github/workflows/build.yml
Expand Up @@ -24,36 +24,57 @@ jobs:
steps:
- uses: actions/checkout@v2


- uses: jiro4989/setup-nim-action@v1
with:
nim-version: ${{ matrix.nim-channel }}
no-color: true # --noColor


- name: Setup NodeJS ${{ matrix.node }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}


- uses: pre-commit/action@v2.0.3
if: runner.os == 'Linux'

# - uses: juancarlospaco/nimpretty-action@main
# with:
# folders: "src"


- name: Set Environment Variables
uses: allenevans/set-env@v2.0.0
with:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
NODE_OPTIONS: "--unhandled-rejections=warn"
CMD: "nim doc -b:js -d:nodejs -d:nimExperimentalAsyncjsThen -d:nimStrictDelete -d:nimPreviewFloatRoundtrip -d:nimPreviewDotLikeOps --experimental:strictFuncs --experimental:strictEffects --index:on --project --styleCheck:usages --styleCheck:hint --outdir:../../docs"


# https://developer.ibm.com/languages/node-js/blogs/nodejs-15-release-blog
- name: Generate Documentation (Linux)
if: runner.os == 'Linux'
- name: Generate Documentation
shell: bash
run: |
cd src/nodejs/
for i in *.nim; do
$CMD $i
done
- name: Clean out
shell: bash
run: |
export NODE_OPTIONS=--unhandled-rejections=warn
nim doc -b:js -d:nodejs -d:nimExperimentalAsyncjsThen --git.url:'https://github.com/juancarlospaco/nodejs' --index:on --project --experimental:strictFuncs --styleCheck:hint --outdir:docs src/nodejs.nim
rm --verbose docs/nodejs/*.idx
rm --verbose --force --recursive docs/*.idx
rm --verbose --force --recursive docs/nimcache/*.*
rm --verbose --force --recursive docs/nimcache/runnableExamples/*.*
mv --verbose docs/nodejs.html docs/index.html
- name: Commit Docs
if: github.ref == 'refs/heads/main'
if: |
github.event_name == 'push' && github.ref == 'refs/heads/main' && runner.os == 'Linux' &&
matrix.platform == 'ubuntu-latest' && matrix.architecture == 'x64' && matrix.node == '17'
uses: EndBug/add-and-commit@v4 # Commit everything to Git repo
with:
add: 'docs'
Expand Down
2 changes: 1 addition & 1 deletion src/nodejs/jsclasses.nim
Expand Up @@ -260,7 +260,7 @@ class $1 {


# when isMainModule:
runnableExamples"-b:js -d:nodejs --experimental:strictFuncs":
runnableExamples"-b:js -d:nodejs --experimental:strictFuncs -r:off":


class Kitten* of JsRoot:
Expand Down
6 changes: 3 additions & 3 deletions src/nodejs/jscore.nim
Expand Up @@ -119,14 +119,14 @@ func indentation*(s: cstring): cint {.importjs: """
})()""".}
## Returns the amount of indentation all lines of `s` have in common, ignoring lines that consist only of whitespace.

proc `[]`*(s: cstring; slice: HSlice[SomeInteger, SomeInteger]): cstring {.asmnostackframe.} =
proc `[]`*(s: cstring; slice: HSlice[SomeInteger, SomeInteger]): cstring {.asmNoStackFrame.} =
let start {.codegenDecl: "const $2".} = slice.a.int
let ends {.codegenDecl: "const $2".} = slice.b.int + 1
assert start >= 0, "Index out of bounds: " & $start
assert ends > s.len, "Index out of bounds: " & $ends
asm "return `s`.slice(`start`, `ends`);"

proc `[]`*(s: cstring; slice: HSlice[SomeInteger, BackwardsIndex]): cstring {.asmnostackframe.} =
proc `[]`*(s: cstring; slice: HSlice[SomeInteger, BackwardsIndex]): cstring {.asmNoStackFrame.} =
let start {.codegenDecl: "const $2".} = slice.a.int
let ends {.codegenDecl: "const $2".} = s.len - slice.b.int + 1
assert start >= 0, "Index out of bounds: " & $start
Expand Down Expand Up @@ -166,7 +166,7 @@ func structuredClone*(value, transfer: auto) {.importjs: "$1(#, #)".}
func structuredClone*(value: auto) {.importjs: "$1(#)".}
## https://developer.mozilla.org/en-US/docs/Web/API/structuredClone

func parseBool*(s: cstring): bool {.asmnostackframe.} = {.emit: """
func parseBool*(s: cstring): bool {.asmNoStackFrame.} = {.emit: """
const value = String(`s`).trim();
if (/^(?:y|1|on|yes|true)$/i.test(value)) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/nodejs/jsfs.nim
Expand Up @@ -399,7 +399,7 @@ runnableExamples:


runnableExamples("-r:off"):
import nodejs/jsbuffer
import jsbuffer
requireFs()
requireBuffer()
proc example(error: int; data: Buffer) = echo data
Expand Down
5 changes: 3 additions & 2 deletions src/nodejs/jsos.nim
Expand Up @@ -56,9 +56,10 @@ when defined(windows):
WSASYSCALLFAILURE* {.importjs: "os.constants.errno.WSASYSCALLFAILURE".}: cint
WSASERVICE_NOT_FOUND* {.importjs: "os.constants.errno.WSASERVICE_NOT_FOUND".}: cint
WSATYPE_NOT_FOUND* {.importjs: "os.constants.errno.WSATYPE_NOT_FOUND".}: cint
WSA_E_NO_MORE* {.importjs: "os.constants.errno.WSA_E_NO_MORE".}: cint
WSA_E_CANCELLED* {.importjs: "os.constants.errno.WSA_E_CANCELLED".}: cint
WSAEREFUSED* {.importjs: "os.constants.errno.WSAEREFUSED".}: cint
# Duplicated ???.
# WSA_E_NO_MORE* {.importjs: "os.constants.errno.WSA_E_NO_MORE".}: cint
# WSA_E_CANCELLED* {.importjs: "os.constants.errno.WSA_E_CANCELLED".}: cint

let
EOL* {.importjs: "os.EOL".}: cstring
Expand Down
2 changes: 1 addition & 1 deletion src/nodejs/jspath.nim
Expand Up @@ -53,7 +53,7 @@ when defined(linux) or defined(posix):
## https://nodejs.org/api/path.html#path_windows_vs_posix


runnableExamples:
runnableExamples"-r:off":
requirePath()
echo delimiter
doAssert basename("/foo/bar/baz".cstring) == "baz".cstring
Expand Down
4 changes: 2 additions & 2 deletions src/nodejs/jsprocess.nim
Expand Up @@ -138,7 +138,7 @@ func getPid*(): cint {.importjs: "process.pid@".}
# ## https://nodejs.org/api/process.html#process_process_send_message_sendhandle_options_callback


runnableExamples: # These are computer specific can not assert them much.
runnableExamples"-r:off": # These are computer specific can not assert them much.
requireProcess()
doAssert not hasUncaughtExceptionCaptureCallback()
echo cwd()
Expand All @@ -156,6 +156,6 @@ runnableExamples: # These are computer specific can not assert them much.
disconnect()
exit(code = 0.cint)

runnableExamples("-r:off"):
runnableExamples"-r:off":
requireProcess()
echo argv ## Read Command Line Arguments as seq[cstring]
5 changes: 3 additions & 2 deletions src/nodejs/jsreadline.nim
Expand Up @@ -62,7 +62,8 @@ func moveCursor*(dx, dy: cint): bool {.importjs: "readline.$1(process.stout, #,


runnableExamples:
import std/jsffi, nodejs/jsprocess
import std/jsffi
import jsprocess
requireProcess()
requireReadline()
block:
Expand All @@ -83,7 +84,7 @@ runnableExamples:
# echo rl.cursor()

runnableExamples("-r:off"):
import nodejs/jsprocess
import jsprocess
requireProcess()
requireReadline()
let rl = newReadline()
Expand Down
3 changes: 2 additions & 1 deletion src/nodejs/jsreutils.nim
@@ -1,7 +1,8 @@
## - Utils for https://nim-lang.github.io/Nim/jsre.html
from std/jsre import RegExp

template groups*(self: RegExp; input: cstring; groups: varargs[var cstring]) =

template groups*(self: RegExp; input: cstring; groups: varargs[cstring]) =
## Named capture groups.
## Similar to `var [a, b, c] = regex.exec(input).slice(1);` in JavaScript.
runnableExamples:
Expand Down
42 changes: 21 additions & 21 deletions src/nodejs/jssets.nim
Expand Up @@ -30,24 +30,24 @@ func toCstring*(this: JsSet): seq[cstring] {.importjs: """

func len*(this: JsSet): int = this.size.int

func `$`*(this: JsSet): string = $this.toString()


runnableExamples:
import std/jsffi
let a: JsSet = newJsSet([1.toJs, 2.toJs, 3.toJs, 4.toJs])
let b: JsSet = newJsSet([1.0.toJs, 2.0.toJs, 3.0.toJs])
doAssert a.len == 4
doAssert b.len == 3
doAssert a.toCstring() == @["1".cstring, "2", "3", "4"]
doAssert b.toCstring() == @["1".cstring, "2", "3"]
a.clear()
b.clear()
let d: JsSet = newJsSet([1.toJs, 2.toJs, 3.toJs])
doAssert d.len == 3
d.add(4.toJs)
d.delete(2.toJs)
doAssert 3.toJs in d
doAssert "3".cstring.toJs notin d
doAssert d.contains 1.toJs
doAssert $d == """@["1", "3", "4"]"""
template `$`*(this: JsSet): string = $this.toString()


# runnableExamples"-r:off":
# import std/jsffi
# let a: JsSet = newJsSet([1.toJs, 2.toJs, 3.toJs, 4.toJs])
# let b: JsSet = newJsSet([1.0.toJs, 2.0.toJs, 3.0.toJs])
# doAssert a.len == 4
# doAssert b.len == 3
# doAssert a.toCstring() == @["1".cstring, "2", "3", "4"]
# doAssert b.toCstring() == @["1".cstring, "2", "3"]
# a.clear()
# b.clear()
# let d: JsSet = newJsSet([1.toJs, 2.toJs, 3.toJs])
# doAssert d.len == 3
# d.add(4.toJs)
# d.delete(2.toJs)
# doAssert 3.toJs in d
# doAssert "3".cstring.toJs notin d
# doAssert d.contains 1.toJs
# doAssert $d == """@["1", "3", "4"]"""
2 changes: 1 addition & 1 deletion src/nodejs/jsutils.nim
Expand Up @@ -196,7 +196,7 @@ func isSymbol*(value: auto): bool {.importjs: "(typeof # === 'symbol')".}
## https://nodejs.org/api/util.html#util_util_issymbol_object


runnableExamples:
runnableExamples"-r:off":
requireUtil()
block:
doAssert cstring"%s:%s".format("example".cstring) == "example:%s".cstring
Expand Down

0 comments on commit e20b37b

Please sign in to comment.