From a9e5c16949ddc9f61c792ff0430a7d2b0dcbe85b Mon Sep 17 00:00:00 2001 From: Jixun Wu Date: Fri, 9 Jun 2023 01:00:57 +0100 Subject: [PATCH 1/5] fix: build issue with libparakeet --- src/dummy.mjs | 1 + vite.config.ts | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 src/dummy.mjs diff --git a/src/dummy.mjs b/src/dummy.mjs new file mode 100644 index 0000000..a7764dc --- /dev/null +++ b/src/dummy.mjs @@ -0,0 +1 @@ +// This is a dummy module for vite/rollup to resolve. diff --git a/vite.config.ts b/vite.config.ts index 604789d..e20f3fb 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -23,6 +23,9 @@ const version = `${pkg.version}-${shortCommit}`; // https://vitejs.dev/config/ export default defineConfig({ + worker: { + format: 'es', + }, server: { fs: { // Note: @@ -85,6 +88,7 @@ export default defineConfig({ resolve: { alias: { '~': path.resolve(__dirname, 'src'), + module: path.resolve(__dirname, 'src', 'dummy.mjs'), }, }, build: { From c579fb1928da7715e78ef1337bfdcbc29c6a1a11 Mon Sep 17 00:00:00 2001 From: Jixun Wu Date: Fri, 9 Jun 2023 01:01:41 +0100 Subject: [PATCH 2/5] ci: get started on ci build --- .drone.yml | 30 ++++++++++++++++++++++ .gitignore | 4 +++ scripts/deploy.sh | 63 ++++++++++++++++++++++++++++++++++++++++++++++ scripts/publish.sh | 21 ++++++++++++++++ 4 files changed, 118 insertions(+) create mode 100644 .drone.yml create mode 100755 scripts/deploy.sh create mode 100755 scripts/publish.sh diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..f82f0b5 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,30 @@ +--- +kind: pipeline +type: docker +name: default + +steps: + - name: test & build + image: node:18.16.0-bullseye + commands: + # - git config --global --add safe.directory "/drone/src" + - npm install -g pnpm + - pnpm i --frozen-lockfile + - pnpm build + + - name: publish + image: node:18.16.0-bullseye + environment: + DRONE_GITEA_SERVER: https://git.unlock-music.dev + GITEA_API_KEY: + from_secret: GITEA_API_KEY + NETLIFY_SITE_ID: + from_secret: NETLIFY_SITE_ID + NETLIFY_API_KEY: + from_secret: NETLIFY_API_KEY + commands: + # - git config --global --add safe.directory "/drone/src" + - apt-get update && apt-get install -y zip jq tar gzip curl + - (cd dist && zip -r -9 ../um-react.zip .) + - ./scripts/publish.sh + - ./scripts/deploy.sh diff --git a/.gitignore b/.gitignore index 6cf4bce..19fa33e 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,7 @@ dist-ssr *.njsproj *.sln *.sw? + +# Files created when running "drone exec" locally +/.pnpm-store/ +/*.zip diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100755 index 0000000..22aa4f4 --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,63 @@ +#!/bin/bash -ex + +BRANCH_NAME="$(git branch --show-current)" + +__netlify_upload() { + curl -sL \ + -H "Content-Type: application/zip" \ + -H "Authorization: Bearer ${NETLIFY_API_KEY}" \ + --data-binary "@${1}" \ + "https://api.netlify.com/api/v1/sites/${NETLIFY_SITE_ID}/deploys?branch=${BRANCH_NAME}" +} + +__netlify_get_deploy() { + local deploy_id="$1" + curl -sL \ + -H "Authorization: Bearer ${NETLIFY_API_KEY}" \ + "https://api.netlify.com/api/v1/deploys/${deploy_id}" +} + +deploy_netlify() { + local upload_resp + upload_resp="$(__netlify_upload "$1")" + + local error_message="$(echo "$upload_resp" | jq -r ".message // .error_message")" + if [[ "$error_message" != "null" ]]; then + echo "Deploy to netlify failed:" + echo " * ${error_message}" + return 1 + fi + + local deploy_id="$(echo "$upload_resp" | jq -r ".id")" + local deploy_resp="" + local deploy_state="" + local retry_count=10 + while [[ "$retry_count" -gt 0 ]]; do + deploy_resp="$(__netlify_get_deploy "$deploy_id")" + deploy_state="$(echo "$deploy_resp" | jq -r '.state')" + case "$deploy_state" in + ready) + echo 'Deploy to netlify OK!' + echo " * main url: $(echo "$deploy_resp" | jq -r '.ssl_url')" + echo " * branch: $(echo "$deploy_resp" | jq -r '.deploy_ssl_url')" + echo " * permalink: $(echo "$deploy_resp" | jq -r '.links.permalink')" + return 0 + ;; + error) + echo "Deploy to netlify failed:" + echo " * $(echo "$deploy_resp" | jq -r '.error_message')" + return 1 + ;; + *) + retry_count="$((retry_count - 1))" + sleep 3 + ;; + esac + done +} + +# For deployment, we care a bit less +if [[ -n "${NETLIFY_API_KEY}" && -n "${NETLIFY_SITE_ID}" ]]; then + echo "Deploy to netlify..." + deploy_netlify um-react.zip +fi diff --git a/scripts/publish.sh b/scripts/publish.sh new file mode 100755 index 0000000..2c1ceba --- /dev/null +++ b/scripts/publish.sh @@ -0,0 +1,21 @@ +#!/bin/bash -ex + +BRANCH_NAME="$(git branch --show-current)" + +publish_gitea() { + local ZIP_NAME="$1" + local URL="${DRONE_GITEA_SERVER}/api/packages/${DRONE_REPO_NAMESPACE}/generic/${DRONE_REPO_NAME}/${DRONE_BUILD_NUMBER}/${ZIP_NAME}" + sha256sum "${ZIP_NAME}" + curl -sLifu "um-release-bot:${GITEA_API_KEY}" -T "${ZIP_NAME}" "${URL}" + echo "Uploaded to: ${URL}" +} + +# Only publish main branch by default +if [[ "${BRANCH_NAME}" = "main" ]]; then + echo 'prepare to publish...' + + if [[ -n "${GITEA_API_KEY}" ]]; then + echo "Publish to gitea..." + publish_gitea "um-react.zip" + fi +fi From b66eea4069913fc1be3a657646a3bb34557ca173 Mon Sep 17 00:00:00 2001 From: Jixun Wu Date: Fri, 9 Jun 2023 01:10:37 +0100 Subject: [PATCH 3/5] ci: hide verbose logging from publish/deploy --- scripts/deploy.sh | 2 +- scripts/publish.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 22aa4f4..bb67ce9 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -1,4 +1,4 @@ -#!/bin/bash -ex +#!/bin/bash -e BRANCH_NAME="$(git branch --show-current)" diff --git a/scripts/publish.sh b/scripts/publish.sh index 2c1ceba..e5325eb 100755 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -1,4 +1,4 @@ -#!/bin/bash -ex +#!/bin/bash -e BRANCH_NAME="$(git branch --show-current)" From 8d7f16b231c8eb8efe63b7803d01c03b790517a9 Mon Sep 17 00:00:00 2001 From: Jixun Wu Date: Fri, 9 Jun 2023 01:17:07 +0100 Subject: [PATCH 4/5] ci: main branch should be considered as prod deployment --- scripts/deploy.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index bb67ce9..7f4b2b4 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -3,11 +3,15 @@ BRANCH_NAME="$(git branch --show-current)" __netlify_upload() { + local production="$DEPLOY_PRODUCTION" + [[ -z "$production" ]] && production="false" + [[ "$BRANCH_NAME" = "main" ]] && production="true" + curl -sL \ -H "Content-Type: application/zip" \ -H "Authorization: Bearer ${NETLIFY_API_KEY}" \ --data-binary "@${1}" \ - "https://api.netlify.com/api/v1/sites/${NETLIFY_SITE_ID}/deploys?branch=${BRANCH_NAME}" + "https://api.netlify.com/api/v1/sites/${NETLIFY_SITE_ID}/deploys?branch=${BRANCH_NAME}&production=${production}" } __netlify_get_deploy() { From 421fb7c23920f5cfa4b2c8b56940a45a370f7aa7 Mon Sep 17 00:00:00 2001 From: Jixun Wu Date: Fri, 9 Jun 2023 01:20:30 +0100 Subject: [PATCH 5/5] docs: add ci badge & update artifact url --- README.MD | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.MD b/README.MD index ae8e9d2..3307685 100644 --- a/README.MD +++ b/README.MD @@ -1,15 +1,17 @@ # Unlock Music 音乐解锁 (React) +[![Build Status](https://ci.unlock-music.dev/api/badges/um/um-react/status.svg)](https://ci.unlock-music.dev/um/um-react) + - 在浏览器中解锁加密的音乐文件。 Unlock encrypted music file in the browser. - Unlock Music 项目是以学习和技术研究的初衷创建的,修改、再分发时请遵循[授权协议]。 - Unlock Music 的 CLI 版本可以在 [unlock-music/cli] 找到,大批量转换建议使用 CLI 版本。 - 我们新建了 Telegram 群组 [`@unlock_music_chat`] ,欢迎加入! -- ~~CI 自动构建已经部署,可以在 [UM-Packages] 下载~~ 目前还没有自动构建 +- CI 自动构建已经部署,可以在 [Packages][um-react-packages] 下载 目前还没有自动构建 [授权协议]: https://git.unlock-music.dev/um/um-react/src/branch/main/LICENSE [unlock-music/cli]: https://git.unlock-music.dev/um/cli [`@unlock_music_chat`]: https://t.me/unlock_music_chat -[UM-Packages]: https://git.unlock-music.dev/um/-/packages/generic/web-build/ +[um-react-packages]: https://git.unlock-music.dev/um/-/packages/generic/um-react/ ## 支持的格式