Skip to content

Commit cbc635c

Browse files
committed
Add github actions workflow
1 parent a938173 commit cbc635c

File tree

6 files changed

+170
-0
lines changed

6 files changed

+170
-0
lines changed

.github/workflows/check-and-lint.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
on:
2+
pull_request:
3+
push:
4+
branches:
5+
- main
6+
7+
8+
name: Check and Lint
9+
10+
jobs:
11+
check:
12+
name: Check
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: actions-rs/toolchain@v1
17+
with:
18+
profile: minimal
19+
toolchain: stable
20+
override: true
21+
- uses: actions-rs/cargo@v1
22+
with:
23+
command: check
24+
25+
fmt:
26+
name: Rustfmt
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v2
30+
- uses: actions-rs/toolchain@v1
31+
with:
32+
profile: minimal
33+
toolchain: stable
34+
override: true
35+
- run: rustup component add rustfmt
36+
- uses: actions-rs/cargo@v1
37+
with:
38+
command: fmt
39+
args: --all -- --check
40+
41+
clippy:
42+
name: Clippy
43+
runs-on: ubuntu-latest
44+
steps:
45+
- uses: actions/checkout@v2
46+
- uses: actions-rs/toolchain@v1
47+
with:
48+
toolchain: stable
49+
components: clippy
50+
override: true
51+
- uses: actions-rs/clippy-check@v1
52+
with:
53+
token: ${{ secrets.GITHUB_TOKEN }}
54+
args: --all-features
55+
name: Clippy Output
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
6+
name: Release Packaging
7+
8+
jobs:
9+
release:
10+
name: Release Packaging
11+
env:
12+
PROJECT_NAME_UNDERSCORE: rust_ci_github_actions_workflow
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: actions-rs/toolchain@v1
17+
with:
18+
profile: minimal
19+
toolchain: stable
20+
override: true
21+
- name: Release Build
22+
run: cargo build --release
23+
- name: 'Upload Artifact'
24+
uses: actions/upload-artifact@v2
25+
with:
26+
name: ${{ env.PROJECT_NAME_UNDERSCORE }}
27+
path: target/release/${{ env.PROJECT_NAME_UNDERSCORE }}

.github/workflows/test.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
on:
2+
pull_request:
3+
push:
4+
branches:
5+
- main
6+
7+
name: Test with Code Coverage
8+
9+
jobs:
10+
test:
11+
name: Test
12+
env:
13+
PROJECT_NAME_UNDERSCORE: rust_ci_github_actions_workflow
14+
CARGO_INCREMENTAL: 0
15+
RUSTFLAGS: -Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort
16+
RUSTDOCFLAGS: -Cpanic=abort
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v2
20+
- uses: actions-rs/toolchain@v1
21+
with:
22+
profile: minimal
23+
toolchain: nightly
24+
override: true
25+
- name: Cache dependencies
26+
uses: actions/cache@v2
27+
env:
28+
cache-name: cache-dependencies
29+
with:
30+
path: |
31+
~/.cargo/.crates.toml
32+
~/.cargo/.crates2.json
33+
~/.cargo/bin
34+
~/.cargo/registry/index
35+
~/.cargo/registry/cache
36+
target
37+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('Cargo.lock') }}
38+
- name: Generate test result and coverage report
39+
run: |
40+
cargo install cargo2junit grcov rust-covfix;
41+
cargo test --features coverage $CARGO_OPTIONS -- -Z unstable-options --format json | cargo2junit > results.xml;
42+
zip -0 ccov.zip `find . \( -name "$PROJECT_NAME_UNDERSCORE*.gc*" \) -print`;
43+
grcov ccov.zip -s . -t lcov --llvm --branch --ignore-not-existing --ignore "/*" --ignore "tests/*" -o lcov.info;
44+
rust-covfix -o lcov_correct.info lcov.info;
45+
- name: Upload test results
46+
uses: EnricoMi/publish-unit-test-result-action@v1
47+
with:
48+
check_name: Test Results
49+
github_token: ${{ secrets.GITHUB_TOKEN }}
50+
files: results.xml
51+
- name: Upload to CodeCov
52+
uses: codecov/codecov-action@v1
53+
with:
54+
# required for private repositories:
55+
# token: ${{ secrets.CODECOV_TOKEN }}
56+
files: ./lcov_correct.info
57+
fail_ci_if_error: true

Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "rust_ci_github_actions_workflow"
3+
version = "0.1.0"
4+
authors = ["[email protected]"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[features]
10+
coverage = []
11+
12+
[dependencies]

src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// Multiplies two integers
2+
pub fn multiply(a: i32, b: i32) -> i32 {
3+
a * b
4+
}
5+
6+
#[cfg(test)]
7+
mod test {
8+
use super::*;
9+
10+
#[test]
11+
fn test() {
12+
assert_eq!(multiply(2, 2), 4);
13+
}
14+
}

src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
use rust_ci_github_actions_workflow::*;
2+
3+
fn main() {
4+
println!("3 time 5 is {}", multiply(3, 5));
5+
}

0 commit comments

Comments
 (0)