diff --git a/sh/mr.sh b/sh/mr.sh index faf109c..cb55ffe 100644 --- a/sh/mr.sh +++ b/sh/mr.sh @@ -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 \ No newline at end of file diff --git a/sh/publish.ts b/sh/publish.ts index 1988dc1..4fea6a2 100644 --- a/sh/publish.ts +++ b/sh/publish.ts @@ -22,8 +22,6 @@ async function init() { if (isExecuteWallet) { await publishWallet() } - //合并分支 - await run(`bash mr.sh`, pathSh) } const publishAuth = async () => { @@ -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 () => { @@ -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) => { @@ -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) => { diff --git a/sh/release_new.sh b/sh/release_new.sh index baaf414..506c54c 100644 --- a/sh/release_new.sh +++ b/sh/release_new.sh @@ -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 diff --git a/xterio-auth/README.md b/xterio-auth/README.md index c9925e5..32bd563 100644 --- a/xterio-auth/README.md +++ b/xterio-auth/README.md @@ -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` diff --git a/xterio-auth/RELEASE.md b/xterio-auth/RELEASE.md index 22fb14f..99e3b35 100644 --- a/xterio-auth/RELEASE.md +++ b/xterio-auth/RELEASE.md @@ -16,6 +16,3 @@ - 定制页面拓展+完善 - 新增api getOtac() - 优化sso登录流程 - -# 0.0.1-p -- test github release diff --git a/xterio-auth/package.json b/xterio-auth/package.json index 22c7cc3..4dd385b 100644 --- a/xterio-auth/package.json +++ b/xterio-auth/package.json @@ -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",