Skip to content

Commit

Permalink
feat: 发布流程优化
Browse files Browse the repository at this point in the history
  • Loading branch information
chenweigh committed Nov 20, 2024
1 parent ba748e9 commit 875282c
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 18 deletions.
70 changes: 62 additions & 8 deletions sh/mr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,68 @@ 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", ...}
checkBranchDiff() {
diffResponse=$(curl -s -H "PRIVATE-TOKEN: $accessToken" "$gitlabUrl/projects/$projectID/repository/compare?from=$sourceBranch&to=$targetBranch")
diffFiles=$(echo "$diffResponse" | jq '.diffs | length')
if [ "$diffFiles" -eq 0 ]; then
return 1
else
return 0
fi
}

if [ -n "$url" ] ; then
echo "[mr] Pull request created success.✅"
echo "[mr] The detail is: $url"
iid=''
createMergeRequest() {
checkBranchDiff "$sourceBranch" "$targetBranch"
# ne不等,eq等
if [ $? -ne 0 ]; then
echo "[mr] The files have no change, cannot create mr.❌"
exit
fi
response=$(curl -X POST -H "PRIVATE-TOKEN: $accessToken" -d "source_branch=$sourceBranch" -d "target_branch=$targetBranch" -d "title=$title" "$gitlabUrl/projects/$projectID/merge_requests")
# url=$(python3 -c "import json,sys;obj=json.loads(sys.argv[1]);print(obj['web_url'])" "$response")
url=$(echo $response | jq -r '.web_url // ""')
iid=$(echo $response | jq -r '.iid // ""')
# {iid:"7", "web_url":"https://gitlab.itlibecc.com/changying/platform/xteriosdk-web/-/merge_requests/7", ...}

if [ -n "$url" ] ; then
echo "[mr] Merge Request Created Success.✅"
echo "[mr] The detail is: $url"
else
echo "[mr] Merge Request Created failure.❌"
echo "$response"
# {"message":["Another open merge request already exists for this source branch: !17"]}
result=$(echo $response | jq -r '.message[0]' | grep -o '![0-9]\+')
iid=${result:1}
fi
}
createMergeRequest

sleep 3
# 自动 merge
maxRetriesCount=3
index=1
executeMergeRequest(){
if [ $index -gt $maxRetriesCount ]; then
echo "[mr] The maximum retry exceeded the limit.❌"
return
fi
((index++))
mergeRequestIID="$1"
mergeResponse=$(curl -X PUT -H "PRIVATE-TOKEN: $accessToken" "$gitlabUrl/projects/$projectID/merge_requests/$mergeRequestIID/merge")
mergeStatus=$(echo $mergeResponse | jq -r '.state')
if [ "$mergeStatus" == "merged" ]; then
echo "[mr] Merge Request Merged Success.✅"
return 0
else
echo "[mr] Merge Request Merged Failure.❌"
echo "$mergeResponse"
executeMergeRequest "$mergeRequestIID"
fi
}
if [ -n "$iid" ] ; then
executeMergeRequest "$iid"
else
echo "[mr] Pull request created failure.❌"
echo "$response"
echo "[mr] mrId invalid.❌"
exit
fi
12 changes: 8 additions & 4 deletions sh/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ async function init() {
if (isExecuteWallet) {
await publishWallet()
}
//合并分支
await run(`bash mr.sh`, pathSh)
}

const publishAuth = async () => {
Expand All @@ -43,8 +41,10 @@ const publishAuth = async () => {
// publish success
updateReleaseDoc(authVersion, pathAuth)
await commitVersionFile('auth', authVersion)
// await run(`bash release.sh auth ${authVersion}`, pathSh)
// 发release
await run(`bash release_new.sh auth ${authVersion} "${lines}"`, pathSh)
//合分支
await run(`bash mr.sh`, pathSh)
}

const publishWallet = async () => {
Expand All @@ -66,11 +66,13 @@ const publishWallet = async () => {
// publish success
updateReleaseDoc(walletVersion, pathWallet)
await commitVersionFile('wallet', walletVersion)
// await run(`bash release.sh wallet ${walletVersion}`, pathSh)
// 发release
await run(`bash release_new.sh wallet ${walletVersion} "${lines}"`, pathSh)
//recover,复原
changeWalletPackageJson('reset')
await commitVersionFile('wallet', walletVersion, true)
//合分支
await run(`bash mr.sh`, pathSh)
}

const changeWalletPackageJson = (flag: string) => {
Expand All @@ -92,6 +94,8 @@ const commitVersionFile = async (_f: string, _v: string, _reset?: boolean) => {
await run(`git push origin npm-publish`)
await run(`git add . && git commit -m "${msg}"`, path)
await run(`git push origin npm-publish`)
await run(`git tag ${_v}-${_f}`)
await run(`git push origin --tags`)
}

const updateReleaseDoc = async (v: string, path: string) => {
Expand Down
2 changes: 1 addition & 1 deletion sh/release_new.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ MESSAGE=$msg
gh repo set-default https://github.com/XterioTech/XterioSDK-Web

# 创建一个发布
gh release create "$VERSION" --title "$TITLE" --notes "$MESSAGE" "${prd}-${version}.zip#${prd} (zip) "
gh release create "$VERSION" --title "$TITLE" --notes "$MESSAGE" "${prd}-${version}.zip#${prd} (zip) " --target main

# 发布特定目录到特定分支
branch=release/$pkgName/$version
Expand Down
2 changes: 1 addition & 1 deletion xterio-auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
- [`LoginMethodType` ](#loginmethodtype-)

# @xterio-sdk/auth
4

## 1. Install
`npm install @xterio-sdk/auth` | `yarn add @xterio-sdk/auth` | `pnpm add @xterio-sdk/auth`

Expand Down
3 changes: 0 additions & 3 deletions xterio-auth/RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,3 @@
- 定制页面拓展+完善
- 新增api getOtac()
- 优化sso登录流程

# 0.0.1-p
- test github release
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.1-p",
"version": "0.0.14",
"description": "xterio-auth",
"author": "xterio platform",
"license": "ISC",
Expand Down

0 comments on commit 875282c

Please sign in to comment.