Skip to content

Commit

Permalink
Merge branch 'npm-publish' into 'main'
Browse files Browse the repository at this point in the history
merge request after publish

See merge request changying/platform/xteriosdk-web!8
  • Loading branch information
clover committed Oct 28, 2024
2 parents 9ee2645 + 71e8886 commit 8c245ad
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 16 deletions.
43 changes: 43 additions & 0 deletions sh/mr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash
set - e

data=$(<sensitive.txt)
gh_token=$(echo "$data" | grep "^gh_token=" | cut -d'=' -f2)
gl_token=$(echo "$data" | grep "^gl_token=" | cut -d'=' -f2)
echo "gh_token=$gh_token"
echo "gl_token=$gl_token"

# https://github.com/chenwei0922/xterio-sdk/
# github
# githubUrl="https://api.github.com"
# owner="chenwei0922"
# repo="xterio-sdk"
# accessToken=$gh_token
# data='{
# "title": "merge request after publish",
# "head": "npm-publish",
# "base": "main"
# }'
# response=$(curl -X POST -H "Authorization: token $accessToken" -d "$data" "$githubUrl/repos/$owner/$repo/pulls")
# url=$(python3 -c "import json,sys;obj=json.loads(sys.argv[1]);print(obj['html_url'])" "$response")
# {"url":"https://api.github.com/repos/chenwei0922/xterio-sdk/pulls/3", ...}

# gitlab
gitlabUrl="https://gitlab.itlibecc.com/api/v4"
projectID="70"
accessToken=$gl_token
title="merge request after publish"
sourceBranch="npm-publish"
targetBranch="main"

response=$(curl -X POST -H "PRIVATE-TOKEN: $accessToken" -d "source_branch=$sourceBranch" -d "target_branch=$targetBranch" -d "title=$title" "$gitlabUrl/projects/70/merge_requests")
url=$(python3 -c "import json,sys;obj=json.loads(sys.argv[1]);print(obj['web_url'])" "$response")
# {"web_url":"https://gitlab.itlibecc.com/changying/platform/xteriosdk-web/-/merge_requests/7", ...}

if [ -n "$url" ] ; then
echo "[mr] Pull request created success.✅"
echo "[mr] The detail is: $url"
else
echo "[mr] Pull request created failure.❌"
echo "$response"
fi
19 changes: 12 additions & 7 deletions sh/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ async function init() {
if (isExecuteWallet) {
await publishWallet()
}
//合并分支
await run(`bash mr.sh`, pathSh)
}

const publishAuth = async () => {
Expand All @@ -42,7 +44,7 @@ const publishAuth = async () => {
updateReleaseDoc(authVersion, pathAuth)
await commitVersionFile('auth', authVersion)
// await run(`bash release.sh auth ${authVersion}`, pathSh)
await run(`bash release_new.sh auth ${authVersion} ${lines}`, pathSh)
await run(`bash release_new.sh auth ${authVersion} "${lines}"`, pathSh)
}

const publishWallet = async () => {
Expand All @@ -63,10 +65,12 @@ const publishWallet = async () => {
}
// publish success
updateReleaseDoc(walletVersion, pathWallet)
await commitVersionFile('wallet', walletVersion)
// await run(`bash release.sh wallet ${walletVersion}`, pathSh)
await run(`bash release_new.sh wallet ${walletVersion} ${lines}`, pathSh)
await run(`bash release_new.sh wallet ${walletVersion} "${lines}"`, pathSh)
//recover,复原
changeWalletPackageJson('reset')
await commitVersionFile('wallet', walletVersion)
await commitVersionFile('wallet', walletVersion, true)
}

const changeWalletPackageJson = (flag: string) => {
Expand All @@ -82,11 +86,12 @@ const changeWalletPackageJson = (flag: string) => {
}
}

const commitVersionFile = async (_f: string, _v: string) => {
const commitVersionFile = async (_f: string, _v: string, _reset?: boolean) => {
const path = _f === 'auth' ? pathAuth : pathWallet
await run(`git push origin main`)
await run(`git add . && git commit -m "feat: npm pkg(${_f}) publish(${_v})"`, path)
await run(`git push origin main`)
const msg = _reset ? `feat: recover files after publish ${_f}(${_v})` : `feat: npm pkg(${_f}) publish(${_v})`
await run(`git push origin npm-publish`)
await run(`git add . && git commit -m "${msg}"`, path)
await run(`git push origin npm-publish`)
}

const updateReleaseDoc = async (v: string, path: string) => {
Expand Down
24 changes: 16 additions & 8 deletions sh/release_new.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ set -e
pkgName=$1
version=$2
# [11,22,33] => 11,22,33 => (11 22 33)
# 将传入的逗号分隔的字符串转换为数组
result=($(echo $3 | tr ',' ' '))
# 将传入的逗号分隔的字符串转换为数组, tr可理解成replace,适合简单分割
# result=($(echo $3 | tr ',' ' '))
IFS=',' read -ra result <<< "$3"

msg=""
for item in "${result[@]}"
do
msg="$msg- $item"$'\n'
done
# echo "msg=$msg"
# exit

data=$(<sensitive.txt)
gh_token=$(echo "$data" | grep "^gh_token=" | cut -d'=' -f2)
Expand All @@ -26,12 +35,6 @@ elif [ $pkgName == "wallet" ]; then
rsync -av --exclude='node_modules' ../examples/example-wallet-react "../$prd"
fi

msg=""
for item in "${result[@]}"
do
msg="$msg- $item"$'\n'
done

cd ../
zip -r "${prd}-${version}.zip" "$prd" -x "$prd/dist/*" "$prd/coverage/*" "$prd/node_modules/*"

Expand All @@ -57,6 +60,11 @@ gh repo set-default https://github.com/XterioTech/XterioSDK-Web
# 创建一个发布
gh release create "$VERSION" --title "$TITLE" --notes "$MESSAGE" "${prd}-${version}.zip#${prd} (zip) "

# 发布特定目录到特定分支
branch=release/$pkgName/$version
git subtree split -P "$prd" -b "$branch"
git push [email protected]:XterioTech/XterioSDK-Web.git "$branch"

# 上传构建文件或者源代码文件
# gh release upload $VERSION a.zip

Expand Down
5 changes: 5 additions & 0 deletions xterio-auth/RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@
# 0.0.13
- tokens 缓存形式由cookie变更为localstorage
- 已注册尚未未验证的用户,继续进行验证

# 0.0.14
- 定制页面拓展+完善
- 新增api getOtac()
- 优化sso登录流程
2 changes: 1 addition & 1 deletion xterio-auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xterio-sdk/auth",
"version": "0.0.13",
"version": "0.0.14",
"description": "xterio-auth",
"author": "xterio platform",
"license": "ISC",
Expand Down

0 comments on commit 8c245ad

Please sign in to comment.