From 4463257374f3de94896f9887bf7b8f132bdbab54 Mon Sep 17 00:00:00 2001 From: Alex Fedoseev Date: Thu, 4 Jun 2020 12:05:13 +0300 Subject: [PATCH 1/3] Switch to GH Actions --- .ci/azure-pipelines.yml | 33 ----- .ci/release/build.yml | 6 - .ci/release/bundle.yml | 58 --------- .ci/release/install.yml | 14 -- .ci/release/pipeline.yml | 17 --- .ci/release/publish.yml | 8 -- .ci/script/package.json.js | 28 ---- .ci/script/postinstall.js | 107 --------------- .github/workflows/pipeline.yml | 123 ++++++++++++++++++ .github/workflows/scripts/copy-binaries.js | 53 ++++++++ .github/workflows/scripts/print-esy-cache.js | 15 +++ .../workflows/scripts/write-package-json.js | 39 ++++++ 12 files changed, 230 insertions(+), 271 deletions(-) delete mode 100644 .ci/azure-pipelines.yml delete mode 100644 .ci/release/build.yml delete mode 100644 .ci/release/bundle.yml delete mode 100644 .ci/release/install.yml delete mode 100644 .ci/release/pipeline.yml delete mode 100644 .ci/release/publish.yml delete mode 100644 .ci/script/package.json.js delete mode 100644 .ci/script/postinstall.js create mode 100644 .github/workflows/pipeline.yml create mode 100644 .github/workflows/scripts/copy-binaries.js create mode 100644 .github/workflows/scripts/print-esy-cache.js create mode 100644 .github/workflows/scripts/write-package-json.js diff --git a/.ci/azure-pipelines.yml b/.ci/azure-pipelines.yml deleted file mode 100644 index e6d0de0..0000000 --- a/.ci/azure-pipelines.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: bs-log-ci - -trigger: - - master - -jobs: - - template: release/pipeline.yml - parameters: - name: "bs_log_macOS" - vmImage: "macOS-10.14" - platform: "macOS" - - - template: release/pipeline.yml - parameters: - name: "bs_log_Linux" - vmImage: "ubuntu-16.04" - platform: "Linux" - - - template: release/pipeline.yml - parameters: - name: "bs_log_Windows" - vmImage: "vs2017-win2016" - platform: "Windows" - - - job: bs_log_bundle - pool: - vmImage: ubuntu-16.04 - dependsOn: - - bs_log_Linux - - bs_log_macOS - - bs_log_Windows - steps: - - template: release/bundle.yml diff --git a/.ci/release/build.yml b/.ci/release/build.yml deleted file mode 100644 index 4cdbb6e..0000000 --- a/.ci/release/build.yml +++ /dev/null @@ -1,6 +0,0 @@ -steps: - - script: yarn run build - displayName: "yarn run build" - - - script: esy build - displayName: "esy build" diff --git a/.ci/release/bundle.yml b/.ci/release/bundle.yml deleted file mode 100644 index d901a69..0000000 --- a/.ci/release/bundle.yml +++ /dev/null @@ -1,58 +0,0 @@ -steps: - - task: NodeTool@0 - displayName: "Use Node 12.x" - inputs: - versionSpec: 12.x - - - task: DownloadBuildArtifacts@0 - displayName: "Download Linux Artifacts" - inputs: - artifactName: Linux - downloadPath: "_release" - - - script: "mkdir -p _release/bin/platform-linux" - displayName: "Create _release/bin/platform-linux" - - - script: "mv _release/Linux/bin.exe _release/bin/platform-linux/bin.exe" - displayName: "mv Linux" - - - task: DownloadBuildArtifacts@0 - displayName: "Download macOS Artifacts" - inputs: - artifactName: macOS - downloadPath: "_release" - - - script: "mkdir -p _release/bin/platform-darwin" - displayName: "Create _release/bin/platform-darwin" - - - script: "mv _release/macOS/bin.exe _release/bin/platform-darwin/bin.exe" - displayName: "mv macOS" - - - task: DownloadBuildArtifacts@0 - displayName: "Download Windows Artifacts" - inputs: - artifactName: Windows - downloadPath: "_release" - - - script: "mkdir -p _release/bin/platform-windows-x64" - displayName: "Create _release/bin/platform-windows-x64" - - - script: "mv _release/Windows/bin.exe _release/bin/platform-windows-x64/bin.exe" - displayName: "mv Windows" - - - script: | - mkdir -p _release/src - cp README.md _release/README.md - cp package.json _release/package.json - cp bsconfig.json _release/bsconfig.json - cp src/BrowserLogger.re _release/src/BrowserLogger.re - cp src/NodeLogger.re _release/src/NodeLogger.re - cp .ci/script/postinstall.js _release/postinstall.js - node .ci/script/package.json.js - displayName: "Copy needed files" - - - task: PublishBuildArtifacts@1 - displayName: "Publish Artifact: Release" - inputs: - PathtoPublish: "_release" - ArtifactName: Release diff --git a/.ci/release/install.yml b/.ci/release/install.yml deleted file mode 100644 index a27691f..0000000 --- a/.ci/release/install.yml +++ /dev/null @@ -1,14 +0,0 @@ -steps: - - task: NodeTool@0 - displayName: "Use Node 12.x" - inputs: - versionSpec: 12.x - - - script: "npm install -g esy@0.5.8" - displayName: "npm install -g esy@0.5.8" - - - script: yarn install - displayName: "yarn install" - - - script: esy install - displayName: "esy install" diff --git a/.ci/release/pipeline.yml b/.ci/release/pipeline.yml deleted file mode 100644 index 8b6187b..0000000 --- a/.ci/release/pipeline.yml +++ /dev/null @@ -1,17 +0,0 @@ -parameters: # defaults to macOS - name: "bs_log_macOS" - vmImage: "macOS-10.13" - platform: "macOS" - -jobs: - - job: ${{ parameters.name }} - pool: - vmImage: ${{ parameters.vmImage }} - demands: node.js - - steps: - - template: install.yml - - template: build.yml - - template: publish.yml - parameters: - platform: ${{ parameters.platform }} diff --git a/.ci/release/publish.yml b/.ci/release/publish.yml deleted file mode 100644 index 56468ae..0000000 --- a/.ci/release/publish.yml +++ /dev/null @@ -1,8 +0,0 @@ -steps: - - task: PublishBuildArtifacts@1 - displayName: "Publish ${{ parameters.platform }}" - inputs: - pathToPublish: "_build/default/bin/bin.exe" - artifactName: "${{ parameters.platform }}" - parallel: true - parallelCount: 8 diff --git a/.ci/script/package.json.js b/.ci/script/package.json.js deleted file mode 100644 index e2aa23a..0000000 --- a/.ci/script/package.json.js +++ /dev/null @@ -1,28 +0,0 @@ -const fs = require("fs"); -const path = require("path"); - -const mainPackageJson = require("../../package.json"); -const packageJson = JSON.stringify( - { - name: mainPackageJson.name, - version: mainPackageJson.version, - description: mainPackageJson.description, - author: mainPackageJson.author, - license: mainPackageJson.license, - repository: mainPackageJson.repository, - files: mainPackageJson.files, - peerDependencies: mainPackageJson.peerDependencies, - keywords: mainPackageJson.keywords, - scripts: { - postinstall: "node ./postinstall.js" - } - }, - null, - 2 -); - -fs.writeFileSync( - path.join(__dirname, "..", "..", "_release", "package.json"), - packageJson, - {encoding: "utf8"}, -); diff --git a/.ci/script/postinstall.js b/.ci/script/postinstall.js deleted file mode 100644 index 51cae10..0000000 --- a/.ci/script/postinstall.js +++ /dev/null @@ -1,107 +0,0 @@ -var fs = require("fs"); -var os = require("os"); -var cp = require("child_process"); -var path = require("path"); - -var platform = process.platform; - -var bin = "bin.exe"; - -var WINDOWS_X64 = "windows-x64"; - -/** - * Since os.arch returns node binary's target arch, not - * the system arch. - * Credits: https://github.com/feross/arch/blob/af080ff61346315559451715c5393d8e86a6d33c/index.js#L10-L58 - */ -function arch() { - /** - * The running binary is 64-bit, so the OS is clearly 64-bit. - */ - if (process.arch === "x64") { - return "x64"; - } - - /** - * All recent versions of Mac OS are 64-bit. - */ - if (process.platform === "darwin") { - return "x64"; - } - - /** - * On Windows, the most reliable way to detect a 64-bit OS from within a 32-bit - * app is based on the presence of a WOW64 file: %SystemRoot%\SysNative. - * See: https://twitter.com/feross/status/776949077208510464 - */ - if (process.platform === "win32") { - var useEnv = false; - try { - useEnv = !!( - process.env.SYSTEMROOT && fs.statSync(process.env.SYSTEMROOT) - ); - } catch (err) {} - - var sysRoot = useEnv ? process.env.SYSTEMROOT : "C:\\Windows"; - - // If %SystemRoot%\SysNative exists, we are in a WOW64 FS Redirected application. - var isWOW64 = false; - try { - isWOW64 = !!fs.statSync(path.join(sysRoot, "sysnative")); - } catch (err) {} - - return isWOW64 ? "x64" : "x86"; - } - - /** - * On Linux, use the `getconf` command to get the architecture. - */ - if (process.platform === "linux") { - var output = cp.execSync("getconf LONG_BIT", { encoding: "utf8" }); - return output === "64\n" ? "x64" : "x86"; - } - - /** - * If none of the above, assume the architecture is 32-bit. - */ - return "x86"; -} - -// implementing it b/c we don't want to depend on fs.copyFileSync -// which appears only in node@8.x -function copyFileSync(sourcePath, destPath) { - var data = fs.readFileSync(sourcePath); - var stat = fs.statSync(sourcePath); - fs.writeFileSync(destPath, data); - fs.chmodSync(destPath, stat.mode); -} - -var copyPlatformBinaries = platformPath => { - var platformBuildPath = path.join(__dirname, "bin", "platform-" + platformPath); - var sourcePath = path.join(platformBuildPath, bin); - var destBin = platformPath === WINDOWS_X64 ? "ppx.exe" : "ppx"; - var destPath = path.join(__dirname, destBin); - if (fs.existsSync(destPath)) { - fs.unlinkSync(destPath); - } - copyFileSync(sourcePath, destPath); - fs.chmodSync(destPath, 0777); -}; - -switch (platform) { - case "win32": - if (arch() !== "x64") { - console.warn("error: x86 is currently not supported on Windows"); - process.exit(1); - } - - copyPlatformBinaries(WINDOWS_X64); - break; - case "linux": - case "darwin": - copyPlatformBinaries(platform); - break; - default: - console.warn("error: no release built for the " + platform + " platform"); - process.exit(1); -} diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml new file mode 100644 index 0000000..72adb60 --- /dev/null +++ b/.github/workflows/pipeline.yml @@ -0,0 +1,123 @@ +name: bs-log pipeline + +on: + pull_request: + branches: + - master + +jobs: + build: + name: Build on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + node-version: [12.x] + os: [ubuntu-latest, macOS-latest, windows-latest] + + steps: + - name: Checkout repo + uses: actions/checkout@v2 + + - name: Setup Node ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - name: Print Yarn cache + id: print-yarn-cache + run: echo "::set-output name=yarn-cache::$(yarn cache dir)" + + - name: Restore Yarn cache + id: yarn-cache + uses: actions/cache@v1 + with: + path: ${{ steps.print-yarn-cache.outputs.yarn-cache }} + key: ${{ matrix.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + + - name: Install Yarn deps + run: yarn install + + - name: Install Esy + run: npm install -g esy@0.6.2 + + - name: Install Esy deps + run: esy install + + - name: Print Esy cache + id: print-esy-cache + run: node .github/workflows/scripts/print-esy-cache.js + + - name: Restore Esy cache + id: esy-cache + uses: actions/cache@v1 + with: + path: ${{ steps.print-esy-cache.outputs.esy-cache }} + key: ${{ matrix.os }}-esy-${{ hashFiles('**/index.json') }} + + - name: Build ppx + run: esy build + + - name: Build BuckleScript lib + run: yarn run build + + - name: Upload artifacts + uses: actions/upload-artifact@v1 + with: + name: ${{ matrix.os }} + path: _build/default/bin/bin.exe + + rc: + needs: build + name: Prepare RC + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v2 + + - name: Setup Node ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: 12.x + + - name: Download Linux artifacts + uses: actions/download-artifact@v1 + with: + name: ubuntu-latest + path: _bin/linux + + - name: Download macOS artifacts + uses: actions/download-artifact@v1 + with: + name: macOS-latest + path: _bin/darwin + + - name: Download Windows artifacts + uses: actions/download-artifact@v1 + with: + name: windows-latest + path: _bin/windows + + - name: Move artifacts + run: | + mkdir -p _release/bin + mv _bin/darwin/bin.exe _release/bin/bs-log-ppx-darwin-x64.exe + mv _bin/windows/bin.exe _release/bin/bs-log-ppx-win-x64.exe + mv _bin/linux/bin.exe _release/bin/bs-log-ppx-linux-x64.exe + rm -rf _bin + + - name: Move lib files + run: | + mkdir -p _release/src + cp README.md _release/README.md + cp bsconfig.json _release/bsconfig.json + cp src/BrowserLogger.re _release/src/BrowserLogger.re + cp src/NodeLogger.re _release/src/NodeLogger.re + cp .github/workflows/scripts/copy-binaries.js _release/postinstall.js + node .github/workflows/scripts/write-package-json.js + + - name: Upload release + uses: actions/upload-artifact@v1 + with: + name: release + path: _release diff --git a/.github/workflows/scripts/copy-binaries.js b/.github/workflows/scripts/copy-binaries.js new file mode 100644 index 0000000..5ee66aa --- /dev/null +++ b/.github/workflows/scripts/copy-binaries.js @@ -0,0 +1,53 @@ +#!/usr/bin/env node + +const fs = require("fs"); + +const PPX = "bs-log-ppx"; + +let arch = process.arch; +let platform = process.platform; + +if (arch === "ia32") { + arch = "x86"; +} + +if (platform === "win32") { + platform = "win"; +} + +const filename = `bin/${PPX}-${platform}-${arch}.exe`; + +const supported = fs.existsSync(filename); + +if (!supported) { + console.error(`${PPX} does not support this platform :(`); + console.error(""); + console.error(`${PPX} comes prepacked as built binaries to avoid large`); + console.error("dependencies at build-time."); + console.error(""); + console.error(`If you want ${PPX} to support this platform natively,`); + console.error("please open an issue at our repository, linked above. Please"); + console.error(`specify that you are on the ${platform} platform,`); + console.error(`on the ${arch} architecture.`); + +} + +if (platform === "win") { + if (!fs.existsSync("ppx.exe")) { + copyFileSync(filename, "ppx.exe"); + fs.chmodSync("ppx.exe", 0755); + } +} else { + if (!fs.existsSync("ppx")) { + copyFileSync(filename, "ppx"); + fs.chmodSync("ppx", 0755); + } +} + +function copyFileSync(source, dest) { + if (typeof fs.copyFileSync === "function") { + fs.copyFileSync(source, dest); + } else { + fs.writeFileSync(dest, fs.readFileSync(source)); + } +} diff --git a/.github/workflows/scripts/print-esy-cache.js b/.github/workflows/scripts/print-esy-cache.js new file mode 100644 index 0000000..4d417a3 --- /dev/null +++ b/.github/workflows/scripts/print-esy-cache.js @@ -0,0 +1,15 @@ +const fs = require("fs"); +const os = require("os"); +const path = require("path"); + +const ESY_FOLDER = process.env.ESY__PREFIX + ? process.env.ESY__PREFIX + : path.join(os.homedir(), ".esy"); + +const esy3 = fs + .readdirSync(ESY_FOLDER) + .filter(name => name.length > 0 && name[0] === "3") + .sort() + .pop(); + +console.log(`::set-output name=esy-cache::${path.join(ESY_FOLDER, esy3, "i")}`); diff --git a/.github/workflows/scripts/write-package-json.js b/.github/workflows/scripts/write-package-json.js new file mode 100644 index 0000000..639e29e --- /dev/null +++ b/.github/workflows/scripts/write-package-json.js @@ -0,0 +1,39 @@ +const fs = require("fs"); +const path = require("path"); + +const { + name, + version, + description, + author, + license, + repository, + files, + peerDependencies, + keywords +} = require("../../../package.json"); + +const packageJson = JSON.stringify( + { + name, + version, + description, + author, + license, + repository, + files, + peerDependencies, + keywords, + scripts: { + postinstall: "node ./postinstall.js" + } + }, + null, + 2 +); + +fs.writeFileSync( + path.join(__dirname, "..", "..", "..", "_release", "package.json"), + packageJson, + { encoding: "utf8" } +); From 9f3513d1ee16bccc74dae4bf5ddb29d7632669ef Mon Sep 17 00:00:00 2001 From: Alex Fedoseev Date: Thu, 4 Jun 2020 12:39:24 +0300 Subject: [PATCH 2/3] Update HISTORY --- HISTORY.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index 94fd5e7..f748c56 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,8 @@ # History +## 1.2.0 +- Make logging event polymorphic in `BrowserLogger` and `NodeLogger`. + ## 1.1.0 - Logging in libraries. From ebf7a1228599e9dfd61461e4f0a6d19f4bca06bf Mon Sep 17 00:00:00 2001 From: Alex Fedoseev Date: Thu, 4 Jun 2020 12:40:43 +0300 Subject: [PATCH 3/3] v1.2.0 --- esy.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/esy.json b/esy.json index 79a9e86..f4bef4f 100644 --- a/esy.json +++ b/esy.json @@ -1,6 +1,6 @@ { "name": "bs-log-ppx", - "version": "1.1.0", + "version": "1.2.0", "description": "Logging implementation for ReasonML/BuckleScript", "author": "Alex Fedoseev ", "license": "MIT", diff --git a/package.json b/package.json index 15d32b1..3c4161b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bs-log", - "version": "1.1.0", + "version": "1.2.0", "description": "Logging implementation for ReasonML/BuckleScript", "author": "Alex Fedoseev ", "license": "MIT",