Skip to content

Commit a63d6a7

Browse files
authored
Create Cargo workspace (#3)
A new Cargo workspace with a single library crate has been created. The crate has not been touched yet, but a Rust workflow was added to lint, format, and test the code on GitHub Actions.
1 parent 51b39f1 commit a63d6a7

File tree

8 files changed

+197
-4
lines changed

8 files changed

+197
-4
lines changed

.github/workflows/rust.yml

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
---
2+
name: Rust
3+
4+
"on":
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
10+
env:
11+
CARGO_INCREMENTAL: 0
12+
CARGO_PROFILE_TEST_DEBUG: 0
13+
14+
jobs:
15+
detect-changes:
16+
name: Detect changes
17+
runs-on: ubuntu-latest
18+
19+
outputs:
20+
any_changed: ${{ steps.detect-changes.outputs.any_changed }}
21+
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v3
25+
26+
- name: Get changed files
27+
id: detect-changes
28+
uses: tj-actions/changed-files@v35
29+
with:
30+
files: |
31+
**/*.rs
32+
**/*.toml
33+
34+
- name: Print changed files
35+
run: |
36+
for file in ${{ steps.changed-files-specific.outputs.all_changed_files }}; do
37+
echo "$file"
38+
done
39+
40+
lint:
41+
name: Lint code
42+
runs-on: ubuntu-latest
43+
44+
needs: detect-changes
45+
if: needs.detect-changes.outputs.any_changed == 'true'
46+
47+
container:
48+
image: ghcr.io/jdno/rust:main
49+
50+
steps:
51+
- name: Checkout code
52+
uses: actions/checkout@v3
53+
54+
- name: Cache build artifacts
55+
uses: swatinem/[email protected]
56+
57+
- name: Run Clippy
58+
run: cargo clippy --all-targets --all-features -- -D warnings
59+
60+
style:
61+
name: Check style
62+
runs-on: ubuntu-latest
63+
64+
needs: detect-changes
65+
if: needs.detect-changes.outputs.any_changed == 'true'
66+
67+
container:
68+
image: ghcr.io/jdno/rust:main
69+
70+
steps:
71+
- name: Checkout code
72+
uses: actions/checkout@v3
73+
74+
- name: Run Rustfmt
75+
run: cargo fmt --all -- --check
76+
77+
test:
78+
name: Run tests
79+
runs-on: ubuntu-latest
80+
81+
needs: detect-changes
82+
if: needs.detect-changes.outputs.any_changed == 'true'
83+
84+
container:
85+
image: xd009642/tarpaulin:develop-nightly
86+
options: --security-opt seccomp=unconfined
87+
88+
steps:
89+
- name: Checkout code
90+
uses: actions/checkout@v3
91+
92+
- name: Cache build artifacts
93+
uses: swatinem/[email protected]
94+
95+
- name: Run tests with test coverage
96+
run: |
97+
cargo +nightly tarpaulin \
98+
--verbose \
99+
--all-features \
100+
--workspace \
101+
--timeout 120 \
102+
--target-dir target/tarpaulin-target/ \
103+
--skip-clean \
104+
--out Xml
105+
106+
- name: Upload to codecov.io
107+
uses: codecov/codecov-action@v3
108+
with:
109+
token: ${{ secrets.CODECOV_TOKEN }}
110+
111+
- name: Archive code coverage results
112+
uses: actions/upload-artifact@v3
113+
with:
114+
name: code-coverage-report
115+
path: cobertura.xml

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
### Rust.gitignore
2+
# Compiled files and executables generated by Cargo
3+
debug/
4+
target/
5+
6+
# Backup files generated by rustfmt
7+
**/*.rs.bk
8+
9+
# Debugging information generated by MSVC Windows builds of rustc
10+
*.pdb

.pre-commit-config.yaml

+12-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
---
1111
repos:
1212
- repo: https://github.com/pre-commit/pre-commit-hooks
13-
rev: v4.3.0
13+
rev: v4.4.0
1414
hooks:
1515
- id: check-added-large-files
1616
args: ["--maxkb=1024"]
@@ -19,14 +19,22 @@ repos:
1919
- id: trailing-whitespace
2020
args: [--markdown-linebreak-ext=md]
2121
- repo: https://github.com/igorshubovych/markdownlint-cli
22-
rev: v0.32.2
22+
rev: v0.33.0
2323
hooks:
2424
- id: markdownlint
2525
- repo: https://github.com/adrienverge/yamllint
26-
rev: v1.28.0
26+
rev: v1.30.0
2727
hooks:
2828
- id: yamllint
2929
- repo: https://github.com/pre-commit/mirrors-prettier
30-
rev: v3.0.0-alpha.4
30+
rev: v3.0.0-alpha.6
3131
hooks:
3232
- id: prettier
33+
- repo: https://github.com/doublify/pre-commit-rust
34+
rev: v1.0
35+
hooks:
36+
- id: clippy
37+
args: [--all-features, --all-targets, --, -D, warnings]
38+
- id: cargo-check
39+
- id: fmt
40+
args: [--all, --]

Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[workspace]
2+
members = [
3+
"src/flowcrafter",
4+
]
5+
6+
[workspace.package]
7+
version = "0.0.0"
8+
edition = "2021"
9+
10+
# Workspace inheritance was stabilized in Rust 1.64.0.
11+
# See https://blog.rust-lang.org/2022/09/22/Rust-1.64.0.html
12+
rust-version = "1.64"
13+
14+
license = "MIT OR Apache-2.0"
15+
description = "Create and manage workflows for GitHub Actions"
16+
repository = "https://github.com/jdno/flowcrafter"

codecov.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
coverage:
3+
status:
4+
project:
5+
default:
6+
informational: true
7+
patch:
8+
default:
9+
informational: true

src/flowcrafter/Cargo.toml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "flowcrafter"
3+
4+
version.workspace = true
5+
edition.workspace = true
6+
rust-version.workspace = true
7+
license.workspace = true
8+
description.workspace = true
9+
repository.workspace = true
10+
11+
# See more keys and their definitions at
12+
# https://doc.rust-lang.org/cargo/reference/manifest.html
13+
14+
[dependencies]

src/flowcrafter/src/lib.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pub fn add(left: usize, right: usize) -> usize {
2+
left + right
3+
}
4+
5+
#[cfg(test)]
6+
mod tests {
7+
use super::*;
8+
9+
#[test]
10+
fn it_works() {
11+
let result = add(2, 2);
12+
assert_eq!(result, 4);
13+
}
14+
}

0 commit comments

Comments
 (0)