Skip to content

Commit

Permalink
Update the post flow
Browse files Browse the repository at this point in the history
  • Loading branch information
kunyuanxu-star committed Jul 19, 2024
1 parent 8e72bfa commit 68d6c36
Showing 1 changed file with 35 additions and 32 deletions.
67 changes: 35 additions & 32 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
env:
CARGO_TERM_COLOR: always
TZ: Asia/Shanghai # 设置时区
ENCODED_API_URL: "aHR0cHM6Ly9hcGkubGVhcm5pbmdjYW1wLmNuL3dlYi9hcGkvY291cnNlUmFuay9jcmVhdGVCeVRoaXJk"

jobs:
initialize:
Expand All @@ -25,6 +26,11 @@ jobs:
- uses: actions/checkout@v3
with:
submodules: recursive # 初始化和更新子模块
- name: Decode API URL
id: decode_api_url
run: |
DECODED_API_URL=$(echo "$ENCODED_API_URL" | base64 --decode)
echo "API_URL=$DECODED_API_URL" >> $GITHUB_ENV
- name: Check for Rustlings, C++ Experiments and Other Submodules
id: check
run: |
Expand Down Expand Up @@ -52,7 +58,6 @@ jobs:
outputs:
details: ${{ steps.autograding.outputs.details }}
points: ${{ steps.autograding.outputs.points}}

steps:
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -107,7 +112,7 @@ jobs:
summary_file=".github/result/rustlings_summary.json"
# 发送 POST 请求
curl -X POST "https://api.learningcamp.cn/web/api/courseRank/createByThird" \
curl -X POST "$API_URL" \
-H "accept: application/json;charset=utf-8" \
-H "Content-Type: application/json" \
-d "$(cat $summary_file)" \
Expand Down Expand Up @@ -141,38 +146,38 @@ jobs:
outfile="test_output.txt"
summary_file="./../.github/result/cxx_result.json"
# 获取最后一行信息并进行处理
info_line=$(tail -n 1 $outfile | sed 's/\x1b\[[0-9;]*m//g')
# 获取最后一行信息并进行处理
info_line=$(tail -n 1 $outfile | sed 's/\x1b\[[0-9;]*m//g')
# 提取通过题数和总题目数量
total_succeeds=$(echo $info_line | cut -d' ' -f1 | cut -d'/' -f1)
total_exercises=$(echo $info_line | cut -d' ' -f1 | cut -d'/' -f2)
# 提取通过题数和总题目数量
total_succeeds=$(echo $info_line | cut -d' ' -f1 | cut -d'/' -f1)
total_exercises=$(echo $info_line | cut -d' ' -f1 | cut -d'/' -f2)
# 提取题目状态字符串
status_string=$(echo $info_line | cut -d' ' -f2 | tr -d '[]')
# 提取题目状态字符串
status_string=$(echo $info_line | cut -d' ' -f2 | tr -d '[]')
# 初始化总失败数
total_failures=$((total_exercises - total_succeeds))
# 初始化总失败数
total_failures=$((total_exercises - total_succeeds))
# 遍历状态字符串并更新 JSON 中的 result 字段
for (( i=0; i<${#status_string}; i++ )); do
exercise_name=$(printf "exercise%02d" $i)
current_char=${status_string:$i:1}
if [[ $current_char == "#" ]]; then
result="true"
else
result="false"
fi
# 遍历状态字符串并更新 JSON 中的 result 字段
for (( i=0; i<${#status_string}; i++ )); do
exercise_name=$(printf "exercise%02d" $i)
current_char=${status_string:$i:1}
if [[ $current_char == "#" ]]; then
result="true"
else
result="false"
fi
# 直接修改 JSON 文件中的相应字段
jq --arg name "$exercise_name" --arg result "$result" '.exercises |= map(if .name == $name then .result = ($result | test("true")) else . end)' $summary_file > tmp.json && mv tmp.json $summary_file
done
# 直接修改 JSON 文件中的相应字段
jq --arg name "$exercise_name" --arg result "$result" '.exercises |= map(if .name == $name then .result = ($result | test("true")) else . end)' $summary_file > tmp.json && mv tmp.json $summary_file
done
# 更新统计信息
jq --argjson succeeds "$total_succeeds" --argjson failures "$total_failures" '.statistics.total_succeeds = $succeeds | .statistics.total_failures = $failures' $summary_file > tmp.json && mv tmp.json $summary_file
# 更新统计信息
jq --argjson succeeds "$total_succeeds" --argjson failures "$total_failures" '.statistics.total_succeeds = $succeeds | .statistics.total_failures = $failures' $summary_file > tmp.json && mv tmp.json $summary_file
# 打印新的 JSON 文件到终端
cat $summary_file
# 打印新的 JSON 文件到终端
cat $summary_file
working-directory: learning-cxx
continue-on-error: true
- uses: yfblock/os-autograding@master
Expand Down Expand Up @@ -210,11 +215,12 @@ jobs:
summary_file=".github/result/cxx_summary.json"
# 发送 POST 请求
curl -X POST "https://api.learningcamp.cn/web/api/courseRank/createByThird" \
curl -X POST "$API_URL" \
-H "accept: application/json;charset=utf-8" \
-H "Content-Type: application/json" \
-d "$(cat $summary_file)" \
-v
test:
name: Test Job for Other Submodules
needs: initialize
Expand All @@ -228,7 +234,7 @@ jobs:
submodules: 'true'
- name: Post summary JSON to remote API
run: |
curl -X POST "https://api.learningcamp.cn/web/api/courseRank/createByThird" \
curl -X POST "$API_URL" \
-H "accept: application/json;charset=utf-8" \
-H "Content-Type: application/json" \
-d '{
Expand All @@ -240,6 +246,3 @@ jobs:
"totalScore": 23
}' \
-v

0 comments on commit 68d6c36

Please sign in to comment.