Merge pull request #4 from DarkLichCode/pr #12
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: GitHub Classroom Workflow | |
on: | |
push: | |
branches: [ main ] | |
paths-ignore: | |
- 'README.md' | |
pull_request: | |
branches: [ main ] | |
workflow_dispatch: | |
env: | |
CARGO_TERM_COLOR: always | |
TZ: Asia/Shanghai # 设置时区 | |
API_URL: "aHR0cHM6Ly9hcGkub3BlbmNhbXAuY24vd2ViL2FwaS9jb3Vyc2VSYW5rL2NyZWF0ZUJ5VGhpcmRUb2tlbg==" | |
TOKEN: "bVVmRzVyU0RaRmtFMXV0cHBtakJabWpMY1NCeGZJ" | |
jobs: | |
build: | |
name: Autograding | |
runs-on: ubuntu-latest | |
steps: | |
- name: Decode API URL | |
id: decode_api_url | |
run: | | |
echo "url=$(echo "$API_URL" | base64 --decode)" >> $GITHUB_ENV | |
- name: Decode Token | |
id: decode_token | |
run: | | |
echo "token=$(echo "$TOKEN" | base64 --decode)" >> $GITHUB_ENV | |
- uses: actions/checkout@v3 | |
- name: Run tests | |
run: cargo run all | |
- name: Generate summary JSON | |
run: | | |
outfile="report.json" | |
summary_file=".github/result/summary.json" | |
# 提取需要的值 | |
total_exercations=$(jq '.statistics.total_exercises' $outfile) | |
total_succeeds=$(jq '.statistics.total_score' $outfile) | |
github_user="${{ github.actor }}" | |
# 生成新的 JSON 内容 | |
new_json=$(jq -n \ | |
--arg channel "github" \ | |
--argjson courseId 1529 \ | |
--arg ext "aaa" \ | |
--arg name "$github_user" \ | |
--argjson score "$total_succeeds" \ | |
--argjson totalScore 100 \ | |
'{channel: $channel, courseId: $courseId, ext: $ext, name: $name, score: $score, totalScore: $totalScore}') | |
# 保存新的 JSON 文件 | |
echo "$new_json" > $summary_file | |
# 打印新的 JSON 文件到终端 | |
cat $summary_file | |
- name: Post summary JSON to remote API | |
run: | | |
summary_file=".github/result/summary.json" | |
# 发送 POST 请求 | |
curl -X POST "$url" \ | |
-H "accept: application/json;charset=utf-8" \ | |
-H "Content-Type: application/json" \ | |
-H "token: $token" \ | |
-d "$(cat $summary_file)" \ | |
-v |