Skip to content

Commit

Permalink
ci: add CI with Github Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardosm committed Apr 6, 2024
1 parent c9c96ef commit 150b08d
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions ci/build-and-test.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions ci/clippy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -euo pipefail

cargo fetch --locked
cargo clippy --workspace --all-targets --frozen -- -D warnings
7 changes: 7 additions & 0 deletions ci/install-lint-deps.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions ci/install-rust.sh
Original file line number Diff line number Diff line change
@@ -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"
18 changes: 18 additions & 0 deletions ci/lint-aux.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions ci/rust-versions/msrv.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.74.0
1 change: 1 addition & 0 deletions ci/rust-versions/stable.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.77.0

0 comments on commit 150b08d

Please sign in to comment.