diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8b47621 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,63 @@ +name: CI + +on: + push: + pull_request: + +jobs: + report: + needs: + - lint-aux + - rustfmt + - clippy + - build-and-test + if: always() + runs-on: ubuntu-20.04 + steps: + - name: Report success + if: "!contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled')" + run: exit 0 + - name: Report failure + if: "contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')" + run: exit 1 + + lint-aux: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v4 + - name: Install dependencies + run: ./ci/install-lint-deps.sh + - name: Run auxilary lints + run: ./ci/lint-aux.sh + + rustfmt: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v4 + - name: Install Rust + run: ./ci/install-rust.sh stable.txt --profile minimal -c rustfmt + - name: Run rustfmt + run: cargo fmt --all -- --check + + clippy: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v4 + - name: Install Rust + run: ./ci/install-rust.sh stable.txt --profile minimal -c clippy + - name: Run clippy + run: ./ci/clippy.sh + + build-and-test: + runs-on: ubuntu-20.04 + strategy: + matrix: + include: + - rust-version: msrv.txt + - rust-version: stable.txt + steps: + - uses: actions/checkout@v4 + - name: Install Rust + run: ./ci/install-rust.sh "${{ matrix.rust-version }}" --profile minimal + - name: Build and test + run: ./ci/build-and-test.sh diff --git a/ci/build-and-test.sh b/ci/build-and-test.sh new file mode 100755 index 0000000..ac18f5c --- /dev/null +++ b/ci/build-and-test.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -euo pipefail + +export RUSTDOCFLAGS="-D warnings" + +cargo fetch --locked + +cargo build --workspace --all-targets --frozen +cargo test --workspace --frozen +cargo doc --workspace --frozen diff --git a/ci/clippy.sh b/ci/clippy.sh new file mode 100755 index 0000000..76b7d1c --- /dev/null +++ b/ci/clippy.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -euo pipefail + +cargo fetch --locked +cargo clippy --workspace --all-targets --frozen -- -D warnings diff --git a/ci/install-lint-deps.sh b/ci/install-lint-deps.sh new file mode 100755 index 0000000..82de250 --- /dev/null +++ b/ci/install-lint-deps.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -euo pipefail + +sudo apt-get update +sudo apt-get install -y --no-install-recommends shellcheck + +sudo gem install mdl diff --git a/ci/install-rust.sh b/ci/install-rust.sh new file mode 100755 index 0000000..3012aa6 --- /dev/null +++ b/ci/install-rust.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -euo pipefail + +rust_version="$1" +shift + +if [[ "$rust_version" = *.txt ]]; then + rust_version="$(cat "ci/rust-versions/$rust_version")" +fi + +echo "Installing Rust $rust_version" +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain "$rust_version" "$@" +echo "$HOME/.cargo/bin" >> "$GITHUB_PATH" diff --git a/ci/lint-aux.sh b/ci/lint-aux.sh new file mode 100755 index 0000000..b2d5645 --- /dev/null +++ b/ci/lint-aux.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -euo pipefail + +echo "Checking MSRV consistency" + +msrv="$(cat ci/rust-versions/msrv.txt)" +msrv="${msrv%.*}" + +if [ "$(grep rust-version Cargo.toml)" != "rust-version = \"$msrv\"" ]; then + echo "Incorrect rust-version in Cargo.toml" + exit 1 +fi + +echo "Checking shell scripts with shellcheck" +find . -type f -name "*.sh" -not -path "./.git/*" -print0 | xargs -0 shellcheck + +echo "Checking markdown documents with markdownlint" +find . -type f -name "*.md" -not -path "./.git/*" -print0 | xargs -0 mdl diff --git a/ci/rust-versions/msrv.txt b/ci/rust-versions/msrv.txt new file mode 100644 index 0000000..dc87e8a --- /dev/null +++ b/ci/rust-versions/msrv.txt @@ -0,0 +1 @@ +1.74.0 diff --git a/ci/rust-versions/stable.txt b/ci/rust-versions/stable.txt new file mode 100644 index 0000000..79e15fd --- /dev/null +++ b/ci/rust-versions/stable.txt @@ -0,0 +1 @@ +1.77.0