diff --git a/.ci/build-platform.yml b/.ci/build-platform.yml deleted file mode 100644 index 6bf81d5..0000000 --- a/.ci/build-platform.yml +++ /dev/null @@ -1,29 +0,0 @@ -parameters: - platform: "macOS" - vmImage: "macOS-latest" - -jobs: - - job: ${{ parameters.platform }} - pool: - vmImage: ${{ parameters.vmImage }} - demands: node.js - timeoutInMinutes: 120 # This is mostly for Windows - steps: - - template: utils/use-node.yml - - template: utils/use-esy.yml - - template: utils/restore-build-cache.yml - - script: "esy install" - displayName: "esy install" - - script: "esy build" - displayName: "esy build" - - template: utils/create-docs.yml - - script: "esy test" - displayName: "Test command" - - script: "esy release" - displayName: "esy release" - - task: PublishBuildArtifacts@1 - displayName: "Publish Artifact: ${{ parameters.platform }}" - inputs: - PathtoPublish: "_release" - ArtifactName: ${{ parameters.platform }} - diff --git a/.ci/cross-release.yml b/.ci/cross-release.yml deleted file mode 100644 index 813fa43..0000000 --- a/.ci/cross-release.yml +++ /dev/null @@ -1,11 +0,0 @@ -steps: - - template: utils/use-node.yml - - - template: release-platform-setup.yml - parameters: - platform: "macOS" - folder: "platform-darwin" - - - script: "node .ci/pipelines-release.js" - displayName: "node .ci/pipelines-release.js" - continueOnError: true diff --git a/.ci/pipelines-release.js b/.ci/pipelines-release.js deleted file mode 100644 index d1af6e8..0000000 --- a/.ci/pipelines-release.js +++ /dev/null @@ -1,73 +0,0 @@ -const fs = require("fs"); -const path = require("path"); - -console.log("Creating package.json"); -const mainPackageJson = require("../esy.json"); -const packageJson = JSON.stringify( - { - name: mainPackageJson.name, - version: mainPackageJson.version, - license: mainPackageJson.license, - description: mainPackageJson.description, - repository: mainPackageJson.repository, - scripts: { - postinstall: "node ./postinstall.js" - }, - bin: mainPackageJson.esy.release.bin.reduce((acc, curr) => { - return Object.assign({ [curr]: "bin/" + curr }, acc); - }, {}), - files: [ - "_export/", - "bin/", - "postinstall.js", - "esyInstallRelease.js", - "platform-linux/", - "platform-darwin/", - "platform-windows-x64/" - ] - }, - null, - 2 -); - -fs.writeFileSync( - path.join(__dirname, "..", "_release", "package.json"), - packageJson, - { - encoding: "utf8" - } -); - -console.log("Copying LICENSE"); -fs.copyFileSync( - path.join(__dirname, "..", "LICENSE"), - path.join(__dirname, "..", "_release", "LICENSE") -); - -console.log("Copying README.md"); -fs.copyFileSync( - path.join(__dirname, "..", "README.md"), - path.join(__dirname, "..", "_release", "README.md") -); - -console.log("Copying postinstall.js"); -fs.copyFileSync( - path.join(__dirname, "release-postinstall.js"), - path.join(__dirname, "..", "_release", "postinstall.js") -); - -console.log("Creating placeholder files"); -const placeholderFile = `#!/usr/bin/env node - -console.log("You need to have postinstall enabled")`; -fs.mkdirSync(path.join(__dirname, "..", "_release", "bin")); -const binPath = path.join( - __dirname, - "..", - "_release", - "bin", - mainPackageJson.esy.release.bin[0] -); - -fs.writeFileSync(binPath, placeholderFile); -fs.chmodSync(binPath, 0777); diff --git a/.ci/release-platform-setup.yml b/.ci/release-platform-setup.yml deleted file mode 100644 index ae5f543..0000000 --- a/.ci/release-platform-setup.yml +++ /dev/null @@ -1,16 +0,0 @@ -parameters: - platform: "macOS" - folder: "platform-darwin" - -steps: - - task: DownloadBuildArtifacts@0 - displayName: "Download ${{ parameters.platform }} Artifacts" - inputs: - artifactName: ${{ parameters.platform }} - downloadPath: "_release" - - - script: "mkdir _release/${{ parameters.folder }}" - displayName: "Create _release/${{ parameters.folder }}" - - - script: "cp -r _release/${{ parameters.platform }}/ _release/${{ parameters.folder }}" - displayName: "cp ${{ parameters.platform }}" diff --git a/.ci/release-postinstall.js b/.ci/release-postinstall.js deleted file mode 100644 index 1a6f020..0000000 --- a/.ci/release-postinstall.js +++ /dev/null @@ -1,169 +0,0 @@ -/** - * release-postinstall.js - * - * XXX: We want to keep this script installable at least with node 4.x. - * - * This script is bundled with the `npm` package and executed on release. - * Since we have a 'fat' NPM package (with all platform binaries bundled), - * this postinstall script extracts them and puts the current platform's - * bits in the right place. - */ - -var path = require("path"); -var cp = require("child_process"); -var fs = require("fs"); -var os = require("os"); -var platform = process.platform; - -var packageJson = require('./package.json'); -var binariesToCopy = Object.keys(packageJson.bin).map(function(name) { - return packageJson.bin[name] -}).concat([ - "esyInstallRelease.js" -]); -var foldersToCopy = ["bin", "_export"]; - -function copyRecursive(srcDir, dstDir) { - var results = []; - var list = fs.readdirSync(srcDir); - var src, dst; - list.forEach(function(file) { - src = path.join(srcDir, file); - dst = path.join(dstDir, file); - - var stat = fs.statSync(src); - if (stat && stat.isDirectory()) { - try { - fs.mkdirSync(dst); - } catch (e) { - console.log("directory already exists: " + dst); - console.error(e); - } - results = results.concat(copyRecursive(src, dst)); - } else { - try { - fs.writeFileSync(dst, fs.readFileSync(src)); - } catch (e) { - console.log("could't copy file: " + dst); - console.error(e); - } - results.push(src); - } - }); - return results; -} - -/** - * 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, "platform-" + platformPath); - - foldersToCopy.forEach(folderPath => { - var sourcePath = path.join(platformBuildPath, folderPath); - var destPath = path.join(__dirname, folderPath); - - copyRecursive(sourcePath, destPath); - }); - - binariesToCopy.forEach(binaryPath => { - var sourcePath = path.join(platformBuildPath, binaryPath); - var destPath = path.join(__dirname, binaryPath); - if (fs.existsSync(destPath)) { - fs.unlinkSync(destPath); - } - copyFileSync(sourcePath, destPath); - fs.chmodSync(destPath, 0777); - }); -}; - -try { - fs.mkdirSync("_export"); -} catch (e) { - console.log("Could not create _export folder"); -} - -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); -} - -require("./esyInstallRelease"); diff --git a/.ci/utils/create-docs.yml b/.ci/utils/create-docs.yml deleted file mode 100644 index 514a22f..0000000 --- a/.ci/utils/create-docs.yml +++ /dev/null @@ -1,16 +0,0 @@ -# These steps are only run on Linux -steps: - - script: "esy doc" - displayName: "Build docs" - condition: and(succeeded(), eq(variables['Agent.OS'], 'Linux')) - - - script: echo '##vso[task.setvariable variable=docsPath]'$(esy echo '_build/default/_doc/_html') - displayName: "Save docsPath in variable" - condition: and(succeeded(), eq(variables['Agent.OS'], 'Linux')) - - # - task: PublishBuildArtifacts@1 - # displayName: "Publish Artifact: Docs" - # condition: and(succeeded(), eq(variables['Agent.OS'], 'Linux')) - # inputs: - # PathtoPublish: $(docsPath) - # ArtifactName: Docs diff --git a/.ci/utils/restore-build-cache.yml b/.ci/utils/restore-build-cache.yml deleted file mode 100644 index 9c6ad85..0000000 --- a/.ci/utils/restore-build-cache.yml +++ /dev/null @@ -1,25 +0,0 @@ -steps: -- bash: | - # COMPUTE THE ESY INSTALL CACHE LOCATION AHEAD OF TIME - DESIRED_LEN="86" - HOME_ESY3="$HOME/.esy/3" - HOME_ESY3_LEN=${#HOME_ESY3} - NUM_UNDERS=$(echo "$(($DESIRED_LEN-$HOME_ESY3_LEN))") - UNDERS=$(printf "%-${NUM_UNDERS}s" "_") - UNDERS="${UNDERS// /_}" - THE_ESY__CACHE_INSTALL_PATH=${HOME_ESY3}${UNDERS}/i - if [ "$AGENT_OS" == "Windows_NT" ]; then - THE_ESY__CACHE_INSTALL_PATH=$( cygpath --mixed --absolute "$THE_ESY__CACHE_INSTALL_PATH") - fi - echo "THE_ESY__CACHE_INSTALL_PATH: $THE_ESY__CACHE_INSTALL_PATH" - # This will be exposed as an env var ESY__CACHE_INSTALL_PATH, or an - # Azure var esy__cache_install_path - echo "##vso[task.setvariable variable=esy__cache_install_path]$THE_ESY__CACHE_INSTALL_PATH" - displayName: '[Cache] calculate esy store path' - -- task: Cache@2 - displayName: Restore build cache - inputs: - key: 'key1 | "$(Agent.OS)" | esy.lock/index.json' - path: $(ESY__CACHE_INSTALL_PATH) - diff --git a/.ci/utils/use-esy.yml b/.ci/utils/use-esy.yml deleted file mode 100644 index 2c9e6bf..0000000 --- a/.ci/utils/use-esy.yml +++ /dev/null @@ -1,5 +0,0 @@ -# steps to install esy globally - -steps: - - script: "npm install -g esy@0.6.6" - displayName: "install esy" diff --git a/.ci/utils/use-node.yml b/.ci/utils/use-node.yml deleted file mode 100644 index 86ac8da..0000000 --- a/.ci/utils/use-node.yml +++ /dev/null @@ -1,7 +0,0 @@ -# steps to use node on agent - -steps: - - task: NodeTool@0 - displayName: "Use Node 8.x" - inputs: - versionSpec: 8.x diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml new file mode 100644 index 0000000..bca73eb --- /dev/null +++ b/.github/workflows/pipeline.yml @@ -0,0 +1,109 @@ +name: bsdoc pipeline + +on: + pull_request: + branches: + - master + push: + 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: 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 + run: | + esy build + - name: Test + run: | + esy test + - name: Release + run: | + esy release + - name: Upload artifacts + uses: actions/upload-artifact@v1 + with: + name: ${{ matrix.os }} + path: _release + + 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: linux + + - name: Download macOS artifacts + uses: actions/download-artifact@v1 + with: + name: macOS-latest + path: darwin + + - name: Download Windows artifacts + uses: actions/download-artifact@v1 + with: + name: windows-latest + path: windows + + - name: Move artifacts + run: | + mkdir -p _release/platforms + mv linux _release/platforms/linux-x64 + mv darwin _release/platforms/darwin-x64 + mv windows _release/platforms/win-x64 + - name: Move files + run: | + cp .github/workflows/scripts/postinstall.js _release/postinstall.js + cp LICENSE _release/ + cp README.md _release/ + 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/postinstall.js b/.github/workflows/scripts/postinstall.js new file mode 100644 index 0000000..c02c446 --- /dev/null +++ b/.github/workflows/scripts/postinstall.js @@ -0,0 +1,91 @@ +#!/usr/bin/env node + +const fs = require("fs"); +const path = require("path"); +const packageJson = require("./package.json"); +const packageFiles = packageJson.files.map((f) => + f[f.length - 1] === "/" ? f.substring(0, f.length - 1) : f +); + +const PROG = "bsdoc"; + +var arch = process.arch; +var platform = process.platform; + +if (arch === "ia32") { + arch = "x86"; +} + +if (platform === "win32") { + platform = "win"; +} + +const platformPath = `${platform}-${arch}`; + +const filename = `platforms/${platformPath}/bin/${PROG}`; + +const supported = fs.existsSync(filename); + +if (!supported) { + console.error(`${PROG} does not support this platform :(`); + console.error(""); + console.error(`${PROG} comes prepacked as built binaries to avoid large`); + console.error("dependencies at build-time."); + console.error(""); + console.error(`If you want ${PROG} 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.`); + process.exit(1); +} + +fs.readdirSync("./").filter(notInPackage).map(rm); +copyRecursiveSync(`platforms/${platformPath}/_export`, "./_export"); +copyRecursiveSync(`platforms/${platformPath}/bin`, "./bin"); +copyRecursiveSync( + `platforms/${platformPath}/esyInstallRelease.js`, + "./esyInstallRelease.js" +); + +if (platform == "win") { + fs.chmodSync(`bin/${PROG}.exe`, 0755); +} else { + fs.chmodSync(`bin/${PROG}`, 0755); +} + +require("child_process").fork("./esyInstallRelease.js"); + +function copyRecursiveSync(src, dest) { + var exists = fs.existsSync(src); + var stats = exists && fs.statSync(src); + var isDirectory = exists && stats.isDirectory(); + if (isDirectory) { + if (!fs.existsSync(dest)) { + fs.mkdirSync(dest); + } + fs.readdirSync(src).forEach(function (childItemName) { + copyRecursiveSync( + path.join(src, childItemName), + path.join(dest, childItemName) + ); + }); + } else { + fs.copyFileSync(src, dest); + } +} + +function rm(path) { + if ("rmSync" in fs) { + return fs.rmSync(path, { force: true, recursive: true }); + } + const stats = fs.statSync(path); + if (stats.isDirectory) { + fs.rmdirSync(path, { recursive: true }); + } else { + fs.unlinkSync(path); + } +} + +function notInPackage(filename) { + return packageFiles.indexOf(filename) === -1; +} diff --git a/.github/workflows/scripts/print-esy-cache.js b/.github/workflows/scripts/print-esy-cache.js new file mode 100644 index 0000000..1f42fab --- /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..9c90216 --- /dev/null +++ b/.github/workflows/scripts/write-package-json.js @@ -0,0 +1,42 @@ +const fs = require("fs"); +const path = require("path"); + +const mainPackageJson = require("../../../esy.json"); +const packageJson = JSON.stringify( + { + name: mainPackageJson.name, + version: mainPackageJson.version, + license: mainPackageJson.license, + description: mainPackageJson.description, + author: mainPackageJson.author, + repository: mainPackageJson.repository, + scripts: { + postinstall: "node ./postinstall.js", + }, + publishConfig: { + access: "public", + }, + bin: mainPackageJson.esy.release.bin.reduce((acc, curr) => { + return Object.assign({ [curr]: "bin/" + curr }, acc); + }, {}), + files: [ + "platforms", + "_export/", + "bin/", + "postinstall.js", + "esyInstallRelease.js", + "LICENSE", + "README.md", + "package.json", + "package-lock.json", + ], + }, + null, + 2 +); + +fs.writeFileSync( + path.join(__dirname, "..", "..", "..", "_release", "package.json"), + packageJson, + { encoding: "utf8" } +); diff --git a/README.md b/README.md index 37e6400..f62f61e 100644 --- a/README.md +++ b/README.md @@ -51,14 +51,3 @@ https://esy.sh After you have done that, you need only run `esy build` to get the project bootstrapped. - -## Installing on Linux/Windows - -Unfortunately I haven't gotten around publishing `bsdoc` for Linux/Windows, but if you have `npm` installed you can run: - -```sh -$ esy build -$ esy npm-release -``` - -And that'll get you an npm package that you can then install locally (or globally) in any of your projects. Be mindful that it'll only work for `bs-platform@6`+ projects! diff --git a/azure-pipelines.yml b/azure-pipelines.yml deleted file mode 100644 index 46538ef..0000000 --- a/azure-pipelines.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: $(Build.BuildId) - - -trigger: - batch: true - branches: - include: - - master - - refs/tags/* - -jobs: - - template: .ci/build-platform.yml - - job: Release - displayName: Publish release - condition: startsWith(variables['build.sourceBranch'], 'refs/tags/') - dependsOn: macOS - pool: - vmImage: macOS-latest - demands: node.js - steps: - - template: .ci/cross-release.yml - - task: Npm@1 - inputs: - command: publish - workingDir: "_release" - publishEndpoint: NPM - diff --git a/esy.json b/esy.json index 4dabc59..27808e4 100644 --- a/esy.json +++ b/esy.json @@ -1,25 +1,15 @@ { "name": "bsdoc", "version": "6.0.4-alpha", - "keywords": [ - "BuckleScript", - "Odoc-driver", - "documentation", - "generation" - ], + "keywords": ["BuckleScript", "Odoc-driver", "documentation", "generation"], "author": "Leandro Ostera ", "license": "MIT", "esy": { "build": "dune build -p #{self.name}", "buildsInSource": "_build", "release": { - "bin": [ - "bsdoc" - ], - "includePackages": [ - "root", - "@opam/odoc" - ] + "bin": ["bsdoc"], + "includePackages": ["root", "@opam/odoc"] } }, "scripts": { diff --git a/yarn.lock b/yarn.lock index ffd66e3..fb57ccd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,14 +2,3 @@ # yarn lockfile v1 -"@elliottcable/bs-cmdliner@^1.0.2": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@elliottcable/bs-cmdliner/-/bs-cmdliner-1.0.2.tgz#825b3351d3beee7def38f7603b81e2a8bb73e939" - integrity sha512-jjxxtT/lJO0pQfPbxP3uZKV+E0/WVoT0f8GZvozbZXV19DdNKnFz91yERbI/VhwsY11nkqF6h5FWAWEF8lBj6Q== - dependencies: - bs-platform "^4.0.1" - -bs-platform@^4.0.1, bs-platform@^4.0.11: - version "4.0.11" - resolved "https://registry.yarnpkg.com/bs-platform/-/bs-platform-4.0.11.tgz#9d195d1ad798a60b872d7612827c70e6f4c0ed05" - integrity sha512-p0aYHXbK8ZO4ZHxwyQ1f0LEhbdkAMPB3FCwIY4HZrfrg0PB6Sc4y2L2al3kL+33sp/FOaMyfzuEnaF6HysuJgg==