diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 0000000..a4dabe7 --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,77 @@ +--- +name: Build and test +on: + pull_request: + paths: + - .github/workflows/build-and-test.yml + - '**/*.rs' + - Cargo.toml + - Cargo.lock + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + RUSTFLAGS: --deny warnings + +jobs: + build-and-test: + strategy: + matrix: + # Keep MSRV in sync with rust-version in Cargo.toml + rust: [stable, beta, nightly, 1.56.0] + runs-on: ubuntu-latest + steps: + - name: Install build dependencies + run: | + sudo apt-get update + sudo apt-get install -y libnftnl-dev libmnl-dev + + - uses: actions/checkout@v4 + + - uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af #v1.0.7 + with: + toolchain: ${{ matrix.rust }} + profile: minimal + default: true + + - name: Build + run: cargo build --all-targets --locked + + - name: Test + run: cargo test --locked + + # Make sure documentation builds without warnings (broken links etc) + - name: Generate documentation + if: matrix.rust == 'stable' + run: RUSTDOCFLAGS="--deny warnings" cargo doc + + # Make sure the library builds with all dependencies downgraded to their + # oldest versions allowed by the semver spec. This ensures we have not + # under-specified any dependency + minimal-versions: + runs-on: ubuntu-latest + steps: + - name: Install build dependencies + run: | + sudo apt-get update + sudo apt-get install -y libnftnl-dev libmnl-dev + + - uses: actions/checkout@v4 + + - name: Install stable Rust + uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af #v1.0.7 + with: + toolchain: stable + profile: minimal + + - name: Install nightly Rust + uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af #v1.0.7 + with: + toolchain: nightly + profile: minimal + + - name: Downgrade dependencies to minimal versions + run: cargo +nightly update -Z minimal-versions + + - name: Compile with minimal versions + run: cargo +stable build --all-targets --locked diff --git a/.github/workflows/formatting.yml b/.github/workflows/formatting.yml new file mode 100644 index 0000000..73a287e --- /dev/null +++ b/.github/workflows/formatting.yml @@ -0,0 +1,25 @@ +--- +name: Rust formatting +on: + pull_request: + paths: + - .github/workflows/formatting.yml + - '**/*.rs' + workflow_dispatch: +jobs: + check-formatting: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af #v1.0.7 + with: + toolchain: stable + profile: minimal + components: rustfmt + default: true + + - name: Check formatting + run: | + rustfmt --version + cargo fmt -- --check diff --git a/.github/workflows/git-commit-message-style.yml b/.github/workflows/git-commit-message-style.yml new file mode 100644 index 0000000..4125202 --- /dev/null +++ b/.github/workflows/git-commit-message-style.yml @@ -0,0 +1,32 @@ +--- +name: Git - Check commit message style +on: + push: + workflow_dispatch: + +jobs: + check-commit-message-style: + name: Check commit message style + runs-on: ubuntu-latest + steps: + # Make sure there are no whitespaces other than space, tab and newline in a commit message. + - name: Check for unicode whitespaces + uses: gsactions/commit-message-checker@16fa2d5de096ae0d35626443bcd24f1e756cafee #v2.0.0 + with: + # Pattern matches strings not containing weird unicode whitespace/separator characters + # \P{Z} = All non-whitespace characters (the u-flag is needed to enable \P{Z}) + # [ \t\n] = Allowed whitespace characters + pattern: '^(\P{Z}|[ \t\n])+$' + flags: 'u' + error: 'Detected unicode whitespace character in commit message.' + checkAllCommitMessages: 'true' # optional: this checks all commits associated with a pull request + accessToken: ${{ secrets.GITHUB_TOKEN }} # only required if checkAllCommitMessages is true + + # Git commit messages should follow these guidelines: https://cbea.ms/git-commit/ + - name: Check against guidelines + uses: mristin/opinionated-commit-message@f3b9cec249cabffbae7cd564542fd302cc576827 #v3.1.1 + with: + # Commit messages are allowed to be subject only, no body + allow-one-liners: 'true' + # This action defaults to 50 char subjects, but 72 is fine. + max-subject-line-length: '72' diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml new file mode 100644 index 0000000..d6434ac --- /dev/null +++ b/.github/workflows/linting.yml @@ -0,0 +1,32 @@ +--- +name: Rust linting +on: + pull_request: + paths: + - .github/workflows/linting.yml + - '**/*.rs' + - Cargo.toml + - Cargo.lock + workflow_dispatch: +jobs: + clippy-linting: + runs-on: ubuntu-latest + steps: + - name: Install build dependencies + run: | + sudo apt-get update + sudo apt-get install -y libnftnl-dev libmnl-dev + + - uses: actions/checkout@v4 + + - uses: actions-rs/toolchain@v1.0.6 + with: + toolchain: stable + profile: minimal + components: clippy + default: true + + - name: Clippy check + env: + RUSTFLAGS: --deny warnings + run: cargo clippy --locked --all-targets diff --git a/.gitignore b/.gitignore index 143b1ca..eccd7b4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ - /target/ **/*.rs.bk -Cargo.lock diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..aefb913 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,89 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "bitflags" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "ipnetwork" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf466541e9d546596ee94f9f69590f89473455f88372423e0008fc1a7daf100e" +dependencies = [ + "serde", +] + +[[package]] +name = "libc" +version = "0.2.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10923947f84a519a45c8fefb7dd1b3e8c08747993381adee176d7a82b4195311" + +[[package]] +name = "log" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "518ef76f2f87365916b142844c16d8fefd85039bc5699050210a7778ee1cd1de" + +[[package]] +name = "mnl" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1a5469630da93e1813bb257964c0ccee3b26b6879dd858039ddec35cc8681ed" +dependencies = [ + "libc", + "log", + "mnl-sys", +] + +[[package]] +name = "mnl-sys" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9750685b201e1ecfaaf7aa5d0387829170fa565989cc481b49080aa155f70457" +dependencies = [ + "libc", + "pkg-config", +] + +[[package]] +name = "nftnl" +version = "0.6.2" +dependencies = [ + "bitflags", + "ipnetwork", + "log", + "mnl", + "nftnl-sys", +] + +[[package]] +name = "nftnl-sys" +version = "0.6.1" +dependencies = [ + "cfg-if", + "libc", + "pkg-config", +] + +[[package]] +name = "pkg-config" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" + +[[package]] +name = "serde" +version = "1.0.185" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be9b6f69f1dfd54c3b568ffa45c310d6973a5e5148fd40cf515acaf38cf5bc31" diff --git a/nftnl/Cargo.toml b/nftnl/Cargo.toml index ec28d10..a0dd46b 100644 --- a/nftnl/Cargo.toml +++ b/nftnl/Cargo.toml @@ -25,5 +25,5 @@ log = "0.4" nftnl-sys = { path = "../nftnl-sys", version = "0.6.1" } [dev-dependencies] -ipnetwork = "0.16" -mnl = "0.2" +ipnetwork = "0.20.0" +mnl = "0.2.2"