From 53d68b36e97b374d6a4733d30a05e35d9a1fad89 Mon Sep 17 00:00:00 2001 From: Daniil Sedov <42098239+Gusarich@users.noreply.github.com> Date: Wed, 29 Nov 2023 18:01:12 +0300 Subject: [PATCH] ci: add for Ubuntu, Windows & macOS CI (#96) Also fixes the build and tests on Windows Co-authored-by: Anton Trunov --- .github/workflows/node.js.yml | 31 +++++++++++++++++++++++++++++++ package.json | 3 ++- scripts/pack.ts | 9 +++++---- src/pipeline/build.ts | 14 +------------- src/utils/filePath.ts | 13 +++++++++++++ yarn.lock | 9 ++++++++- 6 files changed, 60 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/node.js.yml create mode 100644 src/utils/filePath.ts diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml new file mode 100644 index 000000000..3a4614660 --- /dev/null +++ b/.github/workflows/node.js.yml @@ -0,0 +1,31 @@ +name: Node.js CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + strategy: + fail-fast: false + matrix: + node-version: [18.x] + os: [ubuntu-latest, windows-latest, macos-latest] + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'yarn' + - run: yarn install + - run: yarn clean + - run: yarn build + - run: yarn gen + - run: yarn coverage diff --git a/package.json b/package.json index deb5c995b..0df912036 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "clean": "rm -fr dist", "build": "tsc && cp ./src/grammar/grammar.ohm* ./dist/grammar/ && cp ./src/func/funcfiftlib.* ./dist/func", "test": "jest", - "coverage": "COVERAGE=true jest", + "coverage": "cross-env COVERAGE=true jest", "release": "yarn clean && yarn build && yarn coverage && yarn release-it --npm.yarn1" }, "files": [ @@ -54,6 +54,7 @@ "@types/js-yaml": "^4.0.5", "@types/node": "^18.11.9", "@types/qs": "^6.9.7", + "cross-env": "^7.0.3", "glob": "^8.1.0", "jest": "^29.3.1", "js-yaml": "^4.1.0", diff --git a/scripts/pack.ts b/scripts/pack.ts index b4d6bd68c..634e4435e 100644 --- a/scripts/pack.ts +++ b/scripts/pack.ts @@ -1,6 +1,7 @@ import fs from 'fs'; import path from 'path'; import glob from 'glob'; +import { posixNormalize } from '../src/utils/filePath'; // Pack func let wasmBase64 = fs.readFileSync(path.resolve(__dirname, '..', 'src', 'func', 'funcfiftlib.wasm')).toString('base64'); @@ -8,13 +9,13 @@ let wasmBase64js = `module.exports = { FuncFiftLibWasm: '${wasmBase64}' };`; fs.writeFileSync(path.resolve(__dirname, '..', 'src', 'func', 'funcfiftlib.wasm.js'), wasmBase64js); // Pack stdlib -let t = glob.sync(path.resolve(__dirname, '..', 'stdlib', '**', '*.@(tact|fc)')); +let stdlibFiles = glob.sync(path.resolve(__dirname, '..', 'stdlib', '**', '*.@(tact|fc)'), {windowsPathsNoEscape: true}); +const dirPrefixToRemove = posixNormalize(path.resolve(__dirname, '..', 'stdlib')) + '/'; // Remove also the leading slash let output: string = ''; output = 'let files: { [key: string]: string } = {};\n'; -for (let f of t) { +for (let f of stdlibFiles) { let code = fs.readFileSync(f).toString('base64'); - let name = f.replace(path.resolve(__dirname, '..', 'stdlib'), ''); // Thanks ChatGPT - name = name.slice(1); // Remove leading slash + let name = f.replace(dirPrefixToRemove, ''); output += `files['${name}'] =\n`; let first = true; while (code.length > 0) { diff --git a/src/pipeline/build.ts b/src/pipeline/build.ts index 6c9bfe7b5..271814a71 100644 --- a/src/pipeline/build.ts +++ b/src/pipeline/build.ts @@ -14,25 +14,13 @@ import { packageCode } from '../packaging/packageCode'; import { createABITypeRefFromTypeRef } from '../types/resolveABITypeRef'; import { getContracts, getType } from '../types/resolveDescriptors'; import { errorToString } from '../utils/errorToString'; +import { posixNormalize } from '../utils/filePath'; import { createVirtualFileSystem } from '../vfs/createVirtualFileSystem'; import { VirtualFileSystem } from '../vfs/VirtualFileSystem'; import { compile } from './compile'; import { precompile } from "./precompile"; import { getCompilerVersion } from './version'; -// ts-ignore is used on purpose here (instead of installing @types/node or similar) -// because the whole package must not depend on any node code -// however, this function is required to fix compilation on windows -function posixNormalize(path: string): string { - // @ts-ignore - if (typeof global === 'object' && typeof global.process === 'object' && typeof global.process.versions === 'object' && global.process.versions.node) { - // @ts-ignore - const pathModule = require('node:path'); - return path.split(pathModule.sep).join(pathModule.posix.sep); - } - return path; -} - export async function build(args: { config: ConfigProject, project: VirtualFileSystem, diff --git a/src/utils/filePath.ts b/src/utils/filePath.ts new file mode 100644 index 000000000..4f78729d7 --- /dev/null +++ b/src/utils/filePath.ts @@ -0,0 +1,13 @@ +// ts-ignore is used on purpose here (instead of installing @types/node or similar) +// because the whole package must not depend on any node code +// however, this function is required to fix compilation on windows +export function posixNormalize(path: string): string { + // @ts-ignore + if (typeof global === 'object' && typeof global.process === 'object' && typeof global.process.versions === 'object' && global.process.versions.node) { + // @ts-ignore + const pathModule = require('node:path'); + let normalized_path = path.split(pathModule.sep).join(pathModule.posix.sep); + return normalized_path; + } + return path; +} diff --git a/yarn.lock b/yarn.lock index b1df66027..3612c94dc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1596,7 +1596,14 @@ create-require@^1.1.0: resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333" integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ== -cross-spawn@^7.0.3: +cross-env@^7.0.3: + version "7.0.3" + resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.3.tgz#865264b29677dc015ba8418918965dd232fc54cf" + integrity sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw== + dependencies: + cross-spawn "^7.0.1" + +cross-spawn@^7.0.1, cross-spawn@^7.0.3: version "7.0.3" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==