diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 0000000..d236118 --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,61 @@ +--- +name: Build and test +on: + pull_request: + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + # TODO: Do not allow dead_code once crate is out of early prototyping stage + RUSTFLAGS: --deny warnings --allow dead_code + +jobs: + build-and-test: + strategy: + matrix: + # TODO: Add and make Windows work in CI also + os: [ubuntu-latest, macos-latest] + # Keep MSRV in sync with rust-version in Cargo.toml + rust: [stable, beta, nightly, 1.79.0] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + + - uses: dtolnay/rust-toolchain@21dc36fb71dd22e3317045c0c31a3f4249868b17 # master at the time of writing this + with: + toolchain: ${{ matrix.rust }} + + - name: Build + run: cargo --version && 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: + - uses: actions/checkout@v4 + + - name: Install stable Rust + uses: dtolnay/rust-toolchain@21dc36fb71dd22e3317045c0c31a3f4249868b17 # master at the time of writing this + with: + toolchain: stable + + - name: Install nightly Rust + uses: dtolnay/rust-toolchain@21dc36fb71dd22e3317045c0c31a3f4249868b17 # master at the time of writing this + with: + toolchain: nightly + + - 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/cargo-audit.yml b/.github/workflows/cargo-audit.yml new file mode 100644 index 0000000..33627cf --- /dev/null +++ b/.github/workflows/cargo-audit.yml @@ -0,0 +1,29 @@ +--- +name: Audit dependencies +on: + pull_request: + paths: + - .github/workflows/cargo-audit.yml + - Cargo.toml + - Cargo.lock + schedule: + # At 06:20 UTC every day. Will create an issue if a CVE is found. + - cron: '20 6 * * *' + workflow_dispatch: + +jobs: + audit: + runs-on: ubuntu-latest + permissions: + issues: write + + steps: + - uses: actions/checkout@v4 + + - uses: actions-rust-lang/audit@160ac8b6edd32f74656cabba9d1de3fc8339f676 # v1.2 + name: Audit Rust Dependencies + with: + denyWarnings: true + # Ignored audit issues. This list should be kept short, and effort should be + # put into removing items from the list. + ignore: diff --git a/.github/workflows/formatting.yml b/.github/workflows/formatting.yml new file mode 100644 index 0000000..fd21bca --- /dev/null +++ b/.github/workflows/formatting.yml @@ -0,0 +1,24 @@ +--- +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 + + - name: Install stable Rust + uses: dtolnay/rust-toolchain@21dc36fb71dd22e3317045c0c31a3f4249868b17 # master at the time of writing this + with: + toolchain: stable + components: rustfmt + + - 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..83d97ad --- /dev/null +++ b/.github/workflows/linting.yml @@ -0,0 +1,28 @@ +--- +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: + - uses: actions/checkout@v4 + + + - name: Install stable Rust + uses: dtolnay/rust-toolchain@21dc36fb71dd22e3317045c0c31a3f4249868b17 # master at the time of writing this + with: + toolchain: stable + components: clippy + + - name: Clippy check + env: + # TODO: Do not allow dead_code once crate is out of early prototyping stage + RUSTFLAGS: --deny warnings --allow dead_code + run: cargo clippy --locked --all-targets diff --git a/Cargo.lock b/Cargo.lock index f7839df..87f90e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -698,9 +698,9 @@ dependencies = [ [[package]] name = "trycmd" -version = "0.15.4" +version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59709bd8eccada6a3fded26d22a7f2dcee406c18d3bd7ad2605ca3eeb8f6f6ec" +checksum = "41df4fba07f7959dceeabc01cf7a7dad8110e8f77f0b4bc3708e6fe058344cc7" dependencies = [ "automod", "glob", diff --git a/Cargo.toml b/Cargo.toml index 4bd3e3a..fb43529 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,4 +28,4 @@ toml = "0.8.14" serde = { version = "1.0.203", features = ["derive"] } [dev-dependencies] -trycmd = "0.15.4" +trycmd = "0.15.5" diff --git a/src/config.rs b/src/config.rs index 32d955e..945a8a8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -53,7 +53,7 @@ fn unicode_notation_to_char(unicode_notation: &str) -> Result Option { let hex_str_number = unicode_notation.strip_prefix("U+")?; let int_number = u32::from_str_radix(hex_str_number, 16).ok()?; - Some(char::from_u32(int_number)?) + char::from_u32(int_number) }; parse(unicode_notation).ok_or_else(|| InvalidCharacterType(unicode_notation.to_owned())) } @@ -126,7 +126,7 @@ mod tests { #[should_panic] fn invalid_language() { static INVALID_LANGUAGE: &str = "[language.nonon]"; - let config: Config = toml::from_str(INVALID_LANGUAGE).unwrap(); + let _config: Config = toml::from_str(INVALID_LANGUAGE).unwrap(); } #[test]