From d5d1318e20e4379f32d53c8656c4023a56abd1ba Mon Sep 17 00:00:00 2001 From: gordonwwang Date: Wed, 19 Jul 2023 22:17:18 +0800 Subject: [PATCH] 1. Function splitting: Perform rpm-dep query first, and then reprogram the software package. 2. When the software package is recompiled, the recompiled package is removed from pkg_name.log and added to pkg_success. 3. Add a print prompt to let users check pkg_name.log; 4. Shield git pull/push code and redundant prompts when raising PR; --- auto_release_increases/README.md | 12 ++- auto_release_increases/auto_dep.sh | 68 +++++++++++++++ auto_release_increases/auto_release.sh | 112 +++++++------------------ 3 files changed, 106 insertions(+), 86 deletions(-) create mode 100755 auto_release_increases/auto_dep.sh diff --git a/auto_release_increases/README.md b/auto_release_increases/README.md index c23f60e..1290eb7 100644 --- a/auto_release_increases/README.md +++ b/auto_release_increases/README.md @@ -18,10 +18,14 @@ #### 使用说明 -1. 新建一个rpm包名单,用于查询哪些包依赖到了名单中的rpm。例如升级了llvm, 而它的rpm子包有llvm-devel、llvm-libs、llvm-test,则新建rpm_list0,逐行填入这仨rpm包; -2. sh auto_release.sh rpm_list0; -3. 如果已经rpm-dep查询过,得到了pkg_name.log文件。则无需传参rpm_list0,直接执行sh auto_release.sh; -4. 如果不需要提PR,请注释handle_pkgs中的PR_repo函数。 +1. 新建一个rpm子包名单,用于查询哪些包依赖到了名单中的rpm。例如升级了llvm, 而它的rpm子包有llvm-devel、llvm-libs、llvm-test,则新建rpm_list0,逐行填入这仨rpm包; +2. `sh auto_dep.sh rpm_list0`; 根据步骤1名单,查询得到**待重编的软件包名单 pkg_name.log**. +3. `sh auto_release.sh`; 对pkg_name.log中所有的软件包,一键重编并提PR。**使用此脚本前,请仔细确认pkg_name.log!!!避免提交不合理的PR。** + + 执行`sh auto_release.sh`后,若中途失败,**pkg_success中是重编成功的包**;**pkg_name.log是重编失败/尚未重编的包**。 + + 重新执行`sh auto_release.sh`命令,即可继续对**pkg_name.log中重编失败/尚未重编的包**进行重编。若一直失败,请检查该软件包! + #### 参与贡献 diff --git a/auto_release_increases/auto_dep.sh b/auto_release_increases/auto_dep.sh new file mode 100755 index 0000000..7899174 --- /dev/null +++ b/auto_release_increases/auto_dep.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +file_in=$1 +file_out="pkg_name.log" +file_tmp="tmp.log" +# 初始化一个空数组用于存储 "level: 1" 的包名 +src_names=() + +function rpm_dep_list() +{ + if [ $(cat "$file_in" | wc -l) -eq 0 ]; then + echo "WARNNING: input file rpm_list is NULL." + exit 1 + fi + cat $file_in | xargs -I {} rpm-dep -B {} -t yaml -l 2 + # 单纯的安装依赖,应该无需重编 + # cat $file_in | xargs -I {} rpm-dep -I {} + + if [ $? -eq 0 ]; then + echo "====== rpm_dep successful ======" + fi +} + +function rpm_dep_list_clean() +{ + rm dep* +} + +function get_list() +{ + # 清空或创建 file_out 文件 + rm -f $file_out + :> $file_out + :> $file_tmp + + # 查找 yaml + yaml_files=$(ls | grep -E '\.yaml$') + + # 遍历 yaml + for file in $yaml_files; do + # 提取 "level: 1" 的包名 + level1_package=$(cat $file | grep -A 2 "level: 1" | grep "src_name:" | awk '{print $2}') + src_names+=("$level1_package") + # 提取 "level: 2" 的包名 + cat $file | grep -A 2 "level: 2" | grep "src_name:" | awk '{print $2}' >> $file_tmp + done + # cat $file_tmp | sort -u > $file_out + sort -u $file_tmp -o $file_tmp + + # 过滤掉 "level: 1" 的包名,源码包本身 无需重编 + for src_name in "${src_names[@]}"; do + grep -v "^$src_name$" $file_tmp > $file_out + done + + rm -f $file_tmp +} + +# 如果传入参数1,需要执行rpm_dep查询,得到file_out(待release +1软件包名单) +if [ "$#" -ge 1 ]; then + rpm_dep_list + get_list + rpm_dep_list_clean + echo -e "\033[1;31m [Note: Before using auto_release.sh, please check pkg_name.log!!!] \033[0m" +elif [ $(cat "$file_out" | wc -l) -eq 0 ]; then + echo "WARNNING: $file_out is NULL, no package." +else + echo "ERROR: No arguments provided. Skipping rpm_dep function." +fi diff --git a/auto_release_increases/auto_release.sh b/auto_release_increases/auto_release.sh index 6926773..6abf5c5 100755 --- a/auto_release_increases/auto_release.sh +++ b/auto_release_increases/auto_release.sh @@ -17,57 +17,28 @@ gitee_api="https://gitee.com/api/v5" file_in=$1 file_out="pkg_name.log" file_tmp="tmp.log" -# 初始化一个空数组用于存储 "level: 1" 的包名 -src_names=() +file_success="pkg_success" -function rpm_dep_list() +## 1. 从ocs代码仓,fork仓库并clone到本地 +function fork_clone_repo() { - if [ $(cat "$file_in" | wc -l) -eq 0 ]; then - echo "WARNNING: input file rpm_list is NULL." - exit 1 - fi - cat $file_in | xargs -I {} rpm-dep -B {} -t yaml - # 单纯的安装依赖,应该无需重编 - # cat $file_in | xargs -I {} rpm-dep -I {} - - if [ $? -eq 0 ]; then - echo "====== rpm_dep successful ======" - fi -} + gitee_repo=$1 + gitee_api="https://gitee.com/api/v5" -function rpm_dep_list_clean() -{ - rm dep* -} + # Fork repo + fork_result=$(curl -s -X POST -u "${gitee_username}:${gitee_tocken}" "${gitee_api}/repos/opencloudos-stream/${gitee_repo}/forks") -function get_list() -{ - # 清空或创建 file_out 文件 - :> $file_out - :> $file_tmp - - # 查找 yaml - yaml_files=$(ls | grep -E '\.yaml$') - - # 遍历 yaml - for file in $yaml_files; do - # 提取 "level: 1" 的包名 - level1_package=$(cat $file | grep -A 2 "level: 1" | grep "src_name:" | awk '{print $2}') - src_names+=("$level1_package") - # 提取 "level: 2" 的包名 - cat $file | grep -A 2 "level: 2" | grep "src_name:" | awk '{print $2}' >> $file_tmp - done - # cat $file_tmp | sort -u > $file_out - sort -u $file_tmp -o $file_tmp - - # 过滤掉 "level: 1" 的包名,源码包本身 无需重编 - for src_name in "${src_names[@]}"; do - grep -v "^$src_name$" $file_tmp > $file_out - done - - rm $file_tmp + # check Fork + if echo "$fork_result" | grep -q "\"path\":\"${gitee_repo}\""; then + echo "====== Forked repository successfully.${gitee_repo} ======" + else + echo "###### Failed to fork repository.${gitee_repo}.$fork_result ######" + fi + + git clone "https://gitee.com/${gitee_username}/${gitee_repo}.git" --quiet } +## 2. 修改spec文件,Release+1和changelog function modi_spec() { pkg_name="$1" @@ -93,30 +64,9 @@ function modi_spec() spec_version=$(rpmspec -P $pkg_spec | grep -iw "version:" | awk '{print $2}' | awk 'NR==1{print}') sed -i "s/%changelog/%changelog\n* $week_num $month_num $date_num $year_num $commit_auth - $spec_version-$new_release\n- $commit_info\n/g" $pkg_spec fi - - if [ $? -eq 0 ]; then - echo "====== modi_spec successful.${gitee_repo} ======" - fi -} - -function fork_clone_repo() -{ - gitee_repo=$1 - gitee_api="https://gitee.com/api/v5" - - # Fork repo - fork_result=$(curl -X POST -u "${gitee_username}:${gitee_tocken}" "${gitee_api}/repos/opencloudos-stream/${gitee_repo}/forks") - - # check Fork - if echo "$fork_result" | grep -q "\"path\":\"${gitee_repo}\""; then - echo "====== Forked repository successfully.${gitee_repo} ======" - else - echo "###### Failed to fork repository.${gitee_repo}.$fork_result ######" - fi - - git clone "https://gitee.com/${gitee_username}/${gitee_repo}.git" } +## 3. commit、push本地代码到远端 function push_repo() { gitee_repo=$1 @@ -125,8 +75,8 @@ function push_repo() git config credential.helper "store --file=.git/gitee_credentials" echo "https://${gitee_username}:${gitee_tocken}@gitee.com" > .git/gitee_credentials - git commit -am "$commit_info" - git push origin master + git commit -am "$commit_info" --quiet + git push origin master --quiet if [ $? -eq 0 ]; then echo "====== git push successful.${gitee_repo} ======" @@ -136,6 +86,7 @@ function push_repo() fi } +## 4. 提Pull Requests function PR_repo() { gitee_repo=$1 @@ -146,7 +97,7 @@ function PR_repo() { pr_base="master" pr_url="${gitee_api}/repos/opencloudos-stream/${gitee_repo}/pulls" - pr_result=$(curl -X POST "$pr_url" \ + pr_result=$(curl -s -X POST "$pr_url" \ -H "Content-Type: application/json;charset=UTF-8" \ -d '{ "access_token": "'"${gitee_tocken}"'", @@ -167,9 +118,12 @@ function PR_repo() { fi } - +## 0. 各函数入口 function handle_pkgs() { + rm -f $file_success + :> $file_success + # 逐行读取 yaml 文件, 对每个软件包进行fork、clone、Release +1到spec、commit、push、提PR while IFS= read -r pkg_name; do fork_clone_repo $pkg_name @@ -180,18 +134,12 @@ function handle_pkgs() # 如不需要提PR,请注释下行 PR_repo PR_repo $pkg_name cd .. + + # 执行成功的,保存到file_success + echo $pkg_name >> $file_success + # 使用 sed 从文件中删除已处理的软件包 + sed -i "/^${pkg_name}$/d" "$file_out" done < "$file_out" } -# 如果传入参数1,需要执行rpm_dep查询,得到file_out(待release +1软件包名单) -if [ "$#" -ge 1 ]; then - rpm_dep_list - get_list - # rpm_dep_list_clean -elif [ $(cat "$file_out" | wc -l) -eq 0 ]; then - echo "WARNNING: $file_out is NULL, no package." -else - echo "INFO: No arguments provided. Skipping rpm_dep function." -fi - handle_pkgs -- Gitee