Merge pull request #5 from OxfordAbstracts/codegen #10
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: Tests | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| env: | |
| CARGO_TERM_COLOR: always | |
| permissions: | |
| pull-requests: write | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Cache cargo registry & build artifacts | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| target | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-cargo- | |
| - name: Build | |
| run: cargo build --release | |
| - name: Run tests | |
| id: tests | |
| run: | | |
| cargo test --release --no-run | |
| start=$(date +%s%N) | |
| cargo test --release -- --nocapture 2>&1 | |
| end=$(date +%s%N) | |
| elapsed_ms=$(( (end - start) / 1000000 )) | |
| echo "elapsed_ms=$elapsed_ms" >> "$GITHUB_OUTPUT" | |
| if [ $elapsed_ms -ge 1000 ]; then | |
| elapsed_s=$(echo "scale=2; $elapsed_ms / 1000" | bc) | |
| echo "elapsed_display=${elapsed_s}s" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "elapsed_display=${elapsed_ms}ms" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Report test time on PR | |
| if: github.event_name == 'pull_request' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const elapsed = '${{ steps.tests.outputs.elapsed_display }}'; | |
| const body = `**Test execution time:** ${elapsed}`; | |
| // Find existing comment to update | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| }); | |
| const existing = comments.find(c => | |
| c.user.type === 'Bot' && c.body.startsWith('**Test execution time:**') | |
| ); | |
| if (existing) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: existing.id, | |
| body, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body, | |
| }); | |
| } |