From 64cb4774ea6a5c0589fd6944b30c6b2299f00ddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Sat, 26 Nov 2022 19:59:26 +0000 Subject: [PATCH] ci: initial experiment with ci build --- .drone.yml | 31 ++++++++++++++++++ .gitignore | 3 ++ README.md | 28 ++++++++-------- make-extension.js | 50 ++++++++++++++--------------- scripts/build-and-package.sh | 23 +++++++++++++ build-wasm => scripts/build-wasm.sh | 4 ++- 6 files changed, 99 insertions(+), 40 deletions(-) create mode 100644 .drone.yml create mode 100755 scripts/build-and-package.sh rename build-wasm => scripts/build-wasm.sh (69%) diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..bcec4de --- /dev/null +++ b/.drone.yml @@ -0,0 +1,31 @@ +--- +kind: pipeline +type: docker +name: default + +steps: + - name: build + image: node:16.18-bullseye + commands: + - apt-get update + - apt-get install -y cmake jq zip + - ./scripts/build-wasm.sh + - npm ci + - npm run test + - ./scripts/build-and-package.sh modern + - ./scripts/build-and-package.sh legacy + - ./scripts/build-and-package.sh extension + - sha256sum *.zip > sha256sum.txt + + - name: upload + image: plugins/s3 + settings: + bucket: um-web + access_key: + from_secret: S3_ACCESS_KEY + secret_key: + from_secret: S3_SECRET_KEY + source: | + *.zip + sha256sum.txt + target: /${DRONE_COMMIT_BRANCH}-latest diff --git a/.gitignore b/.gitignore index 87b919e..232dfa7 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,6 @@ yarn-error.log* /src/QmcWasm/build /src/QmcWasm/*.js /src/QmcWasm/*.wasm + +*.zip +*.tar.gz diff --git a/README.md b/README.md index c38b616..8053876 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,8 @@ ### 自行构建 -#### JS部分 - +#### JS部分 + - 环境要求 - nodejs (v16.x) - npm @@ -70,15 +70,15 @@ ```sh npm run make-extension ``` - -#### WASM部分 - -- 环境要求 - - Linux - - python3 - -- 运行此目录下的build-wasm - - ```sh - bash build-wasm - ``` + +#### WASM部分 + +- 环境要求 + - Linux + - python3 + +- 运行此目录下的build-wasm + + ```sh + ./scripts/build-wasm.sh + ``` diff --git a/make-extension.js b/make-extension.js index f03f757..eee814b 100644 --- a/make-extension.js +++ b/make-extension.js @@ -1,25 +1,25 @@ -const fs = require('fs') -const path = require('path') -const src = "./src/extension/" -const dst = "./dist" -fs.readdirSync(src).forEach(file => { - let srcPath = path.join(src, file) - let dstPath = path.join(dst, file) - fs.copyFileSync(srcPath, dstPath) - console.log(`Copy: ${srcPath} => ${dstPath}`) -}) - -const manifestRaw = fs.readFileSync("./extension-manifest.json", "utf-8") -const manifest = JSON.parse(manifestRaw) - -const pkgRaw = fs.readFileSync("./package.json", "utf-8") -const pkg = JSON.parse(pkgRaw) - -verExt = pkg["version"] -if (verExt.startsWith("v")) verExt = verExt.slice(1) -if (verExt.includes("-")) verExt = verExt.split("-")[0] -manifest["version"] = `${verExt}.${pkg["ext_build"]}` -manifest["version_name"] = pkg["version"] - -fs.writeFileSync("./dist/manifest.json", JSON.stringify(manifest), "utf-8") -console.log("Write: manifest.json") +const fs = require('fs') +const path = require('path') +const src = __dirname + "/src/extension/" +const dst = __dirname + "/dist" +fs.readdirSync(src).forEach(file => { + let srcPath = path.join(src, file) + let dstPath = path.join(dst, file) + fs.copyFileSync(srcPath, dstPath) + console.log(`Copy: ${srcPath} => ${dstPath}`) +}) + +const manifestRaw = fs.readFileSync(__dirname + "/extension-manifest.json", "utf-8") +const manifest = JSON.parse(manifestRaw) + +const pkgRaw = fs.readFileSync(__dirname + "/package.json", "utf-8") +const pkg = JSON.parse(pkgRaw) + +verExt = pkg["version"] +if (verExt.startsWith("v")) verExt = verExt.slice(1) +if (verExt.includes("-")) verExt = verExt.split("-")[0] +manifest["version"] = `${verExt}.${pkg["ext_build"]}` +manifest["version_name"] = pkg["version"] + +fs.writeFileSync(__dirname + "/dist/manifest.json", JSON.stringify(manifest), "utf-8") +console.log("Write: manifest.json") diff --git a/scripts/build-and-package.sh b/scripts/build-and-package.sh new file mode 100755 index 0000000..7b6c952 --- /dev/null +++ b/scripts/build-and-package.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +set -ex + +cd "$(git rev-parse --show-toplevel)" + +VERSION="$(jq -r ".version"