Rust project template with CI workflow in GitHub Actions
Last updated Dec 23, 2025
41
Stars
6
Forks
5
Issues
0
Stars/day
Attention Score
6
Language breakdown
Rust 100.0%
โธ Files
click to expand
README
Rust CI with GitHub Actions
Table of Contents
- Check and Lint (check-and-lint.yaml) - Test with Code Coverage (test.yaml) - Release Packaging (release-packaging.yaml)Workflows
The CI process is separated into 3 workflows: Check and Lint, Test, and Release Packaging.All jobs run on ubuntu-latest, and are run in parallel.
All jobs use actions/checkout@v2 and actions-rs/toolchain@v1.
Check and Lint (check-and-lint.yaml)
This workflow checks for compiler errors and code style inconsistencies. It runs on pull requests and main branch push.Check job
This job runscargo check on the stable toolchain.
It checks if there are compiler errors.
Rustfmt job
This job runs rustfmt with the--check option through cargo fmt on the stable toolchain.
By default, it checks inconsistencies with the Rust style guide. You can add a rustfmt.toml or .rustfmt.toml to configure the style.
Clippy job
This job runs clippy on the stable toolchain through actions-rs/clippy-check@v1. You can add aclippy.toml or .clippy.toml to configure the style.
- The action outputs result (Clippy Output added to a random workflow), and
- For pull requests, it adds annotations on the diff.
Test with Code Coverage (test.yaml)
This workflow run tests, outputs test results, publishes code coverage results on CodeCov. Publishing test results and code coverage data is in one job to avoid running the tests twice. It runs on pull requests and main branch push.Test job
This job:- Caches dependencies,
- Runs tests and generate test results and code coverage data,
- Uploads test results, and
- Uploads to CodeCov.
PROJECTNAMEUNDERSCORE- project name with hyphens(-) as underscores(_) needed for code coverageCARGOINCREMENTAL,RUSTFLAGS,RUSTDOCFLAGS- added toCARGOOPTIONSin cargo test needed for code coverage
- Cache dependencies.
${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('Cargo.lock') }}
where env.cache-name: cache-dependencies.
- Cache is stored at the end of the job on cache miss. Cache is not updated on cache hit.
- Generate test results and code coverage data.
cargo test in the nightly toolchain.
- $CARGOOPTIONS includes CARGOINCREMENTAL, RUSTFLAGS, and RUSTDOCFLAGS options needed for code coverage.
- -Z unstable-options --format json formats the test result into json.
- | cargo2junit > results.xml converts the json result into junit format for EnricoMi/publish-unit-test-result-action to understand and saves it as results.xml.
4. It generates code coverage data in lcov format through grcov saved as lcov.info.
- Upload test results.
results.xml) through EnricoMi/publish-unit-test-result-action@v1.
- The action outputs the test result (Test Results added to a random workflow).
- For pull requests, the action adds a comment containing the test results.
- Upload to CodeCov.
lcov.info) to CodeCov through codecov/codecov-action@v1.
- For pull requests, the actions adds a comment containing the code coverage report.
- For private repositories, add your token from CodeCov repository setting on GitHub Secrets and uncomment the line: token: ${{ secrets.CODECOV_TOKEN }}.
Release Packaging (release-packaging.yaml)
This workflow builds the package in release mode and uploads resulting file as a GitHub artifact. It runs on main branch push.Release Packaging job
This job builds the project in release mode and uploads the binary as an artifact through actions/upload-artifact@v2.The binary target/release/${{ env.PROJECTNAMEUNDERSCORE }} is uploaded as ${{ env.PROJECTNAMEUNDERSCORE }}.
How to Use
- Replace the value of
PROJECTNAMEUNDERSCOREwith your project name (replace hyphens(-) as underscores(_)).
- Customize when to call the workflows (like branch names)
- Customize options:
Notes:
secrets.GITHUB_TOKENis needed by some actions to create GitHub checks & annotations. it is added automatically by GitHub.- uses cache for GitHub actions.
- clippy html output and test result output are added to random workflows for a certain commit due to limitations in the GitHub Actions API.
License
MIT๐ More in this category