From 3d0d00ce119cc5f4fed53ffbf31e654c06ea78a3 Mon Sep 17 00:00:00 2001 From: fubark Date: Sat, 6 Jan 2024 12:01:34 -0500 Subject: [PATCH] Update ci. --- .github/workflows/gen-docs.yml | 76 +++++++++++++++++---- .github/workflows/latest-build.yml | 102 +++++++++++++++++++++++++++-- .github/workflows/pr-build.yml | 1 - build.zig | 4 +- docs/gen-docs.cy | 2 +- src/tools/md4c.cy | 8 ++- test/behavior_test.zig | 5 +- 7 files changed, 175 insertions(+), 23 deletions(-) diff --git a/.github/workflows/gen-docs.yml b/.github/workflows/gen-docs.yml index a1d257aa2..ba352062c 100644 --- a/.github/workflows/gen-docs.yml +++ b/.github/workflows/gen-docs.yml @@ -6,35 +6,85 @@ on: branches: - master paths: - - 'docs/hugo/**' + - 'docs/**' + - 'src/builtins/**' jobs: deploy: runs-on: ubuntu-22.04 + env: + ZIG_VERSION: 0.11.0 steps: - - uses: actions/checkout@v3 + - name: Clone repo. + uses: actions/checkout@v3 with: submodules: false fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod - - name: Install theme. + - name: Install zig. run: | - git clone --depth=1 https://github.com/alex-shpak/hugo-book docs/hugo/themes/hugo-book + wget -c https://ziglang.org/builds/zig-linux-x86_64-${{ env.ZIG_VERSION }}.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin - - name: Install Hugo. - uses: peaceiris/actions-hugo@v2 + - name: Build md4c. + run: | + git clone --depth=1 https://github.com/mity/md4c.git + cd md4c + mkdir build + cd build + cmake .. + make + + - name: Setup script. + uses: actions/github-script@v5 with: - hugo-version: 'latest' - # Needed to build SCSS/SASS with transpiler set to 'libsass' - extended: true + script: | + async function execCmd(name, args) { + const opts = {}; + let out = ''; + let err = ''; + opts.listeners = { + stdout: (data) => { + out += data.toString(); + }, + stderr: (data) => { + process.stderr.write(data.toString()); + } + }; + // opt.cwd = './lib'; + await exec.exec(name, args, opts); + return out; + } + const version = await execCmd('zig', ['build', 'version']); + const parts = version.split('.') + const last_version = parts[0] + '.' + (parseInt(parts[1])-1) + core.exportVariable('SHORT_VERSION', version); + await execCmd('git', ['fetch', '--all', '--tags']); + const build = await execCmd('git', ['rev-list', '--count', `${last_version}..${context.sha}`]) + core.exportVariable('BUILD', build.trim()); + core.exportVariable('COMMIT', context.sha.substring(0, 7)); + + - name: Cache. + uses: actions/cache@v2 + with: + path: |- + ~/.cache/zig + zig-cache + key: + build-1 + restore-keys: + build-1 + + - name: Build Cyber. + run: zig build cli - - name: Generate. + - name: Generate docs. run: | - cd docs/hugo - hugo --minify + LD_LIBRARY_PATH=`pwd`/md4c/build/src zig-out/bin/cyber docs/gen-docs.cy -version "${{ format('v{0}-dev {1}-{2}', env.SHORT_VERSION, env.BUILD, env.COMMIT) }}" + mkdir -p docs/public + mv docs/docs.html docs/public/index.html - name: Deploy. uses: peaceiris/actions-gh-pages@v3 if: github.ref == 'refs/heads/master' with: github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./docs/hugo/public \ No newline at end of file + publish_dir: ./docs/public \ No newline at end of file diff --git a/.github/workflows/latest-build.yml b/.github/workflows/latest-build.yml index 898799e79..fe0f420ed 100644 --- a/.github/workflows/latest-build.yml +++ b/.github/workflows/latest-build.yml @@ -14,7 +14,6 @@ on: paths-ignore: - '.github/**' - '**.md' - - 'docs/hugo/**' - '.gitattributes' - 'examples/**.cy' - 'examples/**/*.cy' @@ -168,9 +167,11 @@ jobs: return out; } const version = await execCmd('zig', ['build', 'version']); + const parts = version.split('.') + const last_version = parts[0] + '.' + (parseInt(parts[1])-1) core.exportVariable('SHORT_VERSION', version); await execCmd('git', ['fetch', '--all', '--tags']); - const build = await execCmd('git', ['rev-list', '--count', `${version}..${context.sha}`]) + const build = await execCmd('git', ['rev-list', '--count', `${last_version}..${context.sha}`]) core.exportVariable('BUILD', build.trim()); core.exportVariable('COMMIT', context.sha.substring(0, 7)); @@ -295,8 +296,97 @@ jobs: short_version: ${{ env.SHORT_VERSION }} # version: ${{ env.BUILD_VERSION }} + docs: + runs-on: ubuntu-22.04 + env: + ZIG_VERSION: 0.11.0 + steps: + - name: Clone repo. + uses: actions/checkout@v3 + with: + submodules: false + fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod + + - name: Install zig. + run: | + wget -c https://ziglang.org/builds/zig-linux-x86_64-${{ env.ZIG_VERSION }}.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin + + - name: Build md4c. + run: | + git clone --depth=1 https://github.com/mity/md4c.git + cd md4c + mkdir build + cd build + cmake .. + make + + - name: Setup script. + uses: actions/github-script@v5 + with: + script: | + async function execCmd(name, args) { + const opts = {}; + let out = ''; + let err = ''; + opts.listeners = { + stdout: (data) => { + out += data.toString(); + }, + stderr: (data) => { + process.stderr.write(data.toString()); + } + }; + // opt.cwd = './lib'; + await exec.exec(name, args, opts); + return out; + } + const version = await execCmd('zig', ['build', 'version']); + const parts = version.split('.') + const last_version = parts[0] + '.' + (parseInt(parts[1])-1) + core.exportVariable('SHORT_VERSION', version); + await execCmd('git', ['fetch', '--all', '--tags']); + const build = await execCmd('git', ['rev-list', '--count', `${last_version}..${context.sha}`]) + core.exportVariable('BUILD', build.trim()); + core.exportVariable('COMMIT', context.sha.substring(0, 7)); + + - name: Cache. + uses: actions/cache@v2 + with: + path: |- + ~/.cache/zig + zig-cache + key: + build-1 + restore-keys: + build-1 + + - name: Build Cyber. + run: zig build cli + + - name: Generate docs. (Release) + if: startsWith(github.ref, 'refs/tags/') + run: | + LD_LIBRARY_PATH=`pwd`/md4c/build/src zig-out/bin/cyber docs/gen-docs.cy -version v${{ env.SHORT_VERSION }} + mv docs/docs-modules.md docs.md + mv docs/docs.html docs.html + + - name: Generate docs. (Dev) + if: ${{ !startsWith(github.ref, 'refs/tags/') }} + run: | + LD_LIBRARY_PATH=`pwd`/md4c/build/src zig-out/bin/cyber docs/gen-docs.cy -version "${{ format('v{0}-dev {1}-{2}', env.SHORT_VERSION, env.BUILD, env.COMMIT) }}" + mv docs/docs-modules.md docs.md + mv docs/docs.html docs.html + + - name: Save artifact. + uses: actions/upload-artifact@v2 + with: + name: bin + path: | + docs.html + docs.md + release: - needs: build + needs: [build, docs] name: Release runs-on: ubuntu-22.04 steps: @@ -312,7 +402,7 @@ jobs: repo_token: ${{ secrets.GITHUB_TOKEN }} automatic_release_tag: latest prerelease: false - title: v${{ needs.build.outputs.short_version }}-Latest + title: v${{ needs.build.outputs.short_version }}-dev files: | cyber-linux-x64.tar.gz cyber-selinux-x64.tar.gz @@ -325,6 +415,8 @@ jobs: libcyber-macos-arm64.a cyber-web.wasm cyber-wasi.wasm + docs.html + docs.md # Auto dispatch. - name: Github Release. @@ -344,3 +436,5 @@ jobs: libcyber-macos-arm64.a cyber-web.wasm cyber-wasi.wasm + docs.html + docs.md diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index 662231c1d..6387d7d3c 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -11,7 +11,6 @@ on: pull_request: paths-ignore: - '.github/**' - - 'docs/hugo/**' - '**.md' concurrency: group: pr-${{ github.ref }} diff --git a/build.zig b/build.zig index 4952b1e80..a558bc83b 100644 --- a/build.zig +++ b/build.zig @@ -4,8 +4,8 @@ const config = @import("src/config.zig"); const mimalloc_lib = @import("lib/mimalloc/lib.zig"); const tcc_lib = @import("lib/tcc/lib.zig"); -// FIND: v0.3 -const Version = "0.3"; +// FIND: v0.4 +const Version = "0.4"; var optMalloc: ?config.Allocator = undefined; var selinux: bool = undefined; diff --git a/docs/gen-docs.cy b/docs/gen-docs.cy index 2b82be4c1..7cc147013 100644 --- a/docs/gen-docs.cy +++ b/docs/gen-docs.cy @@ -11,7 +11,7 @@ import os import md '../src/tools/md4c.cy' var args = os.parseArgs([ - [ name: 'version', type: string, default: 'v0.4-dev' ], + [ name: 'version', type: string, default: 'dev' ], ]) genDocsModules() diff --git a/src/tools/md4c.cy b/src/tools/md4c.cy index a792e2814..dc53477b9 100644 --- a/src/tools/md4c.cy +++ b/src/tools/md4c.cy @@ -1,5 +1,11 @@ -- ./src/tools/cbindgen.cy -o src/tools/md4c.cy ~/repos/md4c/src/md4c.h -I/opt/homebrew/Cellar/llvm/17.0.5/include -libpath libmd4c.dylib -stripPrefix MD +var Root.libPath = switch os.system: +case 'linux' => 'libmd4c.so' +case 'windows' => 'md4c.dll' +case 'macos' => 'libmd4c.dylib' +else => throw error.Unsupported + -- CBINDGEN MARKER -- Code below is generated by cbindgen.cy type CHAR int @@ -158,7 +164,7 @@ func load(): ffi.cbind(SPAN_WIKILINK_S, [ATTRIBUTE]) ffi.cbind(PARSER_S, [.uint, .uint, .voidPtr, .voidPtr, .voidPtr, .voidPtr, .voidPtr, .voidPtr, .voidPtr]) ffi.cfunc('md_parse', [.voidPtr, .uint, .voidPtr, .voidPtr], .int) - my lib = ffi.bindLib('libmd4c.dylib', [genMap: true]) + my lib = ffi.bindLib(libPath, [genMap: true]) md_parse = lib.md_parse return lib diff --git a/test/behavior_test.zig b/test/behavior_test.zig index bd0919996..69b5da348 100644 --- a/test/behavior_test.zig +++ b/test/behavior_test.zig @@ -3350,12 +3350,15 @@ test "examples" { test "tools" { try compile(.{}, @embedFile("../src/tools/bench.cy")); + try compile(.{}, @embedFile("../src/tools/llvm.cy")); + try compile(.{}, @embedFile("../src/tools/clang_bs.cy")); + try compile(.{}, @embedFile("../src/tools/md4c.cy")); if (!cy.isWasm) { try compile(Config.initFileModules("./src/tools/cbindgen.cy"), @embedFile("../src/tools/cbindgen.cy")); + try compile(Config.initFileModules("./docs/gen-docs.cy"), @embedFile("../docs/gen-docs.cy")); try compile(Config.initFileModules("./src/jit/gen-stencils-a64.cy"), @embedFile("../src/jit/gen-stencils-a64.cy")); try compile(Config.initFileModules("./src/jit/gen-stencils-x64.cy"), @embedFile("../src/jit/gen-stencils-x64.cy")); } - try compile(.{}, @embedFile("../docs/gen-modules.cy")); } test "benchmarks" {