netease-music-cli/scripts/publish.sh
2026-10-02 07:29:09 +08:00

41 lines
1.6 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/sh
# 发布镜像:把本技能目录整体发布成公开仓库(生成物,整体覆盖;不要在镜像仓手工改)。
# 用法:scripts/publish.sh [--dry-run]
# 远端:NETEASE_MUSIC_PUBLISH_REMOTES(空格分隔);默认两个 gitea 远端。
set -eu
here="$(cd "$(dirname "$0")/.." && pwd)"
version="$(cat "$here/VERSION")"
dry=0
ok=0; failed=0
[ "${1:-}" = "--dry-run" ] && dry=1
remotes="${NETEASE_MUSIC_PUBLISH_REMOTES:-git@gitea.gklazycat.heiyu.space:geekinney/netease-music-cli.git https://gitea.vhkd.top/geekinney/netease-music-cli.git}"
# 门禁:先过测试再发布。
(cd "$here" && node --test tests/*.test.mjs >/dev/null)
for remote in $remotes; do
work="$(mktemp -d)"
if git clone --quiet "$remote" "$work/repo" 2>/dev/null; then
cd "$work/repo"
else
mkdir -p "$work/repo"; cd "$work/repo"; git init -q; git remote add origin "$remote"
fi
rsync -a --delete --exclude '.git' --exclude '__pycache__' --exclude 'tests/.runtime-*' "$here/" "$work/repo/"
git add -A
if git diff --cached --quiet; then
printf 'no changes for %s\n' "$remote"
else
git commit -q -m "release v$version"
fi
if [ "$dry" = 1 ]; then
printf 'dry-run: would push %s\n' "$remote"
elif git push -q origin HEAD:main 2>/dev/null || git push -q --set-upstream origin HEAD:main 2>/dev/null; then
printf 'published v%s -> %s\n' "$version" "$remote"
ok=$((ok + 1))
else
printf 'push failed: %s(仓库没建?凭据?)\n' "$remote"
failed=$((failed + 1))
fi
cd "$here"; rm -rf "$work"
done
[ "$ok" -gt 0 ] || exit 1
printf 'remotes ok=%s failed=%s\n' "$ok" "$failed"