update build.yml #41
This file contains hidden or 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: Jobs | |
on: [push] | |
env: | |
CARGO_TERM_COLOR: always | |
rust_toolchain: nightly | |
jobs: | |
build-doc: | |
if: github.repository == 'LearningOS/rCore-Camp-Code-2025S' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Build doc | |
run: | | |
git clone https://github.com/LearningOS/rCore-Tutorial-Test-2025S.git user | |
cd os | |
make | |
cargo doc --no-deps --verbose | |
- name: Push to gh-pages | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./os/target/riscv64gc-unknown-none-elf/doc | |
destination_dir: ${{ github.ref_name }} | |
basic-test: | |
runs-on: ubuntu-latest | |
outputs: | |
points: ${{ steps.end.outputs.points }} | |
container: | |
image: duskmoon/dev-env:rcore-ci | |
steps: | |
- uses: actions/checkout@v4 | |
# 删掉旧的 Override Cargo source 步骤 | |
- name: Run tests | |
run: | | |
qemu-system-riscv64 --version | |
rustup target add riscv64gc-unknown-none-elf | |
git config --global --add safe.directory /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }} | |
git clone https://github.com/LearningOS/rCore-Tutorial-Checker-2025S.git ci-user | |
git clone https://github.com/LearningOS/rCore-Tutorial-Test-2025S.git ci-user/user | |
# --- 新增的步骤:创建本地配置文件以强制覆盖 --- | |
mkdir -p ci-user/.cargo | |
cat > ci-user/.cargo/config.toml <<EOF | |
[source.crates-io] | |
replace-with = "tuna" | |
[source.tuna] | |
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git" | |
EOF | |
# --- 结束 --- | |
ID=`git rev-parse --abbrev-ref HEAD | grep -oP 'ch\K[0-9]'` | |
cd ci-user && make test CHAPTER=$ID passwd=${{ secrets.BASE_TEST_TOKEN }} > ../output.txt | |
cat ../output.txt | |
- name: end | |
id: end | |
run: | | |
cat output.txt | grep -a "Test passed" | grep -oP "\d{1,}/\d{1,}" | xargs -i echo "points={}" | |
cat output.txt | grep -a "Test passed" | grep -oP "\d{1,}/\d{1,}" | xargs -i echo "points={}" >> $GITHUB_OUTPUT | |
deploy: | |
if: github.repository != 'LearningOS/rCore-Camp-Code-2025S' | |
name: Deploy to pages | |
needs: basic-test | |
runs-on: ubuntu-latest | |
permissions: write-all | |
steps: | |
- uses: actions/checkout@v3 | |
continue-on-error: true | |
with: | |
ref: 'gh-pages' | |
- name: Save Log File | |
uses: yfblock/multi-rank-log@main | |
with: | |
public-dir: classroom | |
points: ${{ needs.basic-test.outputs.points }} | |
- name: GitHub Pages | |
uses: crazy-max/ghaction-github-pages@v3 | |
with: | |
target_branch: gh-pages | |
build_dir: ./classroom | |
keep_history: true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: check score | |
env: | |
course_id: ${{ secrets.RCORE_2025_SPRING_COURSE_ID }} | |
post_api: ${{ secrets.RCORE_2025_SPRING_POST_API }} | |
token: ${{ secrets.RCORE_2025_SPRING_TOKEN }} | |
run: | | |
score=$(( $(grep -o 'ch' classroom/latest.json | wc -l) * 100)) | |
cat classroom/latest.json | |
echo $score | |
github_user="${{ github.actor }}" | |
score_json=$(jq -n \ | |
--arg channel "github" \ | |
--argjson courseId "$course_id" \ | |
--arg name "$github_user" \ | |
--argjson score "$score" \ | |
--argjson totalScore 500 \ | |
'{channel: $channel, courseId: $courseId, name: $name, score: $score, totalScore: $totalScore}') | |
response=$(curl -X POST $post_api \ | |
-H "accept: application/json;charset=utf-8" \ | |
-H "Content-Type: application/json" \ | |
-H "token: $token" \ | |
-d "$score_json" \ | |
-v) | |
echo "Response: $response" | |
if echo "$response" | grep -q '"result":1'; then | |
echo "Success: The result field contains 1." | |
else | |
echo "Error: The result field does not contain 1." | |
exit 1 | |
fi |