feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
14
.codebase/scripts/argus-scan.sh
Normal file
14
.codebase/scripts/argus-scan.sh
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
set -ex
|
||||
|
||||
# 暂时只扫描 app-botstudio-main 项目的产物
|
||||
result=$(argus scm -c apps/bot/dist_sg/static -n obric/cloud/bot_studio_oversea -l)
|
||||
|
||||
if echo "$result" | grep -q '::add-message level=error:::'; then
|
||||
if [ "$CI" ]; then
|
||||
echo '::add-message level=info::本地验证命令:`npm install -g @ies/argus-scan@0.30.37 && REGION=sg CUSTOM_VERSION=release rush build -o app-botstudio-main && argus scm -c apps/bot/dist_sg/static -n obric/cloud/bot_studio_oversea -l`'
|
||||
fi
|
||||
exit 1
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
94
.codebase/scripts/check-file-size.sh
Normal file
94
.codebase/scripts/check-file-size.sh
Normal file
@@ -0,0 +1,94 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 设置默认值
|
||||
TARGET_BRANCH=${targetBranch}
|
||||
CI_MODE=${CI:-false}
|
||||
|
||||
# Specify the pattern you want to exclude, using *space* as the separator
|
||||
EXCLUDE_PATTERNS=(
|
||||
'**/pnpm-lock.yaml'
|
||||
'packages/arch/bot-api/src/auto-generate/**'
|
||||
'apps/bot-op/src/services/bam-auto-generate/**'
|
||||
'apps/prompt-platform/src/services/auto-generate/**'
|
||||
".cursor/api/**"
|
||||
"**/lib/**"
|
||||
"**/.*/**"
|
||||
'**/__tests__/**'
|
||||
'**/__test__/**'
|
||||
"**/__mocks__/**"
|
||||
"**/__mock__/**"
|
||||
"**/*.test.*/**"
|
||||
"**/*.spec.*/**"
|
||||
"**/__snapshots__/**"
|
||||
"**/*.snap"
|
||||
'**/e2e/**'
|
||||
'common/changes/**'
|
||||
'apps/fornax/**',
|
||||
"packages/arch/semi-theme-hand01",
|
||||
"packages/arch/arco-icon",
|
||||
"packages/arch/resources/**"
|
||||
)
|
||||
|
||||
for pattern in "${EXCLUDE_PATTERNS[@]}"; do
|
||||
EXCLUDE_STRING+=":(exclude)$pattern "
|
||||
done
|
||||
|
||||
if [ "$CI_MODE" = true ]; then
|
||||
files=$(git diff --name-only --diff-filter=AM "origin/$TARGET_BRANCH..." $EXCLUDE_STRING)
|
||||
else
|
||||
files=$(git diff --name-only --diff-filter=AM --cached $EXCLUDE_STRING)
|
||||
fi
|
||||
|
||||
# 体积限制为512KB
|
||||
size_limit=$((512))
|
||||
large_files_info=""
|
||||
|
||||
IFS=$'\n' # 处理文件名存在空格情况
|
||||
for file in $files; do
|
||||
file_size=$(wc -c <"$file" 2>/dev/null)
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "错误: 无法获取文件 '$file' 的大小"
|
||||
continue
|
||||
fi
|
||||
file_size_kb=$((file_size / 1024))
|
||||
echo "$file file size is $file_size_kb KB"
|
||||
if [ "$file_size_kb" -gt "$size_limit" ]; then
|
||||
large_files_info+="- \`$file\` ($file_size_kb KB)\n"
|
||||
fi
|
||||
done
|
||||
unset IFS
|
||||
|
||||
output_conclusion() {
|
||||
local conclusion="$1"
|
||||
echo "$conclusion" >check-file-size.log
|
||||
echo "::update-check-run::check-file-size.log"
|
||||
}
|
||||
|
||||
if [ -n "$large_files_info" ]; then
|
||||
if [ "$CI_MODE" = true ]; then
|
||||
CONCLUSION="{
|
||||
\"name\": \"文件体积\",
|
||||
\"conclusion\": \"failed\",
|
||||
\"output\": {
|
||||
\"summary\": \"<h1>错误: 文件体积过大</h1> <br /> 以下文件体积超过限制 (${size_limit}KB): \\n \\n $large_files_info \\n \\n <br /> 你可以将资源上传到CDN并通过URL使用。详情请参考此[文档](https://bytedance.larkoffice.com/wiki/MjoIwfyGyiVCBFkBgnXc8LFTniX)。<br /> 如遇紧急情况,可以联系 [@fanwenjie.fe](https://code.byted.org/fanwenjie.fe) 跳过此错误。\"
|
||||
}
|
||||
}"
|
||||
output_conclusion "$CONCLUSION"
|
||||
else
|
||||
echo "错误: 以下文件体积超过限制 (${size_limit}KB):"
|
||||
echo -e "$large_files_info"
|
||||
echo "请将大文件上传到CDN并通过URL使用。详情请参考: https://bytedance.larkoffice.com/wiki/MjoIwfyGyiVCBFkBgnXc8LFTniX"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
if [ "$CI_MODE" = true ]; then
|
||||
CONCLUSION="{
|
||||
\"name\": \"文件体积\",
|
||||
\"conclusion\": \"success\",
|
||||
\"output\": {
|
||||
\"summary\": \"GOOD\"
|
||||
}
|
||||
}"
|
||||
output_conclusion "$CONCLUSION"
|
||||
fi
|
||||
fi
|
||||
16
.codebase/scripts/check-merge-target.sh
Normal file
16
.codebase/scripts/check-merge-target.sh
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
set -ex
|
||||
|
||||
SOURCE_BRANCH=${SOURCE_BRANCH}
|
||||
TARGET_BRANCH=${targetBranch}
|
||||
|
||||
if [[ $TARGET_BRANCH == "master" && !($SOURCE_BRANCH =~ ^release/ || $SOURCE_BRANCH =~ ^hotfix/ || $SOURCE_BRANCH =~ ^task/ || $SOURCE_BRANCH =~ ^fix/) ]]; then
|
||||
# 检查$SOURCE_BRANCH是否以'release/'或'hotfix/'或'task/'或'fix/'开头
|
||||
LATEST_BRANCH="release/$(date -d '+8 hour' +%Y%m%d)"
|
||||
CONCLUSION="{\"name\": \"Target Branch\", \"conclusion\": \"failed\", \"output\":{\"summary\":\"Error: Please don't merge to master directly, use [$LATEST_BRANCH](https://code.byted.org/obric/bot-studio-monorepo/commits/$LATEST_BRANCH) instead.\n You can contact [@fanwenjie.fe](https://code.byted.org/fanwenjie.fe) to skip this error.\" }}"
|
||||
else
|
||||
CONCLUSION="{\"name\": \"Target Branch\", \"conclusion\": \"success\", \"output\":{\"summary\":\"Good Pratice\" }}"
|
||||
fi
|
||||
|
||||
echo $CONCLUSION >>check-merge-target.log
|
||||
echo "::update-check-run::check-merge-target.log"
|
||||
55
.codebase/scripts/check-mr-size.sh
Normal file
55
.codebase/scripts/check-mr-size.sh
Normal file
@@ -0,0 +1,55 @@
|
||||
#!/bin/bash
|
||||
set -ex
|
||||
|
||||
# Your target branch
|
||||
TARGET_BRANCH=$targetBranch
|
||||
|
||||
if [[ ${SOURCE_BRANCH} =~ ^integration/ || ${SOURCE_BRANCH} =~ ^release/ ]]; then
|
||||
# integration -> xxx or release/xxx -> master SKIP check-mr-size.
|
||||
echo "::add-message level=info::SKIP check-mr-size"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Specify the pattern you want to exclude, using *space* as the separator
|
||||
EXCLUDE_PATTERNS=(
|
||||
'**/pnpm-lock.yaml'
|
||||
'packages/arch/bot-api/src/auto-generate/**'
|
||||
'apps/bot-op/src/services/bam-auto-generate/**'
|
||||
'apps/prompt-platform/src/services/auto-generate/**'
|
||||
"**/lib/**"
|
||||
"**/.*/**"
|
||||
'**/__tests__/**'
|
||||
'**/__test__/**'
|
||||
"**/__mocks__/**"
|
||||
"**/__mock__/**"
|
||||
"**/*.test.*/**"
|
||||
"**/*.spec.*/**"
|
||||
"**/__snapshots__/**"
|
||||
"**/*.snap"
|
||||
'**/*.svg'
|
||||
'ee/e2e/bot-studio/**'
|
||||
'common/changes/**'
|
||||
'apps/fornax/**'
|
||||
"apps/api-builder/**"
|
||||
"packages/api-builder/**"
|
||||
)
|
||||
|
||||
for pattern in "${EXCLUDE_PATTERNS[@]}"; do
|
||||
EXCLUDE_STRING+=":(exclude)$pattern "
|
||||
done
|
||||
|
||||
# Count the number of files changed but exclude certain files and folders
|
||||
file_changes=$(git diff --name-only "origin/$TARGET_BRANCH..." $EXCLUDE_STRING | wc -l)
|
||||
|
||||
# Count the number of line changes but exclude certain files and folders
|
||||
line_changes=$(git diff --shortstat "origin/$TARGET_BRANCH..." $EXCLUDE_STRING | awk '{print ($4>$6)?$4:$6}')
|
||||
|
||||
# Check if number of changed files is greater than 100 or if number of line changes is greater than 2000
|
||||
if [ "$file_changes" -gt 100 ] || [ "$line_changes" -gt 2000 ]; then
|
||||
CONCLUSION="{\"name\": \"MR Size\", \"conclusion\": \"failed\", \"output\":{\"summary\":\"Error: Too many changes. Number of changed files is **""$file_changes""**, number of changed lines is **""$line_changes""**.\n You can contact [@fanwenjie.fe](https://code.byted.org/fanwenjie.fe) to skip this error.\" }}"
|
||||
else
|
||||
CONCLUSION="{\"name\": \"MR Size\", \"conclusion\": \"success\", \"output\":{\"summary\":\"Good\" }}"
|
||||
fi
|
||||
|
||||
echo $CONCLUSION >>check-mr-size.log
|
||||
echo "::update-check-run::check-mr-size.log"
|
||||
14
.codebase/scripts/check-pre-commits.sh
Normal file
14
.codebase/scripts/check-pre-commits.sh
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
set -ex
|
||||
|
||||
PRE_COMMITS=$1
|
||||
|
||||
# 按 codebase 给出的口径,pre commits 超过 5 时容易导致 rebase 失败,因此主动给出警告,避免进入 CQ 后被弹出
|
||||
if [ $PRE_COMMITS -gt 5 ]; then
|
||||
CONCLUSION="{\"name\": \"Pre Commits Check\", \"conclusion\": \"failed\", \"output\":{\"summary\":\"分支已落后目标分支较多,非常容易导致进入 CQ 后被弹出,请执行 rebase/merge 同步代码后重试。\" }}"
|
||||
else
|
||||
CONCLUSION="{\"name\": \"Pre Commits Check\", \"conclusion\": \"success\", \"output\":{\"summary\":\"good\" }}"
|
||||
fi
|
||||
|
||||
echo $CONCLUSION >> check-pre-commits.log
|
||||
echo "::update-check-run::check-pre-commits.log"
|
||||
54
.codebase/scripts/check-squash.sh
Normal file
54
.codebase/scripts/check-squash.sh
Normal file
@@ -0,0 +1,54 @@
|
||||
#!/bin/bash
|
||||
set -ex
|
||||
|
||||
basename=$(basename "$CHANGE_URL")
|
||||
lastParam=$(echo "$basename" | cut -d'/' -f1)
|
||||
|
||||
targetBranch="${targetBranch}"
|
||||
sourceBranch="${SOURCE_BRANCH}"
|
||||
mrTitle="${MR_TITLE}"
|
||||
mrDescription="${MR_DESCRIPTION}"
|
||||
|
||||
echo "::set-output name=mrId::$lastParam" # 输出 lastParam 的值
|
||||
|
||||
result=$(curl --location "https://code.byted.org/api/v4/projects/548801/merge_requests/$lastParam" \
|
||||
--header "Private-Token: $GITLAB_TOKEN")
|
||||
|
||||
commits=$(curl --location "https://code.byted.org/api/v4/projects/548801/merge_requests/$lastParam/commits" \
|
||||
--header "Private-Token: $GITLAB_TOKEN")
|
||||
|
||||
isSquash=$(echo "$result" | jq -r '.squash') # 使用jq提取isSquash的值
|
||||
|
||||
commitsCount=$(echo "$commits" | jq length)
|
||||
|
||||
echo "::set-output name=squash::$isSquash" # 输出 isSquash 的值
|
||||
echo "::set-output name=commitsCount::$commitsCount" # 输出 commitsCount 的值
|
||||
|
||||
if [[ $isSquash == true ]]; then
|
||||
# 勾选squash
|
||||
|
||||
if [[ $sourceBranch == release/* && $targetBranch == master ]]; then
|
||||
echo "::add-message level=error::**release 分支合入 master 时,不可开启 squash **"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $mrDescription == \[no-squash\]* ]]; then
|
||||
echo "::add-message level=error::**当前 MR 勾选了 Squash 选项,但是描述中包含[no-squash]**"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
else
|
||||
# 没有勾选squash
|
||||
|
||||
if [[ $mrDescription == \[no-squash\]* ||
|
||||
$commitsCount -le 1 ||
|
||||
$mrTitle == WIP:* ||
|
||||
$mrTitle == wip:* ||
|
||||
$sourceBranch == release/* ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "::add-message level=error::**当前 MR 应该勾选 Squash 选项**"
|
||||
exit 1
|
||||
|
||||
fi
|
||||
53
.codebase/scripts/checksum-by-change.js
Normal file
53
.codebase/scripts/checksum-by-change.js
Normal file
@@ -0,0 +1,53 @@
|
||||
const fs = require('fs/promises');
|
||||
const path = require('path');
|
||||
const crypto = require('crypto');
|
||||
|
||||
// node scripts/checksum-by-change.js /usr/changed-path.json
|
||||
// change-path 文件来自 ci
|
||||
const changedPath = process.argv[2];
|
||||
const readJson = async jsonFile => {
|
||||
const content = await fs.readFile(jsonFile, 'utf-8');
|
||||
let _val = null;
|
||||
try {
|
||||
eval(`_val = ${content}`);
|
||||
return _val;
|
||||
} catch (e) {
|
||||
console.error(`json parse failure: `, e);
|
||||
}
|
||||
};
|
||||
|
||||
const readChangedPackages = async changedPath => {
|
||||
const [changedFiles, { projects }] = await Promise.all([
|
||||
readJson(changedPath),
|
||||
readJson(path.resolve(__dirname, '../../rush.json')),
|
||||
]);
|
||||
const changedProjects = projects
|
||||
.filter(project => {
|
||||
const { projectFolder } = project;
|
||||
const endsWithSlash = projectFolder.endsWith('/');
|
||||
const compareFolder = `${projectFolder}${endsWithSlash ? '' : '/'}`;
|
||||
if (!changedFiles) {
|
||||
// changed-path.json 内容可能为null
|
||||
return true;
|
||||
}
|
||||
const matched = changedFiles.find(file => file.startsWith(compareFolder));
|
||||
return !!matched;
|
||||
})
|
||||
.map(({ packageName }) => packageName)
|
||||
.sort((r1, r2) => r1.localeCompare(r2));
|
||||
return changedProjects;
|
||||
};
|
||||
|
||||
async function main() {
|
||||
if (!changedPath || changedPath.length <= 0) {
|
||||
throw new Error(`Please pass the correct "changedPath" path`);
|
||||
}
|
||||
const changedPackages = await readChangedPackages(changedPath);
|
||||
|
||||
const hash = crypto.createHash('md5');
|
||||
changedPackages.forEach(r => hash.update(r));
|
||||
const hashValue = hash.digest('hex');
|
||||
console.log(`::set-output name=hash::${hashValue}`);
|
||||
}
|
||||
|
||||
main();
|
||||
26
.codebase/scripts/env.sh
Normal file
26
.codebase/scripts/env.sh
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
echo ::set-env name=no_proxy::cn.goofy.app,.cn.goofy.app,goofy.app,.goofy.app,localhost,.byted.org,byted.org,.bytedance.net,bytedance.net,127.0.0.1,127.0.0.0/8,169.254.0.0/16,100.64.0.0/10,172.16.0.0/12,192.168.0.0/16,10.0.0.0/8,::1,fe80::/10,fd00::/8
|
||||
echo ::set-env name=all_proxy::http://sys-proxy-rd-relay.byted.org:3128
|
||||
echo ::set-env name=http_proxy::http://sys-proxy-rd-relay.byted.org:3128
|
||||
echo ::set-env name=https_proxy::http://sys-proxy-rd-relay.byted.org:3128
|
||||
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Setup common env for CI & SCM
|
||||
# 1. 忽略不影响构建的 install
|
||||
export PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=true
|
||||
export CYPRESS_INSTALL_BINARY=0
|
||||
export TAIKO_SKIP_CHROMIUM_DOWNLOAD=0
|
||||
export CUSTOM_VERSION="inhouse"
|
||||
export RE2_DOWNLOAD_SKIP_PATH=1
|
||||
export RE2_DOWNLOAD_MIRROR="https://bnpm.bytedance.net/mirrors"
|
||||
export PUPPETEER_SKIP_DOWNLOAD=true
|
||||
|
||||
# 2. 在 CI 环境生效:
|
||||
echo ::set-env name=PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD::$PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD
|
||||
echo ::set-env name=CYPRESS_INSTALL_BINARY::$CYPRESS_INSTALL_BINARY
|
||||
echo ::set-env name=TAIKO_SKIP_CHROMIUM_DOWNLOAD::$TAIKO_SKIP_CHROMIUM_DOWNLOAD
|
||||
echo ::set-env name=RE2_DOWNLOAD_SKIP_PATH::$RE2_DOWNLOAD_SKIP_PATH
|
||||
echo ::set-env name=RE2_DOWNLOAD_MIRROR::$RE2_DOWNLOAD_MIRROR
|
||||
echo ::set-env name=PUPPETEER_SKIP_DOWNLOAD::$PUPPETEER_SKIP_DOWNLOAD
|
||||
Reference in New Issue
Block a user