|
| 1 | +name: Jobs |
| 2 | + |
| 3 | +on: [push] |
| 4 | + |
| 5 | +env: |
| 6 | + CARGO_TERM_COLOR: always |
| 7 | + rust_toolchain: nightly |
| 8 | + |
| 9 | +jobs: |
| 10 | + build-doc: |
| 11 | + if: github.repository == 'LearningOS/rCore-Camp-Code-2024A' |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v4 |
| 15 | + - name: Build doc |
| 16 | + run: | |
| 17 | + git clone https://github.com/LearningOS/rCore-Tutorial-Test-2024A.git user |
| 18 | + cd os |
| 19 | + make |
| 20 | + cargo doc --no-deps --verbose |
| 21 | + - name: Push to gh-pages |
| 22 | + uses: peaceiris/actions-gh-pages@v3 |
| 23 | + with: |
| 24 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 25 | + publish_dir: ./os/target/riscv64gc-unknown-none-elf/doc |
| 26 | + destination_dir: ${{ github.ref_name }} |
| 27 | + basic-test: |
| 28 | + runs-on: ubuntu-latest |
| 29 | + outputs: |
| 30 | + points: ${{ steps.end.outputs.points}} |
| 31 | + container: |
| 32 | + image: duskmoon/dev-env:rcore-ci |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v4 |
| 35 | + - name: Run tests |
| 36 | + run: | |
| 37 | + qemu-system-riscv64 --version |
| 38 | + rustup target add riscv64gc-unknown-none-elf |
| 39 | + git config --global --add safe.directory /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }} |
| 40 | + git clone https://github.com/LearningOS/rCore-Tutorial-Checker-2024A.git ci-user |
| 41 | + git clone https://github.com/LearningOS/rCore-Tutorial-Test-2024A.git ci-user/user |
| 42 | + ID=`git rev-parse --abbrev-ref HEAD | grep -oP 'ch\K[0-9]'` |
| 43 | + # cd ci-user && make test CHAPTER=$ID passwd=${{ secrets.BASE_TEST_TOKEN }} |
| 44 | + cd ci-user && make test CHAPTER=$ID passwd=${{ secrets.BASE_TEST_TOKEN }} > ../output.txt |
| 45 | + cat ../output.txt |
| 46 | + - name: end |
| 47 | + id: end |
| 48 | + run: | |
| 49 | + cat output.txt | grep -a "Test passed" | grep -oP "\d{1,}/\d{1,}" | xargs -i echo "points={}" |
| 50 | + cat output.txt | grep -a "Test passed" | grep -oP "\d{1,}/\d{1,}" | xargs -i echo "points={}" >> $GITHUB_OUTPUT |
| 51 | + deploy: |
| 52 | + if: github.repository != 'LearningOS/rCore-Camp-Code-2024A' |
| 53 | + name: Deploy to pages |
| 54 | + needs: basic-test |
| 55 | + runs-on: ubuntu-latest |
| 56 | + permissions: write-all |
| 57 | + steps: |
| 58 | + - uses: actions/checkout@v3 |
| 59 | + continue-on-error: true |
| 60 | + with: |
| 61 | + ref: 'gh-pages' |
| 62 | + - name: Save Log File |
| 63 | + uses: yfblock/multi-rank-log@main |
| 64 | + with: |
| 65 | + public-dir: classroom |
| 66 | + points: ${{ needs.basic-test.outputs.points }} |
| 67 | + - name: GitHub Pages |
| 68 | + uses: crazy-max/ghaction-github-pages@v3 |
| 69 | + with: |
| 70 | + target_branch: gh-pages |
| 71 | + build_dir: ./classroom |
| 72 | + keep_history: true |
| 73 | + env: |
| 74 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + - name: check score |
| 76 | + env: |
| 77 | + course_id: ${{ secrets.RCORE_2024_AUTUMN_COURSE_ID }} |
| 78 | + post_api: ${{ secrets.RUSTLINGS_2024_AUTUMN_POST_API }} |
| 79 | + run: | |
| 80 | + score=$(( $(grep -o 'ch' classroom/latest.json | wc -l) * 100)) |
| 81 | + cat classroom/latest.json |
| 82 | + echo $score |
| 83 | +
|
| 84 | + github_user="${{ github.actor }}" |
| 85 | +
|
| 86 | + # 生成 JSON 结果 |
| 87 | + score_json=$(jq -n \ |
| 88 | + --arg channel "github" \ |
| 89 | + --argjson courseId "$course_id" \ |
| 90 | + --arg name "$github_user" \ |
| 91 | + --argjson score "$score" \ |
| 92 | + --argjson totalScore 500 \ |
| 93 | + '{channel: $channel, courseId: $courseId, name: $name, score: $score, totalScore: $totalScore}') |
| 94 | +
|
| 95 | + curl -X POST https://"$post_api" \ |
| 96 | + -H "accept: application/json;charset=utf-8" \ |
| 97 | + -H "Content-Type: application/json" \ |
| 98 | + -d "$score |
0 commit comments