From 38cc5e2189ddca15c667c81749e9f3d1ffd4a8f8 Mon Sep 17 00:00:00 2001 From: Jixun Wu Date: Sat, 26 Nov 2022 19:08:08 +0000 Subject: [PATCH 01/10] chore: share the same emsdk path. --- .gitignore | 1 + src/KgmWasm/build-wasm | 10 ++++------ src/QmcWasm/build-wasm | 11 ++++------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 3d9c3e4..87b919e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .DS_Store node_modules /dist +/build /coverage # local env files diff --git a/src/KgmWasm/build-wasm b/src/KgmWasm/build-wasm index 7a9c12d..85f5658 100755 --- a/src/KgmWasm/build-wasm +++ b/src/KgmWasm/build-wasm @@ -12,16 +12,16 @@ if [ -z "$BUILD_TYPE" ]; then fi mkdir -p build/wasm -if [ ! -d build/emsdk ]; then - git clone https://github.com/emscripten-core/emsdk.git build/emsdk +if [ ! -d ../../build/emsdk ]; then + git clone https://github.com/emscripten-core/emsdk.git ../../build/emsdk fi -pushd build/emsdk +pushd ../../build/emsdk #git pull ./emsdk install 3.0.0 ./emsdk activate 3.0.0 source ./emsdk_env.sh -popd # build/emsdk +popd # ../../build/emsdk pushd build/wasm emcmake cmake -DCMAKE_BUILD_TYPE="$BUILD_TYPE" ../.. @@ -33,8 +33,6 @@ TARGET_FILES=" KgmWasmBundle.js " -#mkdir -p "${CURR_DIR}/npm" -#cp $TARGET_FILES "${CURR_DIR}/npm/" cp $TARGET_FILES "${CURR_DIR}/" popd # build/wasm diff --git a/src/QmcWasm/build-wasm b/src/QmcWasm/build-wasm index 8a9a1f3..c906fae 100755 --- a/src/QmcWasm/build-wasm +++ b/src/QmcWasm/build-wasm @@ -12,16 +12,15 @@ if [ -z "$BUILD_TYPE" ]; then fi mkdir -p build/wasm -if [ ! -d build/emsdk ]; then - git clone https://github.com/emscripten-core/emsdk.git build/emsdk +if [ ! -d ../../build/emsdk ]; then + git clone https://github.com/emscripten-core/emsdk.git ../../build/emsdk fi -pushd build/emsdk -#git pull +pushd ../../build/emsdk ./emsdk install 3.0.0 ./emsdk activate 3.0.0 source ./emsdk_env.sh -popd # build/emsdk +popd # ../../build/emsdk pushd build/wasm emcmake cmake -DCMAKE_BUILD_TYPE="$BUILD_TYPE" ../.. @@ -33,8 +32,6 @@ TARGET_FILES=" QmcWasmBundle.js " -#mkdir -p "${CURR_DIR}/npm" -#cp $TARGET_FILES "${CURR_DIR}/npm/" cp $TARGET_FILES "${CURR_DIR}/" popd # build/wasm From 892fea509ff3ca8717f2d83cdb9f5f4d59fbd0b8 Mon Sep 17 00:00:00 2001 From: Jixun Wu Date: Sat, 26 Nov 2022 19:21:30 +0000 Subject: [PATCH 02/10] test: remove invalid test and avoid jest pick up tests from emsdk folder. --- jest.config.js | 15 +++++++-------- src/decrypt/__test__/QmcCache.test.ts | 20 -------------------- 2 files changed, 7 insertions(+), 28 deletions(-) delete mode 100644 src/decrypt/__test__/QmcCache.test.ts diff --git a/jest.config.js b/jest.config.js index 0524f52..d59ea14 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,8 +1,7 @@ -module.exports = { - setupFilesAfterEnv: [ - './src/__test__/setup_jest.js' - ], - moduleNameMapper: { - '@/(.*)': '/src/$1' - } -}; +module.exports = { + testPathIgnorePatterns: ['/build/', '/dist/', '/node_modules/'], + setupFilesAfterEnv: ['./src/__test__/setup_jest.js'], + moduleNameMapper: { + '@/(.*)': '/src/$1', + }, +}; diff --git a/src/decrypt/__test__/QmcCache.test.ts b/src/decrypt/__test__/QmcCache.test.ts deleted file mode 100644 index daa729e..0000000 --- a/src/decrypt/__test__/QmcCache.test.ts +++ /dev/null @@ -1,20 +0,0 @@ -// import { DecryptBuffer as DecryptQmcCacheBuffer } from '../qmccache'; -// import fs from 'fs'; -// -// const expectedBuffer = fs.readFileSync(__dirname + '/fixture/qmc_cache_expected.bin'); -// -// const createInputBuffer = () => { -// const buffer = Buffer.alloc(256); -// for (let i = buffer.byteLength; i >= 0; i--) { -// buffer[i] = i; -// } -// return buffer; -// }; -// -// describe('decrypt/qmccache', () => { -// it('should decrypt specified buffer correctly', () => { -// const input = createInputBuffer(); -// DecryptQmcCacheBuffer(input); -// expect(input).toEqual(expectedBuffer); -// }); -// }); From 49b31301cf417a4fc1359da6a238b951448a4f67 Mon Sep 17 00:00:00 2001 From: Jixun Wu Date: Sat, 26 Nov 2022 19:59:26 +0000 Subject: [PATCH 03/10] 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" Date: Sat, 26 Nov 2022 20:02:52 +0000 Subject: [PATCH 04/10] chore: don't prefix version string with "v" in package.json. --- package.json | 4 ++-- scripts/build-and-package.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 3c10d04..8373728 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unlock-music", - "version": "v1.10.3", + "version": "1.10.3", "ext_build": 0, "updateInfo": "完善音乐标签编辑功能,支持编辑更多标签", "license": "MIT", @@ -56,4 +56,4 @@ "vue-cli-plugin-element": "^1.0.1", "vue-template-compiler": "^2.6.14" } -} +} \ No newline at end of file diff --git a/scripts/build-and-package.sh b/scripts/build-and-package.sh index 7b6c952..b947db5 100755 --- a/scripts/build-and-package.sh +++ b/scripts/build-and-package.sh @@ -5,7 +5,7 @@ set -ex cd "$(git rev-parse --show-toplevel)" VERSION="$(jq -r ".version" Date: Sat, 26 Nov 2022 20:02:56 +0000 Subject: [PATCH 05/10] chore: add nvmrc --- .nvmrc | 1 + 1 file changed, 1 insertion(+) create mode 100644 .nvmrc diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..0c19c7b --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +v16.18.1 From 9b3dfc0ed6cda03695b802b1745ae7f85dd80c83 Mon Sep 17 00:00:00 2001 From: Jixun Date: Sat, 26 Nov 2022 20:11:05 +0000 Subject: [PATCH 06/10] fix: keep dist after legacy has built --- scripts/build-and-package.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scripts/build-and-package.sh b/scripts/build-and-package.sh index b947db5..72c16e7 100755 --- a/scripts/build-and-package.sh +++ b/scripts/build-and-package.sh @@ -13,11 +13,17 @@ case "$1" in "extension") npm run make-extension ;; *) - echo "Unknown command: $1" - exit 1 - ;; + echo "Unknown command: $1" + exit 1 + ;; esac mv dist "${DIST_NAME}" zip -rJ9 "${DIST_NAME}.zip" "${DIST_NAME}" -rm -rf "${DIST_NAME}" + +if [ "$1" == "legacy" ]; then + # For upcoming extension build + mv "${DIST_NAME}" dist +else + rm -rf "${DIST_NAME}" +fi From e79728c687b744d136f7b960ad7c90fbe4c536a7 Mon Sep 17 00:00:00 2001 From: Jixun Date: Sat, 26 Nov 2022 20:11:13 +0000 Subject: [PATCH 07/10] fix: drone build script --- .drone.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.drone.yml b/.drone.yml index bcec4de..072365a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -12,20 +12,25 @@ steps: - ./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 + - ./scripts/build-and-package.sh modern - sha256sum *.zip > sha256sum.txt - name: upload - image: plugins/s3 + image: "plugins/s3" settings: - bucket: um-web + endpoint: + from_secret: S3_ENDPOINT access_key: from_secret: S3_ACCESS_KEY secret_key: from_secret: S3_SECRET_KEY + bucket: + from_secret: S3_BUCKET + region: "auto" source: | *.zip sha256sum.txt - target: /${DRONE_COMMIT_BRANCH}-latest + target: "${DRONE_REPO}/${DRONE_BUILD_NUMBER}/" + path_style: true From 3c79a1f6e2875a4cb450a9c1d8d157c5091a8a33 Mon Sep 17 00:00:00 2001 From: Jixun Date: Sat, 26 Nov 2022 20:21:43 +0000 Subject: [PATCH 08/10] fix: syntax error for compare text in shell script --- scripts/build-and-package.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build-and-package.sh b/scripts/build-and-package.sh index 72c16e7..5d8c6d7 100755 --- a/scripts/build-and-package.sh +++ b/scripts/build-and-package.sh @@ -21,7 +21,7 @@ esac mv dist "${DIST_NAME}" zip -rJ9 "${DIST_NAME}.zip" "${DIST_NAME}" -if [ "$1" == "legacy" ]; then +if [ "$1" = "legacy" ]; then # For upcoming extension build mv "${DIST_NAME}" dist else From ab2b37ba3c3861e9af34412b31a17ec397f1204f Mon Sep 17 00:00:00 2001 From: Jixun Date: Sat, 26 Nov 2022 20:34:04 +0000 Subject: [PATCH 09/10] chore: gitignore sha256sum.txt --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 232dfa7..75eba67 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ yarn-error.log* *.zip *.tar.gz +/sha256sum.txt From 278104644cc2c68dae31528c67e450c9830b7ee9 Mon Sep 17 00:00:00 2001 From: Jixun Date: Sat, 26 Nov 2022 20:59:08 +0000 Subject: [PATCH 10/10] ci: better glob for file upload --- .drone.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.drone.yml b/.drone.yml index 072365a..cb444be 100644 --- a/.drone.yml +++ b/.drone.yml @@ -16,10 +16,13 @@ steps: - ./scripts/build-and-package.sh extension - ./scripts/build-and-package.sh modern - sha256sum *.zip > sha256sum.txt + - mkdir -p upload + - mv *.zip sha256sum.txt upload/ - name: upload image: "plugins/s3" settings: + path_style: true endpoint: from_secret: S3_ENDPOINT access_key: @@ -29,8 +32,6 @@ steps: bucket: from_secret: S3_BUCKET region: "auto" - source: | - *.zip - sha256sum.txt + source: "upload/*" + strip_prefix: "upload/" target: "${DRONE_REPO}/${DRONE_BUILD_NUMBER}/" - path_style: true