From d733dba221423c48059f6efd2d29b1c30166aa46 Mon Sep 17 00:00:00 2001 From: Jixun Date: Sat, 26 Nov 2022 23:52:48 +0000 Subject: [PATCH 1/6] ci: upload to gitea packages instead of s3 --- .drone.yml | 28 +++++++++------------------- scripts/upload-packages.sh | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 19 deletions(-) create mode 100644 scripts/upload-packages.sh diff --git a/.drone.yml b/.drone.yml index cb444be..4e84fe6 100644 --- a/.drone.yml +++ b/.drone.yml @@ -15,23 +15,13 @@ steps: - ./scripts/build-and-package.sh legacy - ./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: - from_secret: S3_ACCESS_KEY - secret_key: - from_secret: S3_SECRET_KEY - bucket: - from_secret: S3_BUCKET - region: "auto" - source: "upload/*" - strip_prefix: "upload/" - target: "${DRONE_REPO}/${DRONE_BUILD_NUMBER}/" + - name: upload artifact + image: busybox:1.34-glibc + environment: + DRONE_GITEA_SERVER: https://git.unlock-music.dev + GITEA_API_KEY: + from_secret: GITEA_API_KEY + commands: + - apt-get update && apt-get install -y curl + - ./scripts/upload-packages.sh diff --git a/scripts/upload-packages.sh b/scripts/upload-packages.sh new file mode 100644 index 0000000..d2ef758 --- /dev/null +++ b/scripts/upload-packages.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +set -ex + +cd "$(git rev-parse --show-toplevel)" + +URL_BASE="$DRONE_GITEA_SERVER/api/packages/${DRONE_REPO_NAMESPACE}/generic/${DRONE_REPO_NAME}-build" + +for ZIP_NAME in *.zip; do + UPLOAD_URL="${URL_BASE}/${DRONE_BUILD_NUMBER}/${ZIP_NAME}" + sha256sum "${ZIP_NAME}" + curl -sLifu "um-release-bot:$GITEA_API_KEY" -T "${ZIP_NAME}" "${UPLOAD_URL}" + echo "Uploaded to: ${UPLOAD_URL}" +done From 9b76ef295934b44c4ec62aed16ae26da2a6cf31f Mon Sep 17 00:00:00 2001 From: Jixun Date: Sun, 27 Nov 2022 00:17:41 +0000 Subject: [PATCH 2/6] ci: mark upload script as executable --- scripts/upload-packages.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/upload-packages.sh diff --git a/scripts/upload-packages.sh b/scripts/upload-packages.sh old mode 100644 new mode 100755 From ff06c817350d2e8e2608643aa3b8028a6811e03b Mon Sep 17 00:00:00 2001 From: Jixun Date: Sun, 27 Nov 2022 00:26:21 +0000 Subject: [PATCH 3/6] ci: specify debian image + set dependency --- .drone.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index 4e84fe6..925f970 100644 --- a/.drone.yml +++ b/.drone.yml @@ -17,11 +17,11 @@ steps: - ./scripts/build-and-package.sh modern - name: upload artifact - image: busybox:1.34-glibc + image: debian:bullseye-20221114 environment: DRONE_GITEA_SERVER: https://git.unlock-music.dev GITEA_API_KEY: from_secret: GITEA_API_KEY commands: - - apt-get update && apt-get install -y curl + - apt-get update && apt-get install -y curl git - ./scripts/upload-packages.sh From 1fc71429571543188e534e9476fcfe3ab1565fe6 Mon Sep 17 00:00:00 2001 From: Jixun Date: Sun, 27 Nov 2022 00:38:13 +0000 Subject: [PATCH 4/6] ci: use emsdk instead of download emsdk each build. --- .drone.yml | 8 ++++++-- src/KgmWasm/build-wasm | 32 +++++++++++++++++--------------- src/QmcWasm/build-wasm | 31 +++++++++++++++++-------------- 3 files changed, 40 insertions(+), 31 deletions(-) diff --git a/.drone.yml b/.drone.yml index 925f970..7021d95 100644 --- a/.drone.yml +++ b/.drone.yml @@ -4,12 +4,16 @@ type: docker name: default steps: + - name: build-wasm + image: emscripten/emsdk:3.0.0 + commands: + - ./scripts/build-wasm.sh + - name: build image: node:16.18-bullseye commands: - apt-get update - - apt-get install -y cmake jq zip - - ./scripts/build-wasm.sh + - apt-get install -y jq zip - npm ci - npm run test - ./scripts/build-and-package.sh legacy diff --git a/src/KgmWasm/build-wasm b/src/KgmWasm/build-wasm index 85f5658..599b97c 100755 --- a/src/KgmWasm/build-wasm +++ b/src/KgmWasm/build-wasm @@ -8,29 +8,31 @@ CURR_DIR="${PWD}" BUILD_TYPE="$1" if [ -z "$BUILD_TYPE" ]; then - BUILD_TYPE=Release + BUILD_TYPE=Release fi -mkdir -p build/wasm -if [ ! -d ../../build/emsdk ]; then - git clone https://github.com/emscripten-core/emsdk.git ../../build/emsdk +# CI: already had emsdk installed. +if ! command -v emcc; then + if [ ! -d ../../build/emsdk ]; then + git clone https://github.com/emscripten-core/emsdk.git ../../build/emsdk + fi + + pushd ../../build/emsdk + ./emsdk install 3.0.0 + ./emsdk activate 3.0.0 + source ./emsdk_env.sh + popd # ../../build/emsdk fi -pushd ../../build/emsdk -#git pull -./emsdk install 3.0.0 -./emsdk activate 3.0.0 -source ./emsdk_env.sh -popd # ../../build/emsdk - +mkdir -p build/wasm pushd build/wasm emcmake cmake -DCMAKE_BUILD_TYPE="$BUILD_TYPE" ../.. make -j TARGET_FILES=" - KgmLegacy.js - KgmWasm.js - KgmWasm.wasm - KgmWasmBundle.js + KgmLegacy.js + KgmWasm.js + KgmWasm.wasm + KgmWasmBundle.js " cp $TARGET_FILES "${CURR_DIR}/" diff --git a/src/QmcWasm/build-wasm b/src/QmcWasm/build-wasm index c906fae..4cd1640 100755 --- a/src/QmcWasm/build-wasm +++ b/src/QmcWasm/build-wasm @@ -8,28 +8,31 @@ CURR_DIR="${PWD}" BUILD_TYPE="$1" if [ -z "$BUILD_TYPE" ]; then - BUILD_TYPE=Release + BUILD_TYPE=Release fi -mkdir -p build/wasm -if [ ! -d ../../build/emsdk ]; then - git clone https://github.com/emscripten-core/emsdk.git ../../build/emsdk +# CI: already had emsdk installed. +if ! command -v emcc; then + if [ ! -d ../../build/emsdk ]; then + git clone https://github.com/emscripten-core/emsdk.git ../../build/emsdk + fi + + pushd ../../build/emsdk + ./emsdk install 3.0.0 + ./emsdk activate 3.0.0 + source ./emsdk_env.sh + popd # ../../build/emsdk fi -pushd ../../build/emsdk -./emsdk install 3.0.0 -./emsdk activate 3.0.0 -source ./emsdk_env.sh -popd # ../../build/emsdk - +mkdir -p build/wasm pushd build/wasm emcmake cmake -DCMAKE_BUILD_TYPE="$BUILD_TYPE" ../.. make -j TARGET_FILES=" - QmcLegacy.js - QmcWasm.js - QmcWasm.wasm - QmcWasmBundle.js + QmcLegacy.js + QmcWasm.js + QmcWasm.wasm + QmcWasmBundle.js " cp $TARGET_FILES "${CURR_DIR}/" From 26e50473f223e1bdde0c69c4d39f6652a8cf66dc Mon Sep 17 00:00:00 2001 From: Jixun Date: Sun, 27 Nov 2022 00:43:37 +0000 Subject: [PATCH 5/6] ci: skip upload step when api key is empty (usually happens for PR) --- scripts/upload-packages.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/upload-packages.sh b/scripts/upload-packages.sh index d2ef758..06c3d43 100755 --- a/scripts/upload-packages.sh +++ b/scripts/upload-packages.sh @@ -4,11 +4,16 @@ set -ex cd "$(git rev-parse --show-toplevel)" +if [ -z "$GITEA_API_KEY" ]; then + echo "GITEA_API_KEY is empty, skip upload." + exit 0 +fi + URL_BASE="$DRONE_GITEA_SERVER/api/packages/${DRONE_REPO_NAMESPACE}/generic/${DRONE_REPO_NAME}-build" for ZIP_NAME in *.zip; do - UPLOAD_URL="${URL_BASE}/${DRONE_BUILD_NUMBER}/${ZIP_NAME}" - sha256sum "${ZIP_NAME}" - curl -sLifu "um-release-bot:$GITEA_API_KEY" -T "${ZIP_NAME}" "${UPLOAD_URL}" - echo "Uploaded to: ${UPLOAD_URL}" + UPLOAD_URL="${URL_BASE}/${DRONE_BUILD_NUMBER}/${ZIP_NAME}" + sha256sum "${ZIP_NAME}" + curl -sLifu "um-release-bot:$GITEA_API_KEY" -T "${ZIP_NAME}" "${UPLOAD_URL}" + echo "Uploaded to: ${UPLOAD_URL}" done From 70c78772ec80339a666e13e086db0f774b2752b4 Mon Sep 17 00:00:00 2001 From: Jixun Date: Sun, 27 Nov 2022 00:45:15 +0000 Subject: [PATCH 6/6] ci: use same node image to skip dependency install. --- .drone.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index 7021d95..72763ef 100644 --- a/.drone.yml +++ b/.drone.yml @@ -21,11 +21,10 @@ steps: - ./scripts/build-and-package.sh modern - name: upload artifact - image: debian:bullseye-20221114 + image: node:16.18-bullseye environment: DRONE_GITEA_SERVER: https://git.unlock-music.dev GITEA_API_KEY: from_secret: GITEA_API_KEY commands: - - apt-get update && apt-get install -y curl git - ./scripts/upload-packages.sh