Skip to content

Commit

Permalink
chrone: split CI, gen gh pages
Browse files Browse the repository at this point in the history
  • Loading branch information
litlighilit committed Jun 15, 2024
1 parent 202e48d commit 6d84ade
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 19 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: docs

# yamllint disable-line rule:truthy
on:
push:
branches:
- master
env:
nim-version: 'stable'
deploy-dir: .gh-pages
lib-deploy-dir: .gh-pages/Lib
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Cache nimble
id: cache-nimble
uses: actions/cache@v2
with:
path: ~/.nimble
key: ${{ runner.os }}-nimble
- uses: jiro4989/setup-nim-action@v1
with:
nim-version: ${{ env.nim-version }}
- name: genDoc
run: nimble testDoc --index:on --project --git.url:https://github.com/${{ github.repository }} --git.commit:master --outdir:${{ env.deploy-dir }}
- name: genLibDoc
run: nimble testLibDoc --outdir:${{ env.lib-deploy-dir }}
- name: "Copy to index.html"
run: cp ${{ env.deploy-dir }}/${{ github.event.repository.name }}.html ${{ env.deploy-dir }}/index.html
- name: Deploy documents
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ${{ env.deploy-dir }}
13 changes: 8 additions & 5 deletions .github/workflows/main.yml → .github/workflows/testC.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: Build
name: testC
on: [push, pull_request]
env:
nim-version: 'stable'
jobs:
build:
runs-on: ubuntu-latest
if: "! contains(github.event.head_commit.message, '[skip ci]')"
if: ! contains(github.event.head_commit.message, '[skip ci]')
steps:
- uses: actions/checkout@v2
- name: Cache nimble
Expand All @@ -14,6 +16,7 @@ jobs:
key: ${{ runner.os }}-nimble
- uses: jiro4989/setup-nim-action@v1
with:
nim-version: 'stable'
- name: Test nimpylib
run: nimble test
nim-version: ${{ env.nim-version }}
- name: Test C backend
run: nimble testC

21 changes: 21 additions & 0 deletions .github/workflows/testJs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: testJS
on: [push, pull_request]
env:
nim-version: 'stable'
jobs:
build:
runs-on: ubuntu-latest
if: ! contains(github.event.head_commit.message, '[skip ci]')
steps:
- uses: actions/checkout@v2
- name: Cache nimble
id: cache-nimble
uses: actions/cache@v2
with:
path: ~/.nimble
key: ${{ runner.os }}-nimble
- uses: jiro4989/setup-nim-action@v1
with:
nim-version: ${{ env.nim-version }}
- name: Test JS backend
run: nimble testJs
59 changes: 45 additions & 14 deletions pylib.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,64 @@ task testC, "Test C":
exec "nim r --experimental:strictFuncs --mm:orc tests/tester"

import std/os
task testDoc, "Test doc-gen and runnableExamples":
var arg = "pylib.nim"
func getArgs(taskName: string): seq[string] =
## cmdargs: 1 2 3 4 5 -> 1 4 3 2 5
var rargs: seq[string]
let argn = paramCount()
if argn > 1:
let a1 = paramStr argn-1
if a1 == "e" or a1 == "testDoc":
arg = paramStr argn
exec "nim doc --project --outdir:docs " & srcDir / arg
for i in countdown(argn, 0):
let arg = paramStr i
if arg == taskName:
break
rargs.add arg
if rargs.len > 1:
swap rargs[^1], rargs[0] # the file must be the last, others' order don't matter
return rargs

task testLibDoc, "Test doc-gen and runnableExamples":
func getSArg(taskName: string): string = quoteShellCommand getArgs taskName

func getHandledArg(taskName: string, def_arg: string): string =
## the last param can be an arg, if given,
##
## def_arg is used when the last is not arg or is "ALL"
var args = getArgs taskName
if args.len == 0:
return
let lastArg = args[^1]
if lastArg[0] == '-': args.add def_arg
elif lastArg == "ALL": args[^1] = def_arg
# else, the last shall be a nim file
result = quoteShellCommand args

task testDoc, "cmdargs: if the last is arg: " &
"ALL: gen for all(default); else: a nim file":
let def_arg = srcDir / "pylib.nim"
let sargs = getHandledArg("testDoc", def_arg)
exec "nim doc --project --outdir:docs " & sargs

task testLibDoc, "Test doc-gen and runnableExamples, can pass several args":
let libDir = srcDir / "pylib/Lib"
#for f in walkFiles libDir/"*.nim": # walkFiles not support nims
let nimSuf = ".nim"
let args = getSArg "testLibDoc"
for t in walkDir libDir:
if t.kind in {pcDir, pcLinkToDir}: continue
let fp = t.path
var cmd = "nim doc"
if fp.endsWith nimSuf:
if (fp[0..(fp.len - nimSuf.len-1)] & "_impl").dirExists:
cmd.add " --project"
exec cmd & " --outdir:docs/Lib " & fp

task test, "Runs the test suite":
exec cmd & " --outdir:docs/Lib " & args & ' ' & fp

task testDocAll, "Test doc and Lib's doc":
testDocTask()
testLibDocTask()

task testBackends, "Test C, Js, ..":
# Test C
testCTask()
# Test JS
testJsTask()

task test, "Runs the test suite":
testBackendsTask()
# Test all runnableExamples
testDocTask()
testLibDocTask()
testDocAllTask()

0 comments on commit 6d84ade

Please sign in to comment.